Skip to content

Commit 223a62b

Browse files
committed
Add Hello Springboot and Backend
1 parent b5f6470 commit 223a62b

File tree

14 files changed

+1008
-0
lines changed

14 files changed

+1008
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Compiled class file
22
*.class
3+
**/target/*
4+
5+
#Hidden files
6+
.*
37

48
# Log file
59
*.log

backend/pom.xml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
JBoss, Home of Professional Open Source
4+
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
5+
contributors by the @authors tag. See the copyright.txt in the
6+
distribution for a full listing of individual contributors.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<groupId>com.redhat.examples</groupId>
23+
<artifactId>backend</artifactId>
24+
<version>1.0</version>
25+
<packaging>war</packaging>
26+
27+
28+
<properties>
29+
<!-- Explicitly declaring the source encoding eliminates the following
30+
message: -->
31+
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
32+
resources, i.e. build is platform dependent! -->
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
35+
<!-- JBoss dependency versions -->
36+
<version.wildfly.maven.plugin>2.0.0.Final</version.wildfly.maven.plugin>
37+
38+
<!-- Define the version of the JBoss BOMs we want to import to specify
39+
tested stacks. -->
40+
<version.jboss.bom>8.2.2.Final</version.jboss.bom>
41+
42+
<!-- other plugin versions -->
43+
<version.compiler.plugin>3.1</version.compiler.plugin>
44+
<version.surefire.plugin>2.16</version.surefire.plugin>
45+
<version.war.plugin>2.5</version.war.plugin>
46+
47+
<!-- maven-compiler-plugin -->
48+
<maven.compiler.target>1.8</maven.compiler.target>
49+
<maven.compiler.source>1.8</maven.compiler.source>
50+
51+
<!-- Jackason Dependency -->
52+
<jackson-version>2.6.3</jackson-version>
53+
</properties>
54+
55+
56+
<dependencyManagement>
57+
<dependencies>
58+
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill
59+
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
60+
of artifacts. We use this here so that we always get the correct versions
61+
of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can
62+
read this as the JBoss stack of the Java EE 7 APIs, with some extras tools
63+
for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
64+
stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
65+
from the Hibernate family of projects) -->
66+
<dependency>
67+
<groupId>org.wildfly.bom</groupId>
68+
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
69+
<version>${version.jboss.bom}</version>
70+
<type>pom</type>
71+
<scope>import</scope>
72+
</dependency>
73+
</dependencies>
74+
</dependencyManagement>
75+
76+
<dependencies>
77+
78+
<!-- First declare the APIs we depend on and need for compilation. All
79+
of them are provided by JBoss WildFly -->
80+
81+
<!-- Import the CDI API, we use provided scope as the API is included in
82+
JBoss WildFly -->
83+
<dependency>
84+
<groupId>javax.enterprise</groupId>
85+
<artifactId>cdi-api</artifactId>
86+
<scope>provided</scope>
87+
</dependency>
88+
89+
<!-- Import the CDI API, we use provided scope as the API is included in
90+
JBoss WildFly -->
91+
<dependency>
92+
<groupId>org.jboss.spec.javax.servlet</groupId>
93+
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
94+
<scope>provided</scope>
95+
</dependency>
96+
97+
<!-- Import the Common Annotations API (JSR-250), we use provided scope
98+
as the API is included in JBoss WildFly -->
99+
<dependency>
100+
<groupId>org.jboss.spec.javax.annotation</groupId>
101+
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
102+
<scope>provided</scope>
103+
</dependency>
104+
105+
106+
<!-- Jackason dependency -->
107+
<dependency>
108+
<groupId>com.fasterxml.jackson.core</groupId>
109+
<artifactId>jackson-databind</artifactId>
110+
<version>${jackson-version}</version>
111+
</dependency>
112+
113+
</dependencies>
114+
115+
<build>
116+
<!-- Maven will append the version to the finalName (which is the name
117+
given to the generated war, and hence the context root) -->
118+
<finalName>ROOT</finalName>
119+
<plugins>
120+
<plugin>
121+
<artifactId>maven-war-plugin</artifactId>
122+
<version>${version.war.plugin}</version>
123+
<configuration>
124+
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
125+
<failOnMissingWebXml>false</failOnMissingWebXml>
126+
</configuration>
127+
</plugin>
128+
<!-- The WildFly plugin deploys your war to a local WildFly container -->
129+
<!-- To use, run: mvn package wildfly:deploy -->
130+
<plugin>
131+
<groupId>org.wildfly.plugins</groupId>
132+
<artifactId>wildfly-maven-plugin</artifactId>
133+
<version>${version.wildfly.maven.plugin}</version>
134+
</plugin>
135+
</plugins>
136+
</build>
137+
138+
<profiles>
139+
<profile>
140+
<!-- The default profile skips all tests, though you can tune it to run
141+
just unit tests based on a custom pattern -->
142+
<!-- Seperate profiles are provided for running all tests, including Arquillian
143+
tests that execute in the specified container -->
144+
<id>default</id>
145+
<activation>
146+
<activeByDefault>true</activeByDefault>
147+
</activation>
148+
<build>
149+
<plugins>
150+
<plugin>
151+
<artifactId>maven-surefire-plugin</artifactId>
152+
<version>${version.surefire.plugin}</version>
153+
<configuration>
154+
<skip>true</skip>
155+
</configuration>
156+
</plugin>
157+
</plugins>
158+
</build>
159+
</profile>
160+
161+
</profiles>
162+
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
* <p/>
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
* <p/>
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.redhat.examples.backend;
18+
19+
import com.fasterxml.jackson.databind.*;
20+
21+
import javax.servlet.*;
22+
import javax.servlet.annotation.*;
23+
import javax.servlet.http.*;
24+
import java.io.*;
25+
import java.net.*;
26+
27+
/**
28+
* Created by ceposta
29+
* <a href="http://christianposta.com/blog>http://christianposta.com/blog</a>.
30+
*/
31+
@WebServlet(urlPatterns = {"/api/backend"})
32+
public class BackendHttpServlet extends HttpServlet {
33+
34+
@Override
35+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
36+
resp.setContentType("application/json");
37+
38+
ObjectMapper mapper = new ObjectMapper();
39+
String greeting = req.getParameter("greeting");
40+
41+
ResponseDTO response = new ResponseDTO();
42+
response.setGreeting(greeting + " from cluster Backend");
43+
response.setTime(System.currentTimeMillis());
44+
response.setIp(getIp());
45+
46+
PrintWriter out = resp.getWriter();
47+
mapper.writerWithDefaultPrettyPrinter()
48+
.writeValue(out, response);
49+
}
50+
51+
private String getIp() {
52+
String hostname = null;
53+
try {
54+
hostname = InetAddress.getLocalHost().getHostAddress();
55+
} catch (UnknownHostException e) {
56+
hostname = "unknown";
57+
}
58+
return hostname;
59+
}
60+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
* <p/>
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
* <p/>
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.redhat.examples.backend;
18+
19+
/**
20+
* Created by ceposta
21+
* <a href="http://christianposta.com/blog>http://christianposta.com/blog</a>.
22+
*/
23+
public class ResponseDTO {
24+
private String greeting;
25+
private long time;
26+
private String ip;
27+
28+
public String getGreeting() {
29+
return greeting;
30+
}
31+
32+
public void setGreeting(String greeting) {
33+
this.greeting = greeting;
34+
}
35+
36+
public long getTime() {
37+
return time;
38+
}
39+
40+
public void setTime(long time) {
41+
this.time = time;
42+
}
43+
44+
public String getIp() {
45+
return ip;
46+
}
47+
48+
public void setIp(String ip) {
49+
this.ip = ip;
50+
}
51+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
JBoss, Home of Professional Open Source
4+
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
5+
contributors by the @authors tag. See the copyright.txt in the
6+
distribution for a full listing of individual contributors.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<!-- Marker file indicating CDI should be enabled -->
19+
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="
21+
http://xmlns.jcp.org/xml/ns/javaee
22+
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
23+
</beans>

0 commit comments

Comments
 (0)