Skip to content

Commit 2c070e4

Browse files
committed
boilerplate Java EE 7 sample
0 parents  commit 2c070e4

8 files changed

Lines changed: 187 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/target/
2+
nb-*.xml

pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.javaee7.sample</groupId>
5+
<artifactId>javaee7-docker-maven</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>war</packaging>
8+
<name>javaee7-docker-maven</name>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>javax</groupId>
13+
<artifactId>javaee-api</artifactId>
14+
<version>7.0</version>
15+
<scope>provided</scope>
16+
</dependency>
17+
</dependencies>
18+
<build>
19+
<finalName>javaee7-docker-maven</finalName>
20+
<plugins>
21+
<plugin>
22+
<artifactId>maven-compiler-plugin</artifactId>
23+
<version>3.1</version>
24+
<configuration>
25+
<source>1.7</source>
26+
<target>1.7</target>
27+
</configuration>
28+
</plugin>
29+
<plugin>
30+
<artifactId>maven-war-plugin</artifactId>
31+
<version>2.3</version>
32+
<configuration>
33+
<failOnMissingWebXml>false</failOnMissingWebXml>
34+
</configuration>
35+
</plugin>
36+
<plugin>
37+
<groupId>org.wildfly.plugins</groupId>
38+
<artifactId>wildfly-maven-plugin</artifactId>
39+
<version>1.0.2.Final</version>
40+
<!-- <executions>
41+
<execution>
42+
<phase>install</phase>
43+
<goals>
44+
<goal>deploy</goal>
45+
</goals>
46+
</execution>
47+
</executions>-->
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.javaee7.sample;
2+
3+
import javax.ws.rs.ApplicationPath;
4+
import javax.ws.rs.core.Application;
5+
6+
/**
7+
* @author arungupta
8+
*/
9+
@ApplicationPath("/resources")
10+
public class MyApplication extends Application {
11+
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.javaee7.sample;
2+
3+
import javax.xml.bind.annotation.XmlRootElement;
4+
5+
/**
6+
* @author arungupta
7+
*/
8+
@XmlRootElement
9+
public class Person {
10+
private String name;
11+
12+
public Person() {
13+
}
14+
15+
public Person(String name) {
16+
this.name = name;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public void setName(String name) {
24+
this.name = name;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return name;
30+
}
31+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.javaee7.sample;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import javax.annotation.PostConstruct;
7+
import javax.inject.Singleton;
8+
import javax.ws.rs.NotFoundException;
9+
10+
/**
11+
* @author arungupta
12+
*/
13+
@Singleton
14+
public class PersonDatabase {
15+
16+
List<Person> persons;
17+
18+
@PostConstruct
19+
public void init() {
20+
persons = Arrays.asList(
21+
new Person("Penny"),
22+
new Person("Leonard"),
23+
new Person("Sheldon"),
24+
new Person("Amy"),
25+
new Person("Howard"),
26+
new Person("Bernadette"),
27+
new Person("Raj"),
28+
new Person("Priya"));
29+
}
30+
31+
public Person[] currentList() {
32+
return persons.toArray(new Person[0]);
33+
}
34+
35+
public Person getPerson(int id) {
36+
if (id < persons.size()) {
37+
return persons.get(id);
38+
}
39+
40+
throw new NotFoundException("Person with id \"" + id + "\" not found.");
41+
}
42+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.javaee7.sample;
2+
3+
import javax.inject.Inject;
4+
import javax.ws.rs.GET;
5+
import javax.ws.rs.Path;
6+
import javax.ws.rs.PathParam;
7+
import javax.ws.rs.Produces;
8+
9+
/**
10+
* @author arungupta
11+
*/
12+
@Path("persons")
13+
public class PersonResource {
14+
15+
@Inject
16+
PersonDatabase database;
17+
18+
@GET
19+
@Produces("application/xml")
20+
public Person[] get() {
21+
return database.currentList();
22+
}
23+
24+
@GET
25+
@Path("{id}")
26+
@Produces("application/xml")
27+
public Person get(@PathParam("id") int id) {
28+
return database.getPerson(id);
29+
}
30+
}

src/main/webapp/WEB-INF/beans.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
5+
bean-discovery-mode="all">
6+
</beans>

src/main/webapp/index.jsp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<%@page contentType="text/html" pageEncoding="UTF-8"%>
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6+
<title>Java EE 7 Docker Maven Sample</title>
7+
</head>
8+
<body>
9+
<h1>Java EE 7 Docker Maven Sample!</h1>
10+
11+
GET all the <a href="${pageContext.request.contextPath}/resources/persons"/>persons</a>.
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)