Skip to content

Commit c4832e3

Browse files
committed
adding source, verified on WildFly
1 parent f5affc1 commit c4832e3

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

pom.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
5+
<groupId>org.javaee7.sample</groupId>
6+
<artifactId>helloworld</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>war</packaging>
9+
10+
<name>helloworld</name>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>javax</groupId>
19+
<artifactId>javaee-api</artifactId>
20+
<version>7.0</version>
21+
<scope>provided</scope>
22+
</dependency>
23+
</dependencies>
24+
25+
<build>
26+
<finalName>helloworld</finalName>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-compiler-plugin</artifactId>
31+
<version>3.1</version>
32+
<configuration>
33+
<source>1.7</source>
34+
<target>1.7</target>
35+
</configuration>
36+
</plugin>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-war-plugin</artifactId>
40+
<version>2.3</version>
41+
<configuration>
42+
<failOnMissingWebXml>false</failOnMissingWebXml>
43+
</configuration>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
48+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.javaee7.sample;
2+
3+
import javax.ws.rs.ApplicationPath;
4+
import javax.ws.rs.core.Application;
5+
6+
@ApplicationPath("/resources")
7+
public class MyApplication extends Application {
8+
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.javaee7.sample;
2+
3+
import javax.enterprise.context.RequestScoped;
4+
import javax.inject.Inject;
5+
import javax.ws.rs.GET;
6+
import javax.ws.rs.Path;
7+
import javax.ws.rs.PathParam;
8+
9+
@RequestScoped
10+
@Path("persons")
11+
public class Person {
12+
13+
@Inject PersonDatabase database;
14+
15+
@GET
16+
public String get() {
17+
return database.currentList().toString();
18+
}
19+
20+
@GET
21+
@Path("{id}")
22+
public String get(@PathParam("id")int id) {
23+
return database.getPerson(id);
24+
}
25+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
@Singleton
11+
public class PersonDatabase {
12+
List<String> persons;
13+
14+
@PostConstruct
15+
public void init() {
16+
persons = Arrays.asList("Penny", "Leonard", "Sheldon", "Amy", "Howard", "Bernadette", "Raj", "Priya");
17+
}
18+
19+
public List<String> currentList() {
20+
return persons;
21+
}
22+
23+
public String getPerson(int id) {
24+
if (id < persons.size())
25+
return persons.get(id);
26+
27+
throw new NotFoundException("Person with id \"" + id + "\" not found.");
28+
}
29+
30+
public void addPerson(String name) {
31+
persons.add(name);
32+
}
33+
34+
public void deletePerson(String name) {
35+
if (persons.contains(name))
36+
persons.remove(name);
37+
38+
throw new NotFoundException("Person with name \"" + name + "\" not found.");
39+
}
40+
41+
}

src/main/webapp/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Hello Java EE 7 World!</title>
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6+
</head>
7+
<body>
8+
<h1>Hello Java EE 7 World!</h1>
9+
10+
Show all the
11+
<a href="/helloworld/resources/persons">persons</a>.
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)