diff --git a/ratpack/src/main/java/com/baeldung/guice/Application.java b/ratpack/src/main/java/com/baeldung/guice/Application.java new file mode 100644 index 0000000000..39d29b9b2b --- /dev/null +++ b/ratpack/src/main/java/com/baeldung/guice/Application.java @@ -0,0 +1,31 @@ +package com.baeldung.guice; + +import com.baeldung.guice.config.DependencyModule; +import com.baeldung.guice.service.DataPumpService; +import com.baeldung.guice.service.impl.DataPumpServiceImpl; + +import ratpack.guice.Guice; +import ratpack.server.RatpackServer; + +public class Application { + + public static void main(String[] args) throws Exception { + + RatpackServer + .start(server -> server.registry(Guice.registry(bindings -> bindings.module(DependencyModule.class))) + .handlers(chain -> chain.get("randomString", ctx -> { + DataPumpService dataPumpService = ctx.get(DataPumpService.class); + ctx.render(dataPumpService.generate().length()); + }))); + +// RatpackServer.start(server -> server +// .registry(Guice +// .registry(bindings -> bindings.bindInstance(DataPumpService.class, new DataPumpServiceImpl()))) +// .handlers(chain -> chain.get("randomString", ctx -> { +// DataPumpService dataPumpService = ctx.get(DataPumpService.class); +// ctx.render(dataPumpService.generate()); +// }))); + + } + +} diff --git a/ratpack/src/main/java/com/baeldung/guice/config/DependencyModule.java b/ratpack/src/main/java/com/baeldung/guice/config/DependencyModule.java new file mode 100644 index 0000000000..1824578501 --- /dev/null +++ b/ratpack/src/main/java/com/baeldung/guice/config/DependencyModule.java @@ -0,0 +1,16 @@ +package com.baeldung.guice.config; + +import com.baeldung.guice.service.DataPumpService; +import com.baeldung.guice.service.impl.DataPumpServiceImpl; +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; + +public class DependencyModule extends AbstractModule { + + @Override + protected void configure() { + bind(DataPumpService.class).to(DataPumpServiceImpl.class) + .in(Scopes.SINGLETON); + } + +} diff --git a/ratpack/src/main/java/com/baeldung/guice/service/DataPumpService.java b/ratpack/src/main/java/com/baeldung/guice/service/DataPumpService.java new file mode 100644 index 0000000000..6adfec2365 --- /dev/null +++ b/ratpack/src/main/java/com/baeldung/guice/service/DataPumpService.java @@ -0,0 +1,11 @@ +package com.baeldung.guice.service; + +import com.baeldung.guice.service.impl.DataPumpServiceImpl; +import com.google.inject.ImplementedBy; + +@ImplementedBy(DataPumpServiceImpl.class) +public interface DataPumpService { + + String generate(); + +} diff --git a/ratpack/src/main/java/com/baeldung/guice/service/impl/DataPumpServiceImpl.java b/ratpack/src/main/java/com/baeldung/guice/service/impl/DataPumpServiceImpl.java new file mode 100644 index 0000000000..88f171f8a2 --- /dev/null +++ b/ratpack/src/main/java/com/baeldung/guice/service/impl/DataPumpServiceImpl.java @@ -0,0 +1,14 @@ +package com.baeldung.guice.service.impl; + +import java.util.UUID; + +import com.baeldung.guice.service.DataPumpService; + +public class DataPumpServiceImpl implements DataPumpService { + + @Override + public String generate() { + return UUID.randomUUID().toString(); + } + +} diff --git a/ratpack/src/test/java/com/baeldung/ApplicationTest.java b/ratpack/src/test/java/com/baeldung/ApplicationTest.java index 0333441928..047575ca6e 100644 --- a/ratpack/src/test/java/com/baeldung/ApplicationTest.java +++ b/ratpack/src/test/java/com/baeldung/ApplicationTest.java @@ -24,22 +24,27 @@ public class ApplicationTest { public void givenDefaultUrl_getStaticText() { assertEquals("Welcome to baeldung ratpack!!!", appUnderTest.getHttpClient().getText("/")); } - + @Test public void givenDynamicUrl_getDynamicText() { assertEquals("Hello dummybot!!!", appUnderTest.getHttpClient().getText("/dummybot")); } - + @Test public void givenUrl_getListOfEmployee() throws JsonProcessingException { List employees = new ArrayList(); ObjectMapper mapper = new ObjectMapper(); employees.add(new Employee(1L, "Mr", "John Doe")); employees.add(new Employee(2L, "Mr", "White Snow")); - + assertEquals(mapper.writeValueAsString(employees), appUnderTest.getHttpClient().getText("/data/employees")); } - + + @Test + public void givenStaticUrl_getDynamicText() { + assertEquals(21, appUnderTest.getHttpClient().getText("/randomString").length()); + } + @After public void shutdown() { appUnderTest.close(); diff --git a/resteasy/bin/README.md b/resteasy/bin/README.md new file mode 100644 index 0000000000..722f1dfe93 --- /dev/null +++ b/resteasy/bin/README.md @@ -0,0 +1,8 @@ +========= + +## A Guide to RESTEasy + + +### Relevant Articles: +- [A Guide to RESTEasy](http://www.baeldung.com/resteasy-tutorial) +- [RESTEasy Client API](http://www.baeldung.com/resteasy-client-tutorial) diff --git a/resteasy/bin/pom.xml b/resteasy/bin/pom.xml new file mode 100644 index 0000000000..f0bd8298f5 --- /dev/null +++ b/resteasy/bin/pom.xml @@ -0,0 +1,171 @@ + + + 4.0.0 + + com.baeldung + resteasy-tutorial + 1.0 + war + + + 3.0.19.Final + 4.12 + 2.5 + 2.19.1 + 1.6.1 + + + + RestEasyTutorial + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + true + + jetty8x + embedded + + + + 8082 + + + + + + + + + + + + + org.jboss.resteasy + resteasy-servlet-initializer + ${resteasy.version} + + + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + + + + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + + + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + + + + + + junit + junit + ${junit.version} + + + + commons-io + commons-io + ${commons-io.version} + + + + + + + live + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*IntegrationTest.java + + + **/*LiveTest.java + + + + + + + json + + + + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + false + + + + start-server + pre-integration-test + + start + + + + stop-server + post-integration-test + + stop + + + + + + + + + + + \ No newline at end of file diff --git a/resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml b/resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml new file mode 100644 index 0000000000..d94e9f71ab --- /dev/null +++ b/resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/resteasy/bin/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/resteasy/bin/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000000..cb258374a1 --- /dev/null +++ b/resteasy/bin/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/resteasy/bin/src/main/webapp/WEB-INF/jboss-web.xml b/resteasy/bin/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000000..694bb71332 --- /dev/null +++ b/resteasy/bin/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/resteasy/bin/src/main/webapp/WEB-INF/web.xml b/resteasy/bin/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..d5f00293f4 --- /dev/null +++ b/resteasy/bin/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,13 @@ + + + + RestEasy Example + + + resteasy.servlet.mapping.prefix + /rest + + + \ No newline at end of file diff --git a/resteasy/bin/src/main/webapp/script.js b/resteasy/bin/src/main/webapp/script.js new file mode 100644 index 0000000000..88198887b0 --- /dev/null +++ b/resteasy/bin/src/main/webapp/script.js @@ -0,0 +1,16 @@ +function call(url, type, data) { + var request = $.ajax({ + url : url, + method : "GET", + data : (data) ? JSON.stringify(data) : "", + dataType : type + }); + + request.done(function(resp) { + console.log(resp); + }); + + request.fail(function(jqXHR, textStatus) { + console.log("Request failed: " + textStatus); + }); +}; \ No newline at end of file diff --git a/resteasy/bin/src/test/resources/com/baeldung/server/movies/batman.json b/resteasy/bin/src/test/resources/com/baeldung/server/movies/batman.json new file mode 100644 index 0000000000..82aaaa8f40 --- /dev/null +++ b/resteasy/bin/src/test/resources/com/baeldung/server/movies/batman.json @@ -0,0 +1,4 @@ +{ + "title": "Batman", + "imdbId": "tt0096895" +} \ No newline at end of file diff --git a/resteasy/bin/src/test/resources/com/baeldung/server/movies/transformer.json b/resteasy/bin/src/test/resources/com/baeldung/server/movies/transformer.json new file mode 100644 index 0000000000..634cefc73c --- /dev/null +++ b/resteasy/bin/src/test/resources/com/baeldung/server/movies/transformer.json @@ -0,0 +1,4 @@ +{ + "title": "Transformers", + "imdbId": "tt0418279" +} \ No newline at end of file