Skip to content

Commit d3590de

Browse files
AbhinabKanrarmaibin
authored andcommitted
ratpack with google guice (eugenp#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
1 parent 99688e9 commit d3590de

14 files changed

Lines changed: 317 additions & 4 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.guice;
2+
3+
import com.baeldung.guice.config.DependencyModule;
4+
import com.baeldung.guice.service.DataPumpService;
5+
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
6+
7+
import ratpack.guice.Guice;
8+
import ratpack.server.RatpackServer;
9+
10+
public class Application {
11+
12+
public static void main(String[] args) throws Exception {
13+
14+
RatpackServer
15+
.start(server -> server.registry(Guice.registry(bindings -> bindings.module(DependencyModule.class)))
16+
.handlers(chain -> chain.get("randomString", ctx -> {
17+
DataPumpService dataPumpService = ctx.get(DataPumpService.class);
18+
ctx.render(dataPumpService.generate().length());
19+
})));
20+
21+
// RatpackServer.start(server -> server
22+
// .registry(Guice
23+
// .registry(bindings -> bindings.bindInstance(DataPumpService.class, new DataPumpServiceImpl())))
24+
// .handlers(chain -> chain.get("randomString", ctx -> {
25+
// DataPumpService dataPumpService = ctx.get(DataPumpService.class);
26+
// ctx.render(dataPumpService.generate());
27+
// })));
28+
29+
}
30+
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.guice.config;
2+
3+
import com.baeldung.guice.service.DataPumpService;
4+
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
5+
import com.google.inject.AbstractModule;
6+
import com.google.inject.Scopes;
7+
8+
public class DependencyModule extends AbstractModule {
9+
10+
@Override
11+
protected void configure() {
12+
bind(DataPumpService.class).to(DataPumpServiceImpl.class)
13+
.in(Scopes.SINGLETON);
14+
}
15+
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.guice.service;
2+
3+
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
4+
import com.google.inject.ImplementedBy;
5+
6+
@ImplementedBy(DataPumpServiceImpl.class)
7+
public interface DataPumpService {
8+
9+
String generate();
10+
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.guice.service.impl;
2+
3+
import java.util.UUID;
4+
5+
import com.baeldung.guice.service.DataPumpService;
6+
7+
public class DataPumpServiceImpl implements DataPumpService {
8+
9+
@Override
10+
public String generate() {
11+
return UUID.randomUUID().toString();
12+
}
13+
14+
}

‎ratpack/src/test/java/com/baeldung/ApplicationTest.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,27 @@ public class ApplicationTest {
2424
public void givenDefaultUrl_getStaticText() {
2525
assertEquals("Welcome to baeldung ratpack!!!", appUnderTest.getHttpClient().getText("/"));
2626
}
27-
27+
2828
@Test
2929
public void givenDynamicUrl_getDynamicText() {
3030
assertEquals("Hello dummybot!!!", appUnderTest.getHttpClient().getText("/dummybot"));
3131
}
32-
32+
3333
@Test
3434
public void givenUrl_getListOfEmployee() throws JsonProcessingException {
3535
List<Employee> employees = new ArrayList<Employee>();
3636
ObjectMapper mapper = new ObjectMapper();
3737
employees.add(new Employee(1L, "Mr", "John Doe"));
3838
employees.add(new Employee(2L, "Mr", "White Snow"));
39-
39+
4040
assertEquals(mapper.writeValueAsString(employees), appUnderTest.getHttpClient().getText("/data/employees"));
4141
}
42-
42+
43+
@Test
44+
public void givenStaticUrl_getDynamicText() {
45+
assertEquals(21, appUnderTest.getHttpClient().getText("/randomString").length());
46+
}
47+
4348
@After
4449
public void shutdown() {
4550
appUnderTest.close();

‎resteasy/bin/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=========
2+
3+
## A Guide to RESTEasy
4+
5+
6+
### Relevant Articles:
7+
- [A Guide to RESTEasy](http://www.baeldung.com/resteasy-tutorial)
8+
- [RESTEasy Client API](http://www.baeldung.com/resteasy-client-tutorial)

‎resteasy/bin/pom.xml‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>resteasy-tutorial</artifactId>
8+
<version>1.0</version>
9+
<packaging>war</packaging>
10+
11+
<properties>
12+
<resteasy.version>3.0.19.Final</resteasy.version>
13+
<junit.version>4.12</junit.version>
14+
<commons-io.version>2.5</commons-io.version>
15+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
16+
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
17+
</properties>
18+
19+
<build>
20+
<finalName>RestEasyTutorial</finalName>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<configuration>
26+
<source>1.8</source>
27+
<target>1.8</target>
28+
</configuration>
29+
</plugin>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-surefire-plugin</artifactId>
33+
<version>${maven-surefire-plugin.version}</version>
34+
<configuration>
35+
<excludes>
36+
<exclude>**/*IntegrationTest.java</exclude>
37+
<exclude>**/*LiveTest.java</exclude>
38+
</excludes>
39+
</configuration>
40+
</plugin>
41+
42+
<plugin>
43+
<groupId>org.codehaus.cargo</groupId>
44+
<artifactId>cargo-maven2-plugin</artifactId>
45+
<version>${cargo-maven2-plugin.version}</version>
46+
<configuration>
47+
<wait>true</wait>
48+
<container>
49+
<containerId>jetty8x</containerId>
50+
<type>embedded</type>
51+
</container>
52+
<configuration>
53+
<properties>
54+
<cargo.servlet.port>8082</cargo.servlet.port>
55+
</properties>
56+
</configuration>
57+
</configuration>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
62+
<dependencies>
63+
64+
<!-- core library -->
65+
66+
<dependency>
67+
<groupId>org.jboss.resteasy</groupId>
68+
<artifactId>resteasy-servlet-initializer</artifactId>
69+
<version>${resteasy.version}</version>
70+
</dependency>
71+
72+
73+
<dependency>
74+
<groupId>org.jboss.resteasy</groupId>
75+
<artifactId>resteasy-client</artifactId>
76+
<version>${resteasy.version}</version>
77+
</dependency>
78+
79+
<!-- Optional library -->
80+
81+
<dependency>
82+
<groupId>org.jboss.resteasy</groupId>
83+
<artifactId>resteasy-jaxb-provider</artifactId>
84+
<version>${resteasy.version}</version>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>org.jboss.resteasy</groupId>
89+
<artifactId>resteasy-jackson-provider</artifactId>
90+
<version>${resteasy.version}</version>
91+
</dependency>
92+
93+
<!-- Junit Library -->
94+
95+
<dependency>
96+
<groupId>junit</groupId>
97+
<artifactId>junit</artifactId>
98+
<version>${junit.version}</version>
99+
</dependency>
100+
101+
<dependency>
102+
<groupId>commons-io</groupId>
103+
<artifactId>commons-io</artifactId>
104+
<version>${commons-io.version}</version>
105+
</dependency>
106+
107+
</dependencies>
108+
109+
<profiles>
110+
<profile>
111+
<id>live</id>
112+
<build>
113+
114+
<plugins>
115+
116+
<plugin>
117+
<groupId>org.apache.maven.plugins</groupId>
118+
<artifactId>maven-surefire-plugin</artifactId>
119+
<executions>
120+
<execution>
121+
<phase>integration-test</phase>
122+
<goals>
123+
<goal>test</goal>
124+
</goals>
125+
<configuration>
126+
<excludes>
127+
<exclude>**/*IntegrationTest.java</exclude>
128+
</excludes>
129+
<includes>
130+
<include>**/*LiveTest.java</include>
131+
</includes>
132+
</configuration>
133+
</execution>
134+
</executions>
135+
<configuration>
136+
<systemPropertyVariables>
137+
<test.mime>json</test.mime>
138+
</systemPropertyVariables>
139+
</configuration>
140+
</plugin>
141+
<plugin>
142+
<groupId>org.codehaus.cargo</groupId>
143+
<artifactId>cargo-maven2-plugin</artifactId>
144+
<version>${cargo-maven2-plugin.version}</version>
145+
<configuration>
146+
<wait>false</wait>
147+
</configuration>
148+
<executions>
149+
<execution>
150+
<id>start-server</id>
151+
<phase>pre-integration-test</phase>
152+
<goals>
153+
<goal>start</goal>
154+
</goals>
155+
</execution>
156+
<execution>
157+
<id>stop-server</id>
158+
<phase>post-integration-test</phase>
159+
<goals>
160+
<goal>stop</goal>
161+
</goals>
162+
</execution>
163+
</executions>
164+
</plugin>
165+
</plugins>
166+
167+
</build>
168+
</profile>
169+
</profiles>
170+
171+
</project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<configuration scan="true" scanPeriod="10 seconds">
2+
3+
</configuration>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<jboss-deployment-structure>
3+
<deployment>
4+
<exclude-subsystems>
5+
<subsystem name="resteasy"/>
6+
</exclude-subsystems>
7+
<exclusions>
8+
<module name="javaee.api"/><module name="javax.ws.rs.api"/>
9+
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
10+
</exclusions>
11+
<local-last value="true"/>
12+
</deployment>
13+
</jboss-deployment-structure>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 4.2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
3+
<jboss-web>
4+
</jboss-web>

0 commit comments

Comments
 (0)