Skip to content

Commit

Permalink
Guiced EE Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GedMarc committed Mar 3, 2024
1 parent b1c9bb5 commit 3d6cbaa
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 101 deletions.
6 changes: 6 additions & 0 deletions Jaxrs/Basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<artifactId>guiced-undertow</artifactId>
</dependency>

<dependency>
<groupId>com.guicedee</groupId>
<artifactId>guice-injection</artifactId>
</dependency>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
5 changes: 3 additions & 2 deletions Jaxrs/Basic/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public void testWorld() throws Exception
System.out.println(response.body());
assertEquals(200, response.statusCode());

GuiceContext.destroy();
GuiceContext.instance().destroy();
}
}
1 change: 1 addition & 0 deletions Jaxrs/Basic/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions Jaxrs/Binding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
<groupId>com.guicedee.servlets</groupId>
<artifactId>guiced-rest-services</artifactId>
</dependency>
<dependency>
<groupId>com.guicedee</groupId>
<artifactId>guice-inject-client</artifactId>
</dependency>
<dependency>
<groupId>com.guicedee</groupId>
<artifactId>guice-injection</artifactId>
</dependency>


<dependency>
<groupId>com.guicedee.servlets</groupId>
<artifactId>guiced-openapi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,20 +9,20 @@

public class RestApplication extends Application
{
private final Set<Class<?>> classes = new HashSet<>();
private final Set<Object> singletons = new HashSet<>();
@Override
public Set<Class<?>> getClasses()
{
return classes;
}
@Override
public Set<Object> getSingletons()
{
//If using application way, can register individual services
singletons.add(GuiceContext.get(HelloResource.class));
return singletons;
}
private final Set<Class<?>> classes = new HashSet<>();
private final Set<Object> singletons = new HashSet<>();

@Override
public Set<Class<?>> getClasses()
{
return classes;
}

@Override
public Set<Object> getSingletons()
{
//If using application way, can register individual services
singletons.add(IGuiceContext.get(HelloResource.class));
return singletons;
}
}
23 changes: 12 additions & 11 deletions Jaxrs/Binding/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
22 changes: 12 additions & 10 deletions Jaxrs/Binding/src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;

}

0 comments on commit 3d6cbaa

Please sign in to comment.