Skip to content

Commit 3d6cbaa

Browse files
committed
Guiced EE Updates
1 parent b1c9bb5 commit 3d6cbaa

File tree

11 files changed

+124
-101
lines changed

11 files changed

+124
-101
lines changed

Jaxrs/Basic/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
<artifactId>guiced-undertow</artifactId>
2626
</dependency>
2727

28+
<dependency>
29+
<groupId>com.guicedee</groupId>
30+
<artifactId>guice-injection</artifactId>
31+
</dependency>
32+
33+
2834
<dependency>
2935
<groupId>org.junit.jupiter</groupId>
3036
<artifactId>junit-jupiter</artifactId>
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
package com.guicedee.examples.jaxrs.basic;
22

3-
import com.guicedee.guicedinjection.*;
4-
import com.guicedee.guicedservlets.undertow.*;
5-
import io.undertow.*;
6-
import jakarta.ws.rs.*;
3+
import com.guicedee.client.IGuiceContext;
4+
import com.guicedee.guicedservlets.undertow.GuicedUndertow;
5+
import io.undertow.Undertow;
6+
import jakarta.ws.rs.GET;
7+
import jakarta.ws.rs.Path;
8+
import jakarta.ws.rs.PathParam;
9+
import jakarta.ws.rs.Produces;
710

8-
import java.time.*;
9-
import java.time.temporal.*;
11+
import java.time.LocalDateTime;
12+
import java.time.temporal.ChronoUnit;
1013

1114
@Path("hello")
1215
@Produces("application/json")
1316
public class HelloWorld
1417
{
15-
@GET
16-
@Path("{name}")
17-
public String hello(@PathParam("name") final String name)
18-
{
19-
return "Hello! " + name;
20-
}
21-
22-
public static void main(String[] args) throws Exception
23-
{
24-
LocalDateTime startTime = LocalDateTime.now();
25-
26-
//optional for class scanning optimization
27-
GuiceContext.registerModule("com.guicedee.examples.jaxrs.basic");
28-
Undertow boot = GuicedUndertow.boot("0.0.0.0", 6003);
29-
LocalDateTime endTime = LocalDateTime.now();
30-
31-
System.out.println("Started in " + ChronoUnit.MILLIS.between(startTime, endTime) + "ms");
32-
}
18+
@GET
19+
@Path("{name}")
20+
public String hello(@PathParam("name") final String name)
21+
{
22+
return "Hello! " + name;
23+
}
24+
25+
public static void main(String[] args) throws Exception
26+
{
27+
LocalDateTime startTime = LocalDateTime.now();
28+
29+
//optional for class scanning optimization
30+
IGuiceContext.registerModule("com.guicedee.examples.jaxrs.basic");
31+
Undertow boot = GuicedUndertow.boot("0.0.0.0", 6003);
32+
LocalDateTime endTime = LocalDateTime.now();
33+
34+
System.out.println("Started in " + ChronoUnit.MILLIS.between(startTime, endTime) + "ms");
35+
}
3336
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module com.guicedee.examples.jaxrs.basic {
2+
requires com.guicedee.guicedinjection;
23
requires com.guicedee.guicedservlets.rest;
34
requires com.guicedee.guicedservlets.undertow;
45

56
requires java.net.http;
6-
7-
exports com.guicedee.examples.jaxrs.basic;
7+
8+
exports com.guicedee.examples.jaxrs.basic;
89
opens com.guicedee.examples.jaxrs.basic to com.google.guice, com.fasterxml.jackson.databind, org.apache.cxf;
910
}

Jaxrs/Basic/src/test/java/com/guicedee/examples/jaxrs/basic/tests/HelloWorldTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public void testWorld() throws Exception
3232
System.out.println(response.body());
3333
assertEquals(200, response.statusCode());
3434

35-
GuiceContext.destroy();
35+
GuiceContext.instance().destroy();
3636
}
3737
}

