Browse Source

Implementation of Test #6 in Servlet and Gemini; updated Gemini version.

Brian Hauer 12 years ago
parent
commit
7a4029fea2

+ 1 - 1
gemini/.classpath

@@ -8,8 +8,8 @@
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
 	<classpathentry kind="var" path="Resin4Jee"/>
 	<classpathentry kind="var" path="Resin4Jee"/>
 	<classpathentry kind="lib" path="Docroot/WEB-INF/lib/mysql-connector-java-5.1.23-bin.jar"/>
 	<classpathentry kind="lib" path="Docroot/WEB-INF/lib/mysql-connector-java-5.1.23-bin.jar"/>
-	<classpathentry kind="lib" path="Docroot/WEB-INF/lib/gemini-1.3.6.jar"/>
 	<classpathentry kind="lib" path="Docroot/WEB-INF/lib/guava-14.0.1.jar"/>
 	<classpathentry kind="lib" path="Docroot/WEB-INF/lib/guava-14.0.1.jar"/>
 	<classpathentry kind="lib" path="Docroot/WEB-INF/lib/trove4j-3.0.3.jar"/>
 	<classpathentry kind="lib" path="Docroot/WEB-INF/lib/trove4j-3.0.3.jar"/>
+	<classpathentry kind="lib" path="Docroot/WEB-INF/lib/gemini-1.3.7.jar"/>
 	<classpathentry kind="output" path="Docroot/WEB-INF/classes"/>
 	<classpathentry kind="output" path="Docroot/WEB-INF/classes"/>
 </classpath>
 </classpath>

BIN
gemini/Docroot/WEB-INF/lib/gemini-1.3.6.jar → gemini/Docroot/WEB-INF/lib/gemini-1.3.7.jar


+ 3 - 2
gemini/Docroot/WEB-INF/mustache/fortunes.mustache

@@ -1,16 +1,17 @@
 {{<layout}}
 {{<layout}}
+{{$title}}Fortunes{{/title}}
 {{$body}}
 {{$body}}
 <table>
 <table>
 <tr>
 <tr>
 <th>id</th>
 <th>id</th>
 <th>message</th>
 <th>message</th>
 </tr>
 </tr>
