Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit be7d1b2

Browse files
Added sample that shows a servlet present in a WEB-INF/lib jar.
Signed-off-by: arjantijms <arjan.tijms@gmail.com>
1 parent 7471ec9 commit be7d1b2

File tree

6 files changed

+186
-0
lines changed

6 files changed

+186
-0
lines changed

‎servlet/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<module>resource-packaging</module>
2828
<module>file-upload</module>
2929
<module>programmatic-registration</module>
30+
<module>servlet-libs</module>
3031

3132
<!-- Security samples assuming the container identity store -->
3233
<module>security-basicauth</module>
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+
<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+
<parent>
6+
<groupId>org.javaee7</groupId>
7+
<artifactId>servlet-libs</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>empty-app-servlet-lib</artifactId>
12+
<packaging>war</packaging>
13+
14+
<name>Java EE 7 Sample: servlet - empty-app-servlet-lib</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.javaee7</groupId>
19+
<artifactId>servlet-lib</artifactId>
20+
<version>1.0-SNAPSHOT</version>
21+
</dependency>
22+
</dependencies>
23+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.javaee7.servlet.servlet_libs.empty.app;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.net.MalformedURLException;
6+
import java.net.URISyntaxException;
7+
import java.net.URL;
8+
9+
import javax.ws.rs.client.ClientBuilder;
10+
11+
import org.jboss.arquillian.container.test.api.Deployment;
12+
import org.jboss.arquillian.container.test.api.RunAsClient;
13+
import org.jboss.arquillian.junit.Arquillian;
14+
import org.jboss.arquillian.test.api.ArquillianResource;
15+
import org.jboss.shrinkwrap.api.ShrinkWrap;
16+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
17+
import org.jboss.shrinkwrap.api.spec.WebArchive;
18+
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
22+
/**
23+
*
24+
* @author Arjan Tijms
25+
*
26+
*/
27+
@RunWith(Arquillian.class)
28+
public class EmptyAppWithLibTest {
29+
30+
@ArquillianResource
31+
private URL base;
32+
33+
@Deployment(testable = false)
34+
public static WebArchive deploy() throws URISyntaxException {
35+
JavaArchive[] archiveWithServlet =
36+
Maven.resolver()
37+
.loadPomFromFile("pom.xml")
38+
.resolve("org.javaee7:servlet-lib")
39+
.withoutTransitivity()
40+
.as(JavaArchive.class);
41+
42+
return ShrinkWrap.create(WebArchive.class)
43+
.addAsLibraries(archiveWithServlet);
44+
}
45+
46+
@Test
47+
@RunAsClient
48+
public void invokeBasicServlet() throws MalformedURLException, URISyntaxException {
49+
String response =
50+
ClientBuilder.newClient()
51+
.target(new URL(base, "basic").toURI())
52+
.request()
53+
.get()
54+
.readEntity(String.class);
55+
56+
assertTrue(response.startsWith("get request"));
57+
}
58+
59+
}

‎servlet/servlet-libs/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
<parent>
6+
<groupId>org.javaee7</groupId>
7+
<artifactId>servlet</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<description>
12+
This module contains samples for functioning of web apps and code in libraries
13+
(jars in WEB-INF/lib).
14+
</description>
15+
16+
<artifactId>servlet-libs</artifactId>
17+
<packaging>pom</packaging>
18+
19+
<name>Java EE 7 Sample: Servlet - libs</name>
20+
21+
<modules>
22+
<module>servlet-lib</module>
23+
<module>empty-app-servlet-lib</module>
24+
</modules>
25+
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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</groupId>
6+
<artifactId>servlet-lib</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<name>Java EE 7 Sample: servlet - servlet-lib</name>
10+
<description>
11+
This module delivers a jar with a single Servlet in it. The intend is for this to be included
12+
in the WEB-INF/lib folder of a war, to test that Servlets are found and correctly excecuted
13+
from there. As such this module itself contains no tests.
14+
</description>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<java.min.version>1.7</java.min.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>javax</groupId>
24+
<artifactId>javaee-api</artifactId>
25+
<version>7.0</version>
26+
<scope>provided</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>junit</groupId>
30+
<artifactId>junit</artifactId>
31+
<version>4.13</version>
32+
</dependency>
33+
</dependencies>
34+
35+
<build>
36+
<resources>
37+
<resource>
38+
<directory>src/main/resources</directory>
39+
<filtering>true</filtering>
40+
</resource>
41+
</resources>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-compiler-plugin</artifactId>
46+
<version>3.6.1</version>
47+
<configuration>
48+
<source>${java.min.version}</source>
49+
<target>${java.min.version}</target>
50+
</configuration>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.javaee7.servlet.servlet_libs.basic.servlet;
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.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
11+
/**
12+
* @author Arjan Tijms
13+
*/
14+
@WebServlet("/basic")
15+
public class BasicServlet extends HttpServlet {
16+
17+
private static final long serialVersionUID = 1L;
18+
19+
@Override
20+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
21+
response.getWriter().print("get request");
22+
}
23+
24+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /