Skip to content

Commit 7938dca

Browse files
committed
Added sample (no test yet) for Servlet 4.0's mapping API
1 parent d5386f3 commit 7938dca

File tree

7 files changed

+156
-46
lines changed

7 files changed

+156
-46
lines changed

pom.xml

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
-->
7070
<modules>
7171
<module>test-utils</module>
72+
<module>servlet</module>
7273
<module>cdi</module>
7374
</modules>
7475

@@ -102,6 +103,12 @@
102103
103104
(Since not released yet, temporarily uses constitute spec APIs)
104105
-->
106+
<dependency>
107+
<groupId>javax.servlet</groupId>
108+
<artifactId>javax.servlet-api</artifactId>
109+
<version>4.0.0-b07</version>
110+
</dependency>
111+
105112
<dependency>
106113
<groupId>javax.enterprise</groupId>
107114
<artifactId>cdi-api</artifactId>
@@ -424,41 +431,6 @@
424431
<id>payara-remote</id>
425432

426433
<dependencies>
427-
<dependency>
428-
<groupId>org.glassfish</groupId>
429-
<artifactId>javax.json</artifactId>
430-
<version>1.0.4</version>
431-
<scope>test</scope>
432-
</dependency>
433-
434-
<!-- WebSocket client dependencies -->
435-
<dependency>
436-
<groupId>org.glassfish.tyrus</groupId>
437-
<artifactId>tyrus-client</artifactId>
438-
<version>1.13.1</version>
439-
<scope>test</scope>
440-
</dependency>
441-
<dependency>
442-
<groupId>org.glassfish.tyrus</groupId>
443-
<artifactId>tyrus-container-grizzly-client</artifactId>
444-
<version>1.13.1</version>
445-
<scope>test</scope>
446-
</dependency>
447-
448-
<!-- JAX-RS client API dependencies -->
449-
<dependency>
450-
<groupId>org.glassfish.jersey.media</groupId>
451-
<artifactId>jersey-media-json-jackson</artifactId>
452-
<version>2.26-b09</version>
453-
<scope>test</scope>
454-
</dependency>
455-
<dependency>
456-
<groupId>org.glassfish.jersey.media</groupId>
457-
<artifactId>jersey-media-json-processing</artifactId>
458-
<version>2.26-b09</version>
459-
<scope>test</scope>
460-
</dependency>
461-
462434
<!-- The actual Arquillian connector -->
463435
<dependency>
464436
<groupId>org.omnifaces</groupId>
@@ -478,16 +450,6 @@
478450
</configuration>
479451
</plugin>
480452
</plugins>
481-
<testResources>
482-
<testResource>
483-
<directory>src/test/resources</directory>
484-
<filtering>true</filtering>
485-
</testResource>
486-
<testResource>
487-
<directory>src/test/resources-glassfish-remote</directory>
488-
<filtering>true</filtering>
489-
</testResource>
490-
</testResources>
491453
</build>
492454
</profile>
493455

servlet/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Java EE 8 Samples: Servlet 4.0#
2+
3+
The [JSR 369](https://jcp.org/en/jsr/detail?id=369) specifies the next version of Java Servlets - Java Servlets 4.0.
4+
5+
## Samples ##
6+
7+
- mapping
8+
9+

servlet/mapping/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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"> <modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>org.javaee8</groupId>
6+
<artifactId>servlet</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<groupId>org.javaee7</groupId>
11+
<artifactId>servlet-mapping</artifactId>
12+
<packaging>war</packaging>
13+
<name>Java EE 8 Sample: servlet - mapping</name>
14+
15+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.javaee8.servlet.mapping;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.ServletException;
6+
import javax.servlet.annotation.WebServlet;
7+
import javax.servlet.http.HttpServlet;
8+
import javax.servlet.http.HttpServletMapping;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
/**
13+
* @author Arjan Tijms
14+
*/
15+
@WebServlet({"/path/*", "*.ext", "", "/", "/exact"})
16+
public class Servlet extends HttpServlet {
17+
18+
private static final long serialVersionUID = 1L;
19+
20+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
21+
22+
HttpServletMapping mapping = request.getHttpServletMapping();
23+
24+
System.out.println(mapping);
25+
System.out.println(mapping.getMappingMatch());
26+
27+
response.getWriter()
28+
.append("Mapping match:")
29+
.append(mapping.getMappingMatch().name())
30+
.append("\n")
31+
.append("Match value:")
32+
.append(mapping.getMatchValue())
33+
.append("\n")
34+
.append("Pattern:")
35+
.append(mapping.getPattern());
36+
}
37+
38+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.javaee7.servlet.mapping;
2+
3+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
4+
import static org.junit.Assert.assertEquals;
5+
6+
import java.io.IOException;
7+
import java.net.URL;
8+
9+
import org.javaee8.servlet.mapping.Servlet;
10+
import org.jboss.arquillian.container.test.api.Deployment;
11+
import org.jboss.arquillian.junit.Arquillian;
12+
import org.jboss.arquillian.test.api.ArquillianResource;
13+
import org.jboss.shrinkwrap.api.spec.WebArchive;
14+
import org.junit.After;
15+
import org.junit.Before;
16+
import org.junit.Test;
17+
import org.junit.runner.RunWith;
18+
import org.xml.sax.SAXException;
19+
20+
import com.gargoylesoftware.htmlunit.TextPage;
21+
import com.gargoylesoftware.htmlunit.WebClient;
22+
23+
/**
24+
* @author Arjan Tijms
25+
*/
26+
@RunWith(Arquillian.class)
27+
public class ServletMappingTest {
28+
29+
@ArquillianResource
30+
private URL base;
31+
32+
private WebClient webClient;
33+
34+
@Deployment(testable = false)
35+
public static WebArchive createDeployment() {
36+
return create(WebArchive.class)
37+
.addClass(Servlet.class);
38+
}
39+
40+
@Before
41+
public void setup() {
42+
webClient = new WebClient();
43+
}
44+
45+
@After
46+
public void teardown() {
47+
webClient.close();
48+
}
49+
50+
@Test
51+
public void testGet() throws IOException {
52+
TextPage page = webClient.getPage(base + "foo.ext");
53+
54+
System.out.println(page.getContent());
55+
56+
assertEquals("", "");
57+
}
58+
59+
60+
}

servlet/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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"> <modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>org.javaee8</groupId>
6+
<artifactId>samples-parent</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>servlet</artifactId>
11+
<packaging>pom</packaging>
12+
13+
<name>Java EE 8 Sample: servlet</name>
14+
15+
<modules>
16+
<module>mapping</module>
17+
</modules>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.javaee8</groupId>
22+
<artifactId>test-utils</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
</dependencies>
26+
</project>

test-utils/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>junit</groupId>
1818
<artifactId>junit</artifactId>
19-
<version>4.11</version>
19+
<version>4.12</version>
2020
</dependency>
2121
<dependency>
2222
<groupId>org.jboss.arquillian.container</groupId>

0 commit comments

Comments
 (0)