Commits

Quinton Anderson committed 8378f55

INitial commit, not tested

Comments (0)

Files changed (3)

+<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>storm.cookbook</groupId>
+	<artifactId>click-webserver</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<packaging>jar</packaging>
+
+	<name>click-webserver</name>
+	<url>https://bitbucket.org/qanderson/click-webserver</url>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+    		<groupId>javax</groupId>
+    		<artifactId>javaee-api</artifactId>
+    		<version>6.0</version>
+    		<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.mortbay.jetty</groupId>
+			<artifactId>jetty</artifactId>
+			<version>6.1.26</version>
+		</dependency>
+		<dependency>
+			<groupId>org.mortbay.jetty</groupId>
+			<artifactId>jetty-util</artifactId>
+			<version>6.1.26</version>
+		</dependency>
+		<dependency>
+			<groupId>redis.clients</groupId>
+			<artifactId>jedis</artifactId>
+			<version>2.1.0</version>
+		</dependency>
+        <dependency>
+            <groupId>com.googlecode.json-simple</groupId>
+            <artifactId>json-simple</artifactId>
+            <version>1.1</version>
+        </dependency>
+    </dependencies>
+
+	<build>
+		<plugins>
+		    <!-- 
+		    bind the maven-assembly-plugin to the package phase
+		    this will create a jar file without the storm dependencies
+		    suitable for deployment to a cluster.
+		     -->
+			<plugin>
+				<artifactId>maven-assembly-plugin</artifactId>
+				<configuration>
+					<descriptorRefs>
+						<descriptorRef>jar-with-dependencies</descriptorRef>
+					</descriptorRefs>
+					<archive>
+						<manifest>
+							<mainClass>storm.cookbook.web.BasicServer</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+				<executions>
+					<execution>
+						<id>make-assembly</id>
+						<phase>package</phase>
+						<goals>
+							<goal>single</goal>
+						</goals>
+					</execution>
+				</executions>
+
+			</plugin>
+		</plugins>
+	</build>
+</project>

src/main/java/storm/cookbook/web/BasicServer.java

+package storm.cookbook.web;
+
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.AbstractHandler;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class BasicServer {
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) throws Exception {
+		Server server = new Server(8080);
+        Context root = new Context(server,"/", Context.SESSIONS);
+        root.addServlet(new ServletHolder(new ClickServlet()),"/*");
+		server.start();
+
+	}
+
+}

src/main/java/storm/cookbook/web/ClickServlet.java

+package storm.cookbook.web;
+
+import org.json.simple.JSONObject;
+import redis.clients.jedis.Jedis;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: admin
+ * Date: 2012/12/07
+ * Time: 8:42 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ClickServlet extends HttpServlet
+{
+    Jedis jedis = new Jedis("localhost");
+    @Override
+    protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
+    {
+        JSONObject content = new JSONObject();
+        content.put("ip" ,httpServletRequest.getParameter("ip"));
+        content.put("url" ,httpServletRequest.getParameter("url"));
+        content.put("clientKey" ,httpServletRequest.getParameter("clientKey"));
+
+        jedis.rpush("count", content.toJSONString());
+
+        httpServletResponse.setContentType("text/plain");
+        PrintWriter out = httpServletResponse.getWriter();
+        out.println("Counted!");
+        out.close();
+    }
+}