Commits

Micha Kops committed 60a3f13

Initial import.

  • Participants

Comments (0)

Files changed (4)

+.project
+.classpath
+.settings
+target
+<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>
+	<groupId>com.hascode.tutorial</groupId>
+	<artifactId>port-allocator-example</artifactId>
+	<version>1.0.0</version>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.eclipse.jetty</groupId>
+			<artifactId>jetty-server</artifactId>
+			<version>9.0.0.RC2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.jetty</groupId>
+			<artifactId>jetty-servlet</artifactId>
+			<version>9.0.0.RC2</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.sonatype.plugins</groupId>
+				<artifactId>port-allocator-maven-plugin</artifactId>
+				<version>1.2</version>
+				<executions>
+					<execution>
+						<phase>validate</phase>
+						<goals>
+							<goal>allocate-ports</goal>
+						</goals>
+						<configuration>
+							<ports>
+								<port>
+									<name>tomcat-port</name>
+								</port>
+							</ports>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

src/main/java/com/hascode/tutorial/DemoServlet.java

+package com.hascode.tutorial;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class DemoServlet extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+
+	@Override
+	protected void doGet(final HttpServletRequest req,
+			final HttpServletResponse res) throws ServletException, IOException {
+		res.getWriter()
+				.append("I'm a happy web server, running on port "
+						+ req.getLocalPort());
+	}
+
+}

src/main/java/com/hascode/tutorial/HttpRunner.java

+package com.hascode.tutorial;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+public class HttpRunner {
+	public static void main(final String[] args) throws Exception {
+		int port = Integer.parseInt(args[0]);
+		System.out.println("Starting embedded Jetty with port: " + port);
+		Server server = new Server();
+		ServerConnector c = new ServerConnector(server);
+		c.setIdleTimeout(1000);
+		c.setAcceptQueueSize(10);
+		c.setPort(port);
+		c.setHost("localhost");
+		ServletContextHandler handler = new ServletContextHandler(server,
+				"/app", true, false);
+		ServletHolder servletHolder = new ServletHolder(DemoServlet.class);
+		handler.addServlet(servletHolder, "/test");
+		server.addConnector(c);
+		server.start();
+	}
+}