Jaxrs/Basic/src/test/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
requires com.guicedee.guicedservlets.rest;
88
requires com.guicedee.guicedservlets.undertow;
9+
requires com.guicedee.guicedinjection;
910

1011
opens com.guicedee.examples.jaxrs.basic.tests to com.google.guice, com.fasterxml.jackson.databind, org.apache.cxf,org.junit.platform.commons;
1112
}

Jaxrs/Binding/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
<groupId>com.guicedee.servlets</groupId>
2626
<artifactId>guiced-rest-services</artifactId>
2727
</dependency>
28+
<dependency>
29+
<groupId>com.guicedee</groupId>
30+
<artifactId>guice-inject-client</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.guicedee</groupId>
34+
<artifactId>guice-injection</artifactId>
35+
</dependency>
36+
37+
2838
<dependency>
2939
<groupId>com.guicedee.servlets</groupId>
3040
<artifactId>guiced-openapi</artifactId>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.guicedee.examples.jaxrs.binding;
22

33

4-
import com.guicedee.guicedinjection.GuiceContext;
4+
import com.guicedee.client.IGuiceContext;
55
import com.guicedee.guicedservlets.undertow.GuicedUndertow;
66
import io.undertow.Undertow;
77

88
public class BootJaxRSBindings
99
{
10-
public static void main(String... args) throws Exception
11-
{
12-
GuiceContext.registerModule("com.guicedee.examples.jaxrs.binding");
13-
Undertow undertow = GuicedUndertow.boot("0.0.0.0", 6003);
14-
}
10+
public static void main(String... args) throws Exception
11+
{
12+
IGuiceContext.registerModule("com.guicedee.examples.jaxrs.binding");
13+
Undertow undertow = GuicedUndertow.boot("0.0.0.0", 6003);
14+
}
1515
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.guicedee.examples.jaxrs.binding.resources;
22

3-
import com.guicedee.guicedinjection.GuiceContext;
3+
import com.guicedee.client.IGuiceContext;
44
import jakarta.ws.rs.core.Application;
55

66
import java.util.HashSet;
@@ -9,20 +9,20 @@
99

1010
public class RestApplication extends Application
1111
{
12-
private final Set<Class<?>> classes = new HashSet<>();
13-
private final Set<Object> singletons = new HashSet<>();
14-
15-
@Override
16-
public Set<Class<?>> getClasses()
17-
{
18-
return classes;
19-
}
20-
21-
@Override
22-
public Set<Object> getSingletons()
23-
{
24-
//If using application way, can register individual services
25-
singletons.add(GuiceContext.get(HelloResource.class));
26-
return singletons;
27-
}
12+
private final Set<Class<?>> classes = new HashSet<>();
13+
private final Set<Object> singletons = new HashSet<>();
14+
15+
@Override
16+
public Set<Class<?>> getClasses()
17+
{
18+
return classes;
19+
}
20+
21+
@Override
22+
public Set<Object> getSingletons()
23+
{
24+
//If using application way, can register individual services
25+
singletons.add(IGuiceContext.get(HelloResource.class));
26+
return singletons;
27+
}
2828
}

Jaxrs/Binding/src/main/java/module-info.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
import com.guicedee.guicedinjection.interfaces.IGuiceModule;
33

44
module com.guicedee.examples.jaxrs.binding {
5-
exports com.guicedee.examples.jaxrs.binding to com.guicedee.examples.jaxrs.binding.test;
6-
7-
requires com.guicedee.guicedservlets.rest;
8-
requires com.guicedee.guicedservlets.undertow;
9-
10-
requires java.net.http;
11-
requires jakarta.ws.rs;
5+
exports com.guicedee.examples.jaxrs.binding to com.guicedee.examples.jaxrs.binding.test;
126

13-
provides IGuiceModule with RestTestBinding;
7+
requires com.guicedee.guicedservlets.rest;
8+
requires com.guicedee.guicedservlets.undertow;
9+
requires com.guicedee.guicedinjection;
1410

15-
opens com.guicedee.examples.jaxrs.binding to com.google.guice, com.fasterxml.jackson.databind, org.apache.cxf;
16-
opens com.guicedee.examples.jaxrs.binding.implementations to com.fasterxml.jackson.databind, com.google.guice, org.apache.cxf;
17-
opens com.guicedee.examples.jaxrs.binding.resources to com.fasterxml.jackson.databind, com.google.guice, org.apache.cxf;
11+
requires java.net.http;
12+
requires jakarta.ws.rs;
13+
14+
provides IGuiceModule with RestTestBinding;
15+
16+
opens com.guicedee.examples.jaxrs.binding to com.google.guice, com.fasterxml.jackson.databind, org.apache.cxf;
17+
opens com.guicedee.examples.jaxrs.binding.implementations to com.fasterxml.jackson.databind, com.google.guice, org.apache.cxf;
18+
opens com.guicedee.examples.jaxrs.binding.resources to com.fasterxml.jackson.databind, com.google.guice, org.apache.cxf;
1819

1920
}
Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.guicedee.examples.jaxrs.binding.test;
22

3+
import com.guicedee.client.IGuiceContext;
34
import com.guicedee.examples.jaxrs.binding.BootJaxRSBindings;
4-
import com.guicedee.guicedinjection.GuiceContext;
5-
import com.guicedee.guicedservlets.undertow.GuicedUndertow;
6-
import io.undertow.Undertow;
75
import org.junit.jupiter.api.Test;
86

97
import java.net.URI;
@@ -13,35 +11,36 @@
1311
import java.time.Duration;
1412
import java.time.temporal.ChronoUnit;
1513

16-
import static org.junit.jupiter.api.Assertions.*;
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
1715

1816
class BootJaxRSBindingsTest
1917
{
2018

21-
@Test
22-
public void testRS() throws Exception
23-
{
24-
BootJaxRSBindings.main(null);
25-
26-
HttpClient client = HttpClient.newBuilder()
27-
.connectTimeout(Duration.of(5, ChronoUnit.SECONDS))
28-
.build();
29-
HttpResponse response = client.send(HttpRequest.newBuilder()
30-
.GET()
31-
.uri(new URI("http://localhost:6003/rest/hello/world"))
32-
.build(),
33-
HttpResponse.BodyHandlers.ofString());
34-
System.out.println(response.body());
35-
assertEquals(200, response.statusCode());
36-
response = client.send(HttpRequest.newBuilder()
37-
.GET()
38-
.uri(new URI("http://localhost:6003/rest/hello/helloObject/world"))
39-
.build(),
40-
HttpResponse.BodyHandlers.ofString());
41-
System.out.println(response.body());
42-
43-
assertEquals(200, response.statusCode());
44-
45-
GuiceContext.destroy();
46-
}
19+
@Test
20+
public void testRS() throws Exception
21+
{
22+
BootJaxRSBindings.main(null);
23+
24+
HttpClient client = HttpClient.newBuilder()
25+
.connectTimeout(Duration.of(5, ChronoUnit.SECONDS))
26+
.build();
27+
HttpResponse response = client.send(HttpRequest.newBuilder()
28+
.GET()
29+
.uri(new URI("http://localhost:6003/rest/hello/world"))
30+
.build(),
31+
HttpResponse.BodyHandlers.ofString());
32+
System.out.println(response.body());
33+
assertEquals(200, response.statusCode());
34+
response = client.send(HttpRequest.newBuilder()
35+
.GET()
36+
.uri(new URI("http://localhost:6003/rest/hello/helloObject/world"))
37+
.build(),
38+
HttpResponse.BodyHandlers.ofString());
39+
System.out.println(response.body());
40+
41+
assertEquals(200, response.statusCode());
42+
43+
IGuiceContext.instance()
44+
.destroy();
45+
}
4746
}

0 commit comments

Comments
 (0)