Skip to content

Commit 7df3327

Browse files
author
Reza Naghibi
committed
servlet
0 parents  commit 7df3327

File tree

11 files changed

+232
-0
lines changed

11 files changed

+232
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Java servlet example used for benchmarking

deploy.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
if [ "$1" != "local" -a "$1" != "prod" ]
4+
then
5+
echo "Please pass in local or prod"
6+
exit 1
7+
fi
8+
9+
mvn tomcat7:deploy -P $1

pom.xml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<artifactId>servlet</artifactId>
7+
<groupId>org.rezsoft</groupId>
8+
<name>servlet</name>
9+
<version>1.0</version>
10+
<packaging>war</packaging>
11+
12+
<properties>
13+
<java.version>1.7</java.version>
14+
<build.date>${maven.build.timestamp}</build.date>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<maven.build.timestamp.format>yyyyMMdd_HHmm</maven.build.timestamp.format>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>javax.servlet</groupId>
22+
<artifactId>servlet-api</artifactId>
23+
<version>2.5</version>
24+
<scope>provided</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>javax.servlet.jsp</groupId>
28+
<artifactId>jsp-api</artifactId>
29+
<version>2.1</version>
30+
<scope>provided</scope>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<finalName>servlet</finalName>
36+
<filters>
37+
<filter>src/main/config/${env}.properties</filter>
38+
</filters>
39+
<resources>
40+
<resource>
41+
<directory>src/main/resources</directory>
42+
<filtering>true</filtering>
43+
</resource>
44+
</resources>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-war-plugin</artifactId>
49+
<version>2.3</version>
50+
<configuration>
51+
<webResources>
52+
<resource>
53+
<directory>${basedir}/src/main/webapp</directory>
54+
<filtering>true</filtering>
55+
<includes>
56+
<include>**/*.xml</include>
57+
<include>**/*.html</include>
58+
<include>version.jsp</include>
59+
<include>index.jsp</include>
60+
</includes>
61+
</resource>
62+
</webResources>
63+
<packagingExcludes>${war.exclude}</packagingExcludes>
64+
</configuration>
65+
</plugin>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-compiler-plugin</artifactId>
69+
<version>3.0</version>
70+
<configuration>
71+
<source>1.7</source>
72+
<target>1.7</target>
73+
<debug>true</debug>
74+
</configuration>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.apache.tomcat.maven</groupId>
78+
<artifactId>tomcat7-maven-plugin</artifactId>
79+
<version>2.0</version>
80+
<configuration>
81+
<server>${tomcat.server}</server>
82+
<url>${tomcat.url}/manager/text</url>
83+
<path>${tomcat.path}</path>
84+
<update>true</update>
85+
</configuration>
86+
</plugin>
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-surefire-plugin</artifactId>
90+
<version>2.16</version>
91+
<configuration>
92+
<skipTests>${skipTests}</skipTests>
93+
</configuration>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
98+
<profiles>
99+
<profile>
100+
<id>local</id>
101+
<activation>
102+
<activeByDefault>true</activeByDefault>
103+
</activation>
104+
<properties>
105+
<!-- username and password go into your maven settings.xml for each server -->
106+
<env>local</env>
107+
<tomcat.server>local</tomcat.server>
108+
<tomcat.url>http://localhost:8888</tomcat.url>
109+
<tomcat.path>/servlet</tomcat.path>
110+
<skipTests>true</skipTests>
111+
<war.exclude></war.exclude>
112+
</properties>
113+
</profile>
114+
<profile>
115+
<id>prod</id>
116+
<properties>
117+
<env>prod</env>
118+
<tomcat.server>rezsoft</tomcat.server>
119+
<tomcat.url>http://www.rezsoft.org:8080</tomcat.url>
120+
<tomcat.path>/servlet</tomcat.path>
121+
<skipTests>true</skipTests>
122+
<war.exclude>index.jsp</war.exclude>
123+
</properties>
124+
</profile>
125+
</profiles>
126+
</project>

src/main/config/local.properties

Whitespace-only changes.

src/main/config/prod.properties

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.rezsoft.servlet;
2+
3+
import java.io.IOException;
4+
import java.io.Writer;
5+
import javax.servlet.ServletException;
6+
import javax.servlet.http.HttpServlet;
7+
import javax.servlet.http.HttpServletRequest;
8+
import javax.servlet.http.HttpServletResponse;
9+
10+
/**
11+
*
12+
* @author Reza Naghibi
13+
*/
14+
public class Serve extends HttpServlet {
15+
16+
@Override
17+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
18+
{
19+
String param=request.getParameter("param");
20+
21+
StringBuilder sb=new StringBuilder();
22+
sb.append("{\"reza\":true,\"hello\":\"world!\",\"param\":\"").append(param).append("\"}");
23+
24+
response.setHeader("Content-Type", "application/json");
25+
26+
Writer writer=response.getWriter();
27+
writer.write(sb.toString());
28+
writer.flush();
29+
}
30+
31+
}

src/main/webapp/META-INF/context.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Context path="/servlet"/>

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

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+
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
5+
6+
<display-name>servlet</display-name>
7+
<description>servlet</description>
8+
9+
<welcome-file-list>
10+
<welcome-file>index.jsp</welcome-file>
11+
</welcome-file-list>
12+
13+
<servlet>
14+
<servlet-name>serve</servlet-name>
15+
<servlet-class>org.rezsoft.servlet.Serve</servlet-class>
16+
</servlet>
17+
18+
<servlet-mapping>
19+
<servlet-name>serve</servlet-name>
20+
<url-pattern>/test/param</url-pattern>
21+
</servlet-mapping>
22+
23+
</web-app>

src/main/webapp/index.jsp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<%@ page session="false" %>
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6+
<title>servlet</title>
7+
</head>
8+
<body>
9+
<pre>
10+
<h1>servlet</h1>
11+
<h2>Links</h2>
12+
<a href="version.jsp">version</a>
13+
<a href="#general">Test section</a>
14+
15+
<a id="general"><h2>Test</h2></a>
16+
<b>param</b>
17+
GET /test/param
18+
test service with param
19+
-params: param
20+
<form action="test/param" method="GET">
21+
param <input type="text" name="param">
22+
<input type="submit" value="Submit">
23+
</form>
24+
25+
</pre>
26+
</body>
27+
</html>

0 commit comments

Comments
 (0)