ratpack with google guice (#1542)
* rest with spark java * 4 * Update Application.java * indentation changes * spring @requestmapping shortcuts * removing spring requestmapping and pushing spring-mvc-java * Joining/Splitting Strings with Java and Stream API * adding more join/split functionality * changing package name * testcase change * adding webutils * adding testcase for WebUtils and ServletRequestUtils * adding testcase * spring-security-stormpath * adding ratpack module * adding pom.xml * adding following modules with updated testcase : DB, Filter, Json * adding spring-boot custom banner tutorial * changing banner format in plain text * Delete banner.txt~ * Delete b.txt~ * CORS in JAX-RS * ratpack with google guice
This commit is contained in:
parent
99688e9b19
commit
d3590de13c
31
ratpack/src/main/java/com/baeldung/guice/Application.java
Normal file
31
ratpack/src/main/java/com/baeldung/guice/Application.java
Normal file
@ -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());
|
||||
// })));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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<Employee> employees = new ArrayList<Employee>();
|
||||
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();
|
||||
|
8
resteasy/bin/README.md
Normal file
8
resteasy/bin/README.md
Normal file
@ -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)
|
171
resteasy/bin/pom.xml
Normal file
171
resteasy/bin/pom.xml
Normal file
@ -0,0 +1,171 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>resteasy-tutorial</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<resteasy.version>3.0.19.Final</resteasy.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>RestEasyTutorial</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
<artifactId>cargo-maven2-plugin</artifactId>
|
||||
<version>${cargo-maven2-plugin.version}</version>
|
||||
<configuration>
|
||||
<wait>true</wait>
|
||||
<container>
|
||||
<containerId>jetty8x</containerId>
|
||||
<type>embedded</type>
|
||||
</container>
|
||||
<configuration>
|
||||
<properties>
|
||||
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||
</properties>
|
||||
</configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- core library -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-servlet-initializer</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-client</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Optional library -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxb-provider</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jackson-provider</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Junit Library -->
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>live</id>
|
||||
<build>
|
||||
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*LiveTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
<artifactId>cargo-maven2-plugin</artifactId>
|
||||
<version>${cargo-maven2-plugin.version}</version>
|
||||
<configuration>
|
||||
<wait>false</wait>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-server</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-server</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
3
resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml
Normal file
3
resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
|
||||
</configuration>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<jboss-deployment-structure>
|
||||
<deployment>
|
||||
<exclude-subsystems>
|
||||
<subsystem name="resteasy"/>
|
||||
</exclude-subsystems>
|
||||
<exclusions>
|
||||
<module name="javaee.api"/><module name="javax.ws.rs.api"/>
|
||||
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
|
||||
</exclusions>
|
||||
<local-last value="true"/>
|
||||
</deployment>
|
||||
</jboss-deployment-structure>
|
4
resteasy/bin/src/main/webapp/WEB-INF/jboss-web.xml
Normal file
4
resteasy/bin/src/main/webapp/WEB-INF/jboss-web.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 4.2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
|
||||
<jboss-web>
|
||||
</jboss-web>
|
13
resteasy/bin/src/main/webapp/WEB-INF/web.xml
Normal file
13
resteasy/bin/src/main/webapp/WEB-INF/web.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
|
||||
|
||||
<display-name>RestEasy Example</display-name>
|
||||
|
||||
<context-param>
|
||||
<param-name>resteasy.servlet.mapping.prefix</param-name>
|
||||
<param-value>/rest</param-value>
|
||||
</context-param>
|
||||
|
||||
</web-app>
|
16
resteasy/bin/src/main/webapp/script.js
Normal file
16
resteasy/bin/src/main/webapp/script.js
Normal file
@ -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);
|
||||
});
|
||||
};
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "Batman",
|
||||
"imdbId": "tt0096895"
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "Transformers",
|
||||
"imdbId": "tt0418279"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user