diff --git a/Jaxrs/Basic/pom.xml b/Jaxrs/Basic/pom.xml index daf7c3f..a806bc0 100644 --- a/Jaxrs/Basic/pom.xml +++ b/Jaxrs/Basic/pom.xml @@ -25,6 +25,12 @@ guiced-undertow + + com.guicedee + guice-injection + + + org.junit.jupiter junit-jupiter diff --git a/Jaxrs/Basic/src/main/java/com/guicedee/examples/jaxrs/basic/HelloWorld.java b/Jaxrs/Basic/src/main/java/com/guicedee/examples/jaxrs/basic/HelloWorld.java index 03b6d57..655b43f 100644 --- a/Jaxrs/Basic/src/main/java/com/guicedee/examples/jaxrs/basic/HelloWorld.java +++ b/Jaxrs/Basic/src/main/java/com/guicedee/examples/jaxrs/basic/HelloWorld.java @@ -1,33 +1,36 @@ package com.guicedee.examples.jaxrs.basic; -import com.guicedee.guicedinjection.*; -import com.guicedee.guicedservlets.undertow.*; -import io.undertow.*; -import jakarta.ws.rs.*; +import com.guicedee.client.IGuiceContext; +import com.guicedee.guicedservlets.undertow.GuicedUndertow; +import io.undertow.Undertow; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; -import java.time.*; -import java.time.temporal.*; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; @Path("hello") @Produces("application/json") public class HelloWorld { - @GET - @Path("{name}") - public String hello(@PathParam("name") final String name) - { - return "Hello! " + name; - } - - public static void main(String[] args) throws Exception - { - LocalDateTime startTime = LocalDateTime.now(); - - //optional for class scanning optimization - GuiceContext.registerModule("com.guicedee.examples.jaxrs.basic"); - Undertow boot = GuicedUndertow.boot("0.0.0.0", 6003); - LocalDateTime endTime = LocalDateTime.now(); - - System.out.println("Started in " + ChronoUnit.MILLIS.between(startTime, endTime) + "ms"); - } + @GET + @Path("{name}") + public String hello(@PathParam("name") final String name) + { + return "Hello! " + name; + } + + public static void main(String[] args) throws Exception + { + LocalDateTime startTime = LocalDateTime.now(); + + //optional for class scanning optimization + IGuiceContext.registerModule("com.guicedee.examples.jaxrs.basic"); + Undertow boot = GuicedUndertow.boot("0.0.0.0", 6003); + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("Started in " + ChronoUnit.MILLIS.between(startTime, endTime) + "ms"); + } } diff --git a/Jaxrs/Basic/src/main/java/module-info.java b/Jaxrs/Basic/src/main/java/module-info.java index 2212bb6..872cff9 100644 --- a/Jaxrs/Basic/src/main/java/module-info.java +++ b/Jaxrs/Basic/src/main/java/module-info.java @@ -1,9 +1,10 @@ module com.guicedee.examples.jaxrs.basic { + requires com.guicedee.guicedinjection; requires com.guicedee.guicedservlets.rest; requires com.guicedee.guicedservlets.undertow; requires java.net.http; - - exports com.guicedee.examples.jaxrs.basic; + + exports com.guicedee.examples.jaxrs.basic; opens com.guicedee.examples.jaxrs.basic to com.google.guice, com.fasterxml.jackson.databind, org.apache.cxf; } diff --git a/Jaxrs/Basic/src/test/java/com/guicedee/examples/jaxrs/basic/tests/HelloWorldTest.java b/Jaxrs/Basic/src/test/java/com/guicedee/examples/jaxrs/basic/tests/HelloWorldTest.java index e97dba4..b41835a 100644 --- a/Jaxrs/Basic/src/test/java/com/guicedee/examples/jaxrs/basic/tests/HelloWorldTest.java +++ b/Jaxrs/Basic/src/test/java/com/guicedee/examples/jaxrs/basic/tests/HelloWorldTest.java @@ -32,6 +32,6 @@ public void testWorld() throws Exception System.out.println(response.body()); assertEquals(200, response.statusCode()); - GuiceContext.destroy(); + GuiceContext.instance().destroy(); } } \ No newline at end of file diff --git a/Jaxrs/Basic/src/test/java/module-info.java b/Jaxrs/Basic/src/test/java/module-info.java index c673775..c448b36 100644 --- a/Jaxrs/Basic/src/test/java/module-info.java +++ b/Jaxrs/Basic/src/test/java/module-info.java @@ -6,6 +6,7 @@ requires com.guicedee.guicedservlets.rest; requires com.guicedee.guicedservlets.undertow; + requires com.guicedee.guicedinjection; opens com.guicedee.examples.jaxrs.basic.tests to com.google.guice, com.fasterxml.jackson.databind, org.apache.cxf,org.junit.platform.commons; } \ No newline at end of file diff --git a/Jaxrs/Binding/pom.xml b/Jaxrs/Binding/pom.xml index d9bd658..93613d0 100644 --- a/Jaxrs/Binding/pom.xml +++ b/Jaxrs/Binding/pom.xml @@ -25,6 +25,16 @@ com.guicedee.servlets guiced-rest-services + + com.guicedee + guice-inject-client + + + com.guicedee + guice-injection + + + com.guicedee.servlets guiced-openapi diff --git a/Jaxrs/Binding/src/main/java/com/guicedee/examples/jaxrs/binding/BootJaxRSBindings.java b/Jaxrs/Binding/src/main/java/com/guicedee/examples/jaxrs/binding/BootJaxRSBindings.java index a11dad3..cc46e4e 100644 --- a/Jaxrs/Binding/src/main/java/com/guicedee/examples/jaxrs/binding/BootJaxRSBindings.java +++ b/Jaxrs/Binding/src/main/java/com/guicedee/examples/jaxrs/binding/BootJaxRSBindings.java @@ -1,15 +1,15 @@ package com.guicedee.examples.jaxrs.binding; -import com.guicedee.guicedinjection.GuiceContext; +import com.guicedee.client.IGuiceContext; import com.guicedee.guicedservlets.undertow.GuicedUndertow; import io.undertow.Undertow; public class BootJaxRSBindings { - public static void main(String... args) throws Exception - { - GuiceContext.registerModule("com.guicedee.examples.jaxrs.binding"); - Undertow undertow = GuicedUndertow.boot("0.0.0.0", 6003); - } + public static void main(String... args) throws Exception + { + IGuiceContext.registerModule("com.guicedee.examples.jaxrs.binding"); + Undertow undertow = GuicedUndertow.boot("0.0.0.0", 6003); + } } diff --git a/Jaxrs/Binding/src/main/java/com/guicedee/examples/jaxrs/binding/resources/RestApplication.java b/Jaxrs/Binding/src/main/java/com/guicedee/examples/jaxrs/binding/resources/RestApplication.java index 4f656a6..9e1534b 100644 --- a/Jaxrs/Binding/src/main/java/com/guicedee/examples/jaxrs/binding/resources/RestApplication.java +++ b/Jaxrs/Binding/src/main/java/com/guicedee/examples/jaxrs/binding/resources/RestApplication.java @@ -1,6 +1,6 @@ package com.guicedee.examples.jaxrs.binding.resources; -import com.guicedee.guicedinjection.GuiceContext; +import com.guicedee.client.IGuiceContext; import jakarta.ws.rs.core.Application; import java.util.HashSet; @@ -9,20 +9,20 @@ public class RestApplication extends Application { - private final Set> classes = new HashSet<>(); - private final Set singletons = new HashSet<>(); - - @Override - public Set> getClasses() - { - return classes; - } - - @Override - public Set getSingletons() - { - //If using application way, can register individual services - singletons.add(GuiceContext.get(HelloResource.class)); - return singletons; - } + private final Set> classes = new HashSet<>(); + private final Set singletons = new HashSet<>(); + + @Override + public Set> getClasses() + { + return classes; + } + + @Override + public Set getSingletons() + { + //If using application way, can register individual services + singletons.add(IGuiceContext.get(HelloResource.class)); + return singletons; + } } diff --git a/Jaxrs/Binding/src/main/java/module-info.java b/Jaxrs/Binding/src/main/java/module-info.java index fecb08c..ffc5610 100644 --- a/Jaxrs/Binding/src/main/java/module-info.java +++ b/Jaxrs/Binding/src/main/java/module-info.java @@ -2,18 +2,19 @@ import com.guicedee.guicedinjection.interfaces.IGuiceModule; module com.guicedee.examples.jaxrs.binding { - exports com.guicedee.examples.jaxrs.binding to com.guicedee.examples.jaxrs.binding.test; - - requires com.guicedee.guicedservlets.rest; - requires com.guicedee.guicedservlets.undertow; - - requires java.net.http; - requires jakarta.ws.rs; + exports com.guicedee.examples.jaxrs.binding to com.guicedee.examples.jaxrs.binding.test; - provides IGuiceModule with RestTestBinding; + requires com.guicedee.guicedservlets.rest; + requires com.guicedee.guicedservlets.undertow; + requires com.guicedee.guicedinjection; - opens com.guicedee.examples.jaxrs.binding to com.google.guice, com.fasterxml.jackson.databind, org.apache.cxf; - opens com.guicedee.examples.jaxrs.binding.implementations to com.fasterxml.jackson.databind, com.google.guice, org.apache.cxf; - opens com.guicedee.examples.jaxrs.binding.resources to com.fasterxml.jackson.databind, com.google.guice, org.apache.cxf; + requires java.net.http; + requires jakarta.ws.rs; + + provides IGuiceModule with RestTestBinding; + + opens com.guicedee.examples.jaxrs.binding to com.google.guice, com.fasterxml.jackson.databind, org.apache.cxf; + opens com.guicedee.examples.jaxrs.binding.implementations to com.fasterxml.jackson.databind, com.google.guice, org.apache.cxf; + opens com.guicedee.examples.jaxrs.binding.resources to com.fasterxml.jackson.databind, com.google.guice, org.apache.cxf; } diff --git a/Jaxrs/Binding/src/test/java/com/guicedee/examples/jaxrs/binding/test/BootJaxRSBindingsTest.java b/Jaxrs/Binding/src/test/java/com/guicedee/examples/jaxrs/binding/test/BootJaxRSBindingsTest.java index 27c3bb9..b2612f9 100644 --- a/Jaxrs/Binding/src/test/java/com/guicedee/examples/jaxrs/binding/test/BootJaxRSBindingsTest.java +++ b/Jaxrs/Binding/src/test/java/com/guicedee/examples/jaxrs/binding/test/BootJaxRSBindingsTest.java @@ -1,9 +1,7 @@ package com.guicedee.examples.jaxrs.binding.test; +import com.guicedee.client.IGuiceContext; import com.guicedee.examples.jaxrs.binding.BootJaxRSBindings; -import com.guicedee.guicedinjection.GuiceContext; -import com.guicedee.guicedservlets.undertow.GuicedUndertow; -import io.undertow.Undertow; import org.junit.jupiter.api.Test; import java.net.URI; @@ -13,35 +11,36 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class BootJaxRSBindingsTest { - @Test - public void testRS() throws Exception - { - BootJaxRSBindings.main(null); - - HttpClient client = HttpClient.newBuilder() - .connectTimeout(Duration.of(5, ChronoUnit.SECONDS)) - .build(); - HttpResponse response = client.send(HttpRequest.newBuilder() - .GET() - .uri(new URI("http://localhost:6003/rest/hello/world")) - .build(), - HttpResponse.BodyHandlers.ofString()); - System.out.println(response.body()); - assertEquals(200, response.statusCode()); - response = client.send(HttpRequest.newBuilder() - .GET() - .uri(new URI("http://localhost:6003/rest/hello/helloObject/world")) - .build(), - HttpResponse.BodyHandlers.ofString()); - System.out.println(response.body()); - - assertEquals(200, response.statusCode()); - - GuiceContext.destroy(); - } + @Test + public void testRS() throws Exception + { + BootJaxRSBindings.main(null); + + HttpClient client = HttpClient.newBuilder() + .connectTimeout(Duration.of(5, ChronoUnit.SECONDS)) + .build(); + HttpResponse response = client.send(HttpRequest.newBuilder() + .GET() + .uri(new URI("http://localhost:6003/rest/hello/world")) + .build(), + HttpResponse.BodyHandlers.ofString()); + System.out.println(response.body()); + assertEquals(200, response.statusCode()); + response = client.send(HttpRequest.newBuilder() + .GET() + .uri(new URI("http://localhost:6003/rest/hello/helloObject/world")) + .build(), + HttpResponse.BodyHandlers.ofString()); + System.out.println(response.body()); + + assertEquals(200, response.statusCode()); + + IGuiceContext.instance() + .destroy(); + } } \ No newline at end of file diff --git a/Jaxrs/Binding/src/test/java/module-info.java b/Jaxrs/Binding/src/test/java/module-info.java index 11fcbac..9539581 100644 --- a/Jaxrs/Binding/src/test/java/module-info.java +++ b/Jaxrs/Binding/src/test/java/module-info.java @@ -1,12 +1,14 @@ open module com.guicedee.examples.jaxrs.binding.test { - requires com.guicedee.examples.jaxrs.binding; - requires org.junit.jupiter.api; - - requires java.net.http; - - requires org.junit.jupiter; - - requires com.guicedee.guicedservlets.rest; - requires com.guicedee.guicedservlets.undertow; - + requires com.guicedee.examples.jaxrs.binding; + + requires org.junit.jupiter.api; + + requires java.net.http; + + requires org.junit.jupiter; + + requires com.guicedee.guicedservlets.rest; + requires com.guicedee.guicedservlets.undertow; + requires com.guicedee.guicedinjection; + } \ No newline at end of file