-{{#.}}
+{{#req}}
 <tr>
 <tr>
 <td>{{id}}</td>
 <td>{{id}}</td>
 <td>{{message}}</td>
 <td>{{message}}</td>
 </tr>
 </tr>
-{{/.}}
+{{/req}}
 </table>
 </table>
 {{/body}}
 {{/body}}
 {{/layout}}
 {{/layout}}

+ 1 - 1
gemini/Docroot/WEB-INF/mustache/layout.mustache

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html>
 <html>
 <head>
 <head>
-<title>Fortunes</title>
+<title>{{$title}}{{/title}}</title>
 </head>
 </head>
 <body>
 <body>
 {{$body}}{{/body}}
 {{$body}}{{/body}}

+ 29 - 9
gemini/Source/hello/home/handler/HelloHandler.java

@@ -11,11 +11,10 @@ import com.techempower.gemini.path.*;
 import com.techempower.gemini.path.annotation.*;
 import com.techempower.gemini.path.annotation.*;
 
 
 /**
 /**
- * Responds to the framework benchmarking requests for "hello, world" and
- * simple database queries.
+ * Handles the various framework benchmark request types.
  */
  */
 public class HelloHandler
 public class HelloHandler
-    extends  BasicPathHandler<Context>
+    extends  MethodPathHandler<Context>
 {
 {
 
 
   private static final int DB_ROWS = 10000;
   private static final int DB_ROWS = 10000;
@@ -34,6 +33,7 @@ public class HelloHandler
   /**
   /**
    * Return "hello world" as a JSON-encoded message.
    * Return "hello world" as a JSON-encoded message.
    */
    */
+  @PathSegment("json")
   @PathDefault
   @PathDefault
   public boolean helloworld()
   public boolean helloworld()
   {
   {
@@ -41,14 +41,24 @@ public class HelloHandler
   }
   }
 
 
   /**
   /**
-   * Return a list of World objects as JSON, selected randomly from the World
-   * table.  For consistency, we have assumed the table has 10,000 rows.
+   * Return a single World objects as JSON, selected randomly from the World
+   * table.  Assume the table has 10,000 rows.
    */
    */
   @PathSegment
   @PathSegment
   public boolean db()
   public boolean db()
+  {
+    return json(store.get(World.class, ThreadLocalRandom.current().nextInt(DB_ROWS)));
+  }
+
+  /**
+   * Return a list of World objects as JSON, selected randomly from the World
+   * table.  Assume the table has 10,000 rows.
+   */
+  @PathSegment("query")
+  public boolean multipleQueries()
   {
   {
     final Random random = ThreadLocalRandom.current();
     final Random random = ThreadLocalRandom.current();
-    final int queries = context().getInt("queries", 1, 1, 500);
+    final int queries = query().getInt("queries", 1, 1, 500);
     final World[] worlds = new World[queries];
     final World[] worlds = new World[queries];
 
 
     for (int i = 0; i < queries; i++)
     for (int i = 0; i < queries; i++)
@@ -75,14 +85,15 @@ public class HelloHandler
 
 
   /**
   /**
    * Return a list of World objects as JSON, selected randomly from the World
    * Return a list of World objects as JSON, selected randomly from the World
-   * table.  For each row that is retrieved, that row will have it's randomNumber
-   * field updated and persisted. For consistency, we have assumed the table has 10,000 rows.
+   * table.  For each row that is retrieved, that row will have its 
+   * randomNumber field updated and then the row will be persisted.  We
+   * assume the table has 10,000 rows.
    */
    */
   @PathSegment
   @PathSegment
   public boolean update()
   public boolean update()
   {
   {
     final Random random = ThreadLocalRandom.current();
     final Random random = ThreadLocalRandom.current();
-    final int queries = context().getInt("queries", 1, 1, 500);
+    final int queries = query().getInt("queries", 1, 1, 500);
     final World[] worlds = new World[queries];
     final World[] worlds = new World[queries];
 
 
     for (int i = 0; i < queries; i++)
     for (int i = 0; i < queries; i++)
@@ -95,5 +106,14 @@ public class HelloHandler
     
     
     return json(worlds);
     return json(worlds);
   }
   }
+  
+  /**
+   * Responds with a plaintext "Hello, World!" 
+   */
+  @PathSegment
+  public boolean plaintext()
+  {
+    return text("Hello, World!");
+  }
 
 
 }
 }

+ 1 - 0
servlet/src/main/java/hello/Common.java

@@ -13,6 +13,7 @@ public class Common
   // Constants for setting the content type.
   // Constants for setting the content type.
   protected static final String HEADER_CONTENT_TYPE    = "Content-Type";
   protected static final String HEADER_CONTENT_TYPE    = "Content-Type";
   protected static final String CONTENT_TYPE_JSON      = "application/json";
   protected static final String CONTENT_TYPE_JSON      = "application/json";
+  protected static final String CONTENT_TYPE_TEXT      = "text/plain";
   protected static final String CONTENT_TYPE_HTML      = "text/html";
   protected static final String CONTENT_TYPE_HTML      = "text/html";
 
 
   // Jackson encoder, reused for each response.
   // Jackson encoder, reused for each response.

+ 33 - 0
servlet/src/main/java/hello/PlaintextServlet.java

@@ -0,0 +1,33 @@
+package hello;
+
+import java.io.*;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+/**
+ * Plaintext rendering Test
+ */
+@SuppressWarnings("serial")
+public class PlaintextServlet extends HttpServlet
+{
+
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse res)
+      throws ServletException, IOException
+  {
+    // Set content type to text/plain.
+    res.setHeader(Common.HEADER_CONTENT_TYPE, Common.CONTENT_TYPE_TEXT);
+
+    // Write plaintext "Hello, World!" to the response.
+    try
+    {
+      res.getWriter().write("Hello, World!");
+    }
+    catch (IOException ioe) 
+    {
+      // do nothing
+    }
+  }
+  
+}

+ 6 - 0
servlet/src/main/webapp/WEB-INF/web.xml

@@ -5,6 +5,12 @@
     <load-on-startup/>
     <load-on-startup/>
   </servlet>
   </servlet>
   <servlet-mapping url-regexp='^/json$' servlet-name='json'/>
   <servlet-mapping url-regexp='^/json$' servlet-name='json'/>
+  <servlet>
+    <servlet-name>plaintext</servlet-name>
+    <servlet-class>hello.PlaintextServlet</servlet-class>
+    <load-on-startup/>
+  </servlet>
+  <servlet-mapping url-regexp='^/plaintext$' servlet-name='plaintext'/>
   <servlet>
   <servlet>
     <servlet-name>db</servlet-name>
     <servlet-name>db</servlet-name>
     <servlet-class>hello.DbPoolServlet</servlet-class>
     <servlet-class>hello.DbPoolServlet</servlet-class>