Browse Source

Do miscellaneous cleanup of the grizzly-jersey code (#2660)

- Implement MustacheViewProcessor ourselves, allowing us to correctly
  use UTF-8 to render fortunes.  The third-party library we used for
  this previously relied on the default charset.

- Upgrade dependencies that are trivial to upgrade.  I did not attempt
  larger upgrades like Jersey 1->2 or Hibernate 4->5.

- Use Collections.singletonMap instead of HashMap for the JSON endpoint,
  which should be more efficient.

- Use an array instead of a ConcurrentHashMap for the db/queries
  endpoint, which should be more efficient.

- Other minor changes.
Michael Hixson 8 years ago
parent
commit
a544dcf72b

+ 39 - 40
frameworks/Java/grizzly-jersey/pom.xml

@@ -14,28 +14,52 @@
   </prerequisites>
 
   <properties>
-    <grizzly.version>2.3.28</grizzly.version>
-    <jersey.version>1.19</jersey.version>
-    <jersey-mustache.version>1.0.0</jersey-mustache.version>
-    <jackson.version>2.8.5</jackson.version>
-    <mustache.version>0.9.1</mustache.version>
+    <commons-cli.version>1.4</commons-cli.version>
+    <grizzly.version>2.3.30</grizzly.version>
     <hibernate.version>4.3.11.Final</hibernate.version>
-    <mysql-connector.version>5.1.38</mysql-connector.version>
+    <hibernate-jpa-api.version>1.0.0.Final</hibernate-jpa-api.version>
+    <jackson.version>2.8.7</jackson.version>
+    <jersey.version>1.19.3</jersey.version>
+    <jsr311-api.version>1.1.1</jsr311-api.version>
+    <mustache.version>0.9.4</mustache.version>
+    <mysql-connector.version>5.1.41</mysql-connector.version>
   </properties>
 
   <dependencies>
+    <dependency>
+      <groupId>javax.ws.rs</groupId>
+      <artifactId>jsr311-api</artifactId>
+      <version>${jsr311-api.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>com.sun.jersey</groupId>
+      <artifactId>jersey-core</artifactId>
+      <version>${jersey.version}</version>
+    </dependency>
     <dependency>
       <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-server</artifactId>
+      <version>${jersey.version}</version>
     </dependency>
     <dependency>
       <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-grizzly2</artifactId>
+      <version>${jersey.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.eluder.jersey</groupId>
-      <artifactId>jersey-mustache</artifactId>
-      <version>${jersey-mustache.version}</version>
+      <groupId>org.glassfish.grizzly</groupId>
+      <artifactId>grizzly-http</artifactId>
+      <version>${grizzly.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.glassfish.grizzly</groupId>
+      <artifactId>grizzly-http-server</artifactId>
+      <version>${grizzly.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>com.github.spullara.mustache.java</groupId>
+      <artifactId>compiler</artifactId>
+      <version>${mustache.version}</version>
     </dependency>
     <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
@@ -52,6 +76,11 @@
       <artifactId>hibernate-hikaricp</artifactId>
       <version>${hibernate.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.hibernate.javax.persistence</groupId>
+      <artifactId>hibernate-jpa-2.1-api</artifactId>
+      <version>${hibernate-jpa-api.version}</version>
+    </dependency>
     <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
@@ -60,39 +89,9 @@
     <dependency>
       <groupId>commons-cli</groupId>
       <artifactId>commons-cli</artifactId>
-      <version>1.2</version>
+      <version>${commons-cli.version}</version>
     </dependency>
   </dependencies>
-  
-  <dependencyManagement>
-    <dependencies>
-      <dependency>
-        <groupId>com.sun.jersey</groupId>
-        <artifactId>jersey-server</artifactId>
-        <version>${jersey.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>com.sun.jersey</groupId>
-        <artifactId>jersey-grizzly2</artifactId>
-        <version>${jersey.version}</version>
-      </dependency>
-      <dependency>
-      	<groupId>org.glassfish.grizzly</groupId>
-      	<artifactId>grizzly-http</artifactId>
-      	<version>${grizzly.version}</version>
-      </dependency>
-      <dependency>
-      	<groupId>org.glassfish.grizzly</groupId>
-      	<artifactId>grizzly-http-server</artifactId>
-      	<version>${grizzly.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>com.github.spullara.mustache.java</groupId>
-        <artifactId>compiler</artifactId>
-        <version>${mustache.version}</version>
-      </dependency>
-    </dependencies>
-  </dependencyManagement>
 
   <build>
     <finalName>${project.artifactId}</finalName>

+ 12 - 7
frameworks/Java/grizzly-jersey/src/main/java/hello/Common.java

@@ -8,13 +8,18 @@ import java.util.concurrent.TimeUnit;
 /**
  * @author denkab
  */
-public class Common {
+final class Common {
+  private Common() {}
 
-    private static final int cpuCount = Runtime.getRuntime().availableProcessors();
-
-    public static ExecutorService EXECUTOR = new ThreadPoolExecutor(
-        cpuCount * 2, cpuCount * 25, 200, TimeUnit.MILLISECONDS,
-        new LinkedBlockingQueue<Runnable>(cpuCount * 100),
-        new ThreadPoolExecutor.CallerRunsPolicy());
+  private static final int cpuCount =
+      Runtime.getRuntime().availableProcessors();
 
+  static ExecutorService EXECUTOR =
+      new ThreadPoolExecutor(
+          cpuCount * 2,
+          cpuCount * 25,
+          200,
+          TimeUnit.MILLISECONDS,
+          new LinkedBlockingQueue<>(cpuCount * 100),
+          new ThreadPoolExecutor.CallerRunsPolicy());
 }

+ 20 - 28
frameworks/Java/grizzly-jersey/src/main/java/hello/DbResource.java

@@ -1,79 +1,71 @@
 package hello;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-import hello.domain.World;
 
-import java.util.Map;
-import java.util.Random;
+import com.sun.jersey.spi.resource.Singleton;
+import hello.domain.World;
 import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadLocalRandom;
-
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
-
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 
-import com.sun.jersey.spi.resource.Singleton;
-
 @Singleton
 @Path("/db")
 public class DbResource {
 
-  private static final int DB_ROWS = 10000;
-  
   @Context
   private SessionFactory sessionFactory;
-  
+
   @GET
   @Produces(APPLICATION_JSON)
-  public Object db(@QueryParam("queries") String queryParam, @QueryParam("single") boolean isSingle)
+  public Object db(@QueryParam("queries") String queryParam,
+                   @QueryParam("single") boolean isSingle)
       throws ExecutionException, InterruptedException {
 
-    final int queries = getQueries(queryParam);
-    final World[] worlds = new World[queries];
-    final Random random = ThreadLocalRandom.current();
+    int queries = getQueries(queryParam);
 
-    Map<Integer, Future<World>> futureWorlds = new ConcurrentHashMap<>();
+    @SuppressWarnings("unchecked")
+    Future<World>[] futureWorlds = new Future[queries];
     for (int i = 0; i < queries; i++) {
-      futureWorlds.put(i, Common.EXECUTOR.submit(
-        new Callable<World>() {
-          @Override
-          public World call() throws Exception {
+      Callable<World> callable =
+          () -> {
+            int id = ThreadLocalRandom.current().nextInt(DB_ROWS) + 1;
             Session session = sessionFactory.openSession();
             session.setDefaultReadOnly(true);
-
             try {
-              return (World) session.byId(World.class).load(random.nextInt(DB_ROWS) + 1);
+              return (World) session.byId(World.class).load(id);
             } finally {
               session.close();
             }
-          }
-        }
-      ));
+          };
+      futureWorlds[i] = Common.EXECUTOR.submit(callable);
     }
 
+    World[] worlds = new World[queries];
     for (int i = 0; i < queries; i++) {
-      worlds[i] = futureWorlds.get(i).get();
+      worlds[i] = futureWorlds[i].get();
     }
 
     return isSingle ? worlds[0] : worlds;
   }
 
-  private int getQueries(String proto) {
+  private static int getQueries(String proto) {
     int result = 1;
     try {
       if (proto != null && !proto.trim().isEmpty()) {
         result = Integer.parseInt(proto);
       }
-    } catch (NumberFormatException e) {/* by test contract */}
+    } catch (NumberFormatException ignored) {/* by test contract */}
 
     return Math.min(500, Math.max(1, result));
   }
+
+  private static final int DB_ROWS = 10000;
 }

+ 21 - 20
frameworks/Java/grizzly-jersey/src/main/java/hello/FortunesResource.java

@@ -1,47 +1,48 @@
 package hello;
 
 import static javax.ws.rs.core.MediaType.TEXT_HTML;
-import hello.domain.Fortune;
 
+import com.sun.jersey.api.view.Viewable;
+import com.sun.jersey.spi.resource.Singleton;
+import hello.domain.Fortune;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
-
+import org.hibernate.Criteria;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 
-import com.sun.jersey.api.view.Viewable;
-import com.sun.jersey.spi.resource.Singleton;
-
 @Singleton
 @Path("/fortunes")
 public class FortunesResource {
 
   @Context
   private SessionFactory sessionFactory;
-  
+
   @GET
   @Produces(TEXT_HTML + "; charset=utf-8")
   public Viewable fortunes() {
-    final Session session = sessionFactory.openSession();
-    final List fortunes = new ArrayList(session.createCriteria(Fortune.class).list());
-    fortunes.add(new Fortune(0, "Additional fortune added at request time."));
-    Collections.sort(fortunes);
-    
+    Session session = sessionFactory.openSession();
+    Criteria criteria = session.createCriteria(Fortune.class);
+    @SuppressWarnings("unchecked")
+    List<Fortune> fortunes = new ArrayList<>(criteria.list());
     session.close();
-    return new Viewable("/fortunes.mustache", new Scope(fortunes));
+    fortunes.add(new Fortune(0, "Additional fortune added at request time."));
+    fortunes.sort(null);
+    return new ViewableFortunes(fortunes);
   }
-  
-  public static class Scope {
-    public List fortunes;
-    
-    public Scope(final List fortunes) {
-      this.fortunes = fortunes;
+
+  private static final class ViewableFortunes extends Viewable {
+    ViewableFortunes(List<Fortune> fortunes) {
+      super("fortunes.mustache", fortunes);
+    }
+
+    @Override
+    public boolean isTemplateNameAbsolute() {
+      return true;
     }
   }
 }

+ 20 - 24
frameworks/Java/grizzly-jersey/src/main/java/hello/JerseyWebServer.java

@@ -1,28 +1,36 @@
 package hello;
 
+import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
+import com.sun.jersey.api.core.PackagesResourceConfig;
+import com.sun.jersey.api.core.ResourceConfig;
 import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
-
 import javax.ws.rs.core.UriBuilder;
-
 import org.apache.commons.cli.BasicParser;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.Options;
 import org.glassfish.grizzly.http.server.HttpServer;
 
-import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
-import com.sun.jersey.api.core.PackagesResourceConfig;
-import com.sun.jersey.api.core.ResourceConfig;
-
 public class JerseyWebServer {
 
+  public static void main(String[] args) throws Exception {
+    CommandLineParser parser = new BasicParser();
+    CommandLine cmd = parser.parse(options(), args);
+
+    int port = Integer.parseInt(cmd.getOptionValue("port", "8080"));
+    String dbHost = cmd.getOptionValue("dbhost", "localhost");
+    int dbPort = Integer.parseInt(cmd.getOptionValue("dbport", "3306"));
+
+    new JerseyWebServer(port,dbHost, dbPort).run();
+  }
+
   private final int port;
   private final String dbHost;
   private final int dbPort;
 
-  public JerseyWebServer(final int port, final String dbHost, final int dbPort) {
+  public JerseyWebServer(int port, String dbHost, int dbPort) {
     this.port = port;
     this.dbHost = dbHost;
     this.dbPort = dbPort;
@@ -30,14 +38,13 @@ public class JerseyWebServer {
 
   public void run() throws Exception {
     URI baseUri = getBaseUrl(port);
-    ResourceConfig rc = new PackagesResourceConfig("hello", "org.eluder.jersey.mustache");
+    ResourceConfig rc = new PackagesResourceConfig("hello");
     rc.setPropertiesAndFeatures(properties());
-    rc.getContainerResponseFilters().add(new ServerResponseFilter());
+    rc.getContainerResponseFilters().add(new ServerHeaderFilter());
     HttpServer server = GrizzlyServerFactory.createHttpServer(baseUri, rc);
 
     try {
         server.start();
-
         System.err.print("Server started.\n");
         synchronized (JerseyWebServer.class) {
             JerseyWebServer.class.wait();
@@ -48,27 +55,16 @@ public class JerseyWebServer {
   }
 
   private Map<String, Object> properties() {
-    Map<String, Object> properties = new HashMap<String, Object>();
+    Map<String, Object> properties = new HashMap<>();
     properties.put("dbhost", dbHost);
     properties.put("dbport", dbPort);
     return properties;
   }
-  
-  private static URI getBaseUrl(final int port) {
+
+  private static URI getBaseUrl(int port) {
     return UriBuilder.fromUri("http://0.0.0.0/").port(port).build();
   }
 
-  public static void main(final String[] args) throws Exception {
-    CommandLineParser parser = new BasicParser();
-    CommandLine cmd = parser.parse(options(), args);
-    
-    int port = Integer.parseInt(cmd.getOptionValue("port", "8080"));
-    String dbHost = cmd.getOptionValue("dbhost", "localhost");
-    int dbPort = Integer.parseInt(cmd.getOptionValue("dbport", "3306"));
-    
-    new JerseyWebServer(port,dbHost, dbPort).run();
-  }
-  
   private static Options options() {
     Options options = new Options();
     options.addOption("port", true, "server port");

+ 20 - 22
frameworks/Java/grizzly-jersey/src/main/java/hello/JsonMessageBodyWriter.java

@@ -2,11 +2,12 @@ package hello;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sun.jersey.spi.resource.Singleton;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
-
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
@@ -14,44 +15,41 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.sun.jersey.spi.resource.Singleton;
-
-@Provider
 @Singleton
+@Provider
 @Produces(APPLICATION_JSON)
 public class JsonMessageBodyWriter implements MessageBodyWriter<Object> {
-  
+
   private final ObjectMapper mapper = new ObjectMapper();
 
   @Override
   public boolean isWriteable(
-      final Class<?> type,
-      final Type genericType,
-      final Annotation[] annotations,
-      final MediaType mediaType) {
+      Class<?> type,
+      Type genericType,
+      Annotation[] annotations,
+      MediaType mediaType) {
     return "json".equals(mediaType.getSubtype());
   }
 
   @Override
   public long getSize(
-      final Object t,
-      final Class<?> type,
-      final Type genericType,
-      final Annotation[] annotations,
-      final MediaType mediaType) {
+      Object t,
+      Class<?> type,
+      Type genericType,
+      Annotation[] annotations,
+      MediaType mediaType) {
     return -1; // We can't predict the output size at this point
   }
 
   @Override
   public void writeTo(
-      final Object t,
-      final Class<?> type,
-      final Type genericType,
-      final Annotation[] annotations,
-      final MediaType mediaType,
-      final MultivaluedMap<String, Object> httpHeaders,
-      final OutputStream entityStream)
+      Object t,
+      Class<?> type,
+      Type genericType,
+      Annotation[] annotations,
+      MediaType mediaType,
+      MultivaluedMap<String, Object> httpHeaders,
+      OutputStream entityStream)
       throws IOException, WebApplicationException {
     mapper.writeValue(entityStream, t);
   }

+ 4 - 9
frameworks/Java/grizzly-jersey/src/main/java/hello/JsonResource.java

@@ -2,24 +2,19 @@ package hello;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 
-import java.util.HashMap;
-import java.util.Map;
-
+import com.sun.jersey.spi.resource.Singleton;
+import java.util.Collections;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
-import com.sun.jersey.spi.resource.Singleton;
-
 @Singleton
 @Path("/json")
 public class JsonResource {
-  
+
   @GET
   @Produces(APPLICATION_JSON)
   public Object json() {
-    Map<String, String> data = new HashMap<String, String>(1);
-    data.put("message", "Hello, World!");
-    return data;
+    return Collections.singletonMap("message", "Hello, World!");
   }
 }

+ 42 - 0
frameworks/Java/grizzly-jersey/src/main/java/hello/MustacheViewProcessor.java

@@ -0,0 +1,42 @@
+package hello;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import com.github.mustachejava.DefaultMustacheFactory;
+import com.github.mustachejava.Mustache;
+import com.github.mustachejava.MustacheFactory;
+import com.github.mustachejava.resolver.ClasspathResolver;
+import com.sun.jersey.api.view.Viewable;
+import com.sun.jersey.spi.resource.Singleton;
+import com.sun.jersey.spi.template.ViewProcessor;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import javax.ws.rs.ext.Provider;
+
+@Singleton
+@Provider
+public class MustacheViewProcessor implements ViewProcessor<Mustache> {
+
+  private final MustacheFactory factory;
+
+  public MustacheViewProcessor() {
+    factory = new DefaultMustacheFactory(new ClasspathResolver());
+  }
+
+  @Override
+  public Mustache resolve(String name) {
+    return factory.compile(name);
+  }
+
+  @Override
+  public void writeTo(Mustache t,
+                      Viewable viewable,
+                      OutputStream out) throws IOException {
+    try (BufferedWriter writer =
+             new BufferedWriter(new OutputStreamWriter(out, UTF_8))) {
+      t.execute(writer, viewable.getModel());
+    }
+  }
+}

+ 2 - 4
frameworks/Java/grizzly-jersey/src/main/java/hello/PlaintextResource.java

@@ -1,11 +1,10 @@
 package hello;
 
+import com.sun.jersey.spi.resource.Singleton;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
-import com.sun.jersey.spi.resource.Singleton;
-
 @Singleton
 @Path("/plaintext")
 public class PlaintextResource {
@@ -13,7 +12,6 @@ public class PlaintextResource {
   @GET
   @Produces("text/plain")
   public Object plaintext() {
-    String data = "Hello, World!";
-    return data;
+    return "Hello, World!";
   }
 }

+ 15 - 0
frameworks/Java/grizzly-jersey/src/main/java/hello/ServerHeaderFilter.java

@@ -0,0 +1,15 @@
+package hello;
+
+import com.sun.jersey.spi.container.ContainerRequest;
+import com.sun.jersey.spi.container.ContainerResponse;
+import com.sun.jersey.spi.container.ContainerResponseFilter;
+
+public class ServerHeaderFilter implements ContainerResponseFilter {
+
+  @Override
+  public ContainerResponse filter(ContainerRequest request,
+                                  ContainerResponse response) {
+    response.getHttpHeaders().add("Server", "Grizzly");
+    return response;
+  }
+}

+ 0 - 18
frameworks/Java/grizzly-jersey/src/main/java/hello/ServerResponseFilter.java

@@ -1,18 +0,0 @@
-package hello;
-
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerResponse;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-
-public class ServerResponseFilter implements ContainerResponseFilter {
-  
-  private static final String SERVER_HEADER = "Server";
-  private static final String SERVER_VALUE  = "Grizzly";
-  
-  @Override
-  public ContainerResponse filter(final ContainerRequest request, final ContainerResponse response) {
-    response.getHttpHeaders().add(SERVER_HEADER, SERVER_VALUE);
-    return response;
-  }
-
-}

+ 16 - 15
frameworks/Java/grizzly-jersey/src/main/java/hello/SessionFactoryProvider.java

@@ -1,35 +1,36 @@
 package hello;
 
+import com.sun.jersey.api.core.ResourceConfig;
+import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider;
+import com.sun.jersey.spi.resource.Singleton;
 import hello.domain.Fortune;
 import hello.domain.World;
-
 import javax.ws.rs.core.Context;
 import javax.ws.rs.ext.Provider;
-
 import org.hibernate.SessionFactory;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
 import org.hibernate.cfg.Configuration;
-import org.hibernate.service.ServiceRegistryBuilder;
-
-import com.sun.jersey.api.core.ResourceConfig;
-import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider;
-import com.sun.jersey.spi.resource.Singleton;
 
-@Provider
 @Singleton
-public class SessionFactoryProvider extends SingletonTypeInjectableProvider<Context, SessionFactory> {
+@Provider
+public class SessionFactoryProvider
+    extends SingletonTypeInjectableProvider<Context, SessionFactory> {
 
-  public SessionFactoryProvider(@Context final ResourceConfig rc) {
+  public SessionFactoryProvider(@Context ResourceConfig rc) {
     super(SessionFactory.class, createSessionFactory(rc));
   }
-  
-  private static SessionFactory createSessionFactory(final ResourceConfig rc) {
+
+  private static SessionFactory createSessionFactory(ResourceConfig rc) {
     Configuration configuration = new Configuration().configure();
     String url = configuration.getProperty("hibernate.hikari.dataSource.url");
-    url = url.replace("//localhost:3306/", "//" + rc.getProperty("dbhost") + ":" + rc.getProperty("dbport") + "/");
+    url = url.replace(
+        "//localhost:3306/",
+        "//" + rc.getProperty("dbhost") + ":" + rc.getProperty("dbport") + "/");
     configuration.setProperty("hibernate.hikari.dataSource.url", url);
     configuration.addAnnotatedClass(World.class);
     configuration.addAnnotatedClass(Fortune.class);
-    ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder().applySettings(configuration.getProperties());
-    return configuration.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
+    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
+    builder.applySettings(configuration.getProperties());
+    return configuration.buildSessionFactory(builder.build());
   }
 }

+ 5 - 6
frameworks/Java/grizzly-jersey/src/main/java/hello/domain/Fortune.java

@@ -12,17 +12,16 @@ public class Fortune implements Comparable<Fortune> {
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   public int id;
   public String message;
-  
+
   public Fortune() { }
-  
-  public Fortune(final int id, final String message) {
+
+  public Fortune(int id, String message) {
     this.id = id;
     this.message = message;
   }
-  
+
   @Override
-  public int compareTo(final Fortune other)
-  {
+  public int compareTo(Fortune other) {
     return message.compareTo(other.message);
   }
 }

+ 6 - 6
frameworks/Java/grizzly-jersey/src/main/java/hello/domain/World.java

@@ -7,10 +7,10 @@ import javax.persistence.Id;
 
 @Entity
 public class World {
-    
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    public int id;
-    public int randomNumber;
-    
+
+  @Id
+  @GeneratedValue(strategy = GenerationType.IDENTITY)
+  public int id;
+  public int randomNumber;
+
 }

+ 2 - 2
frameworks/Java/grizzly-jersey/src/main/resources/fortunes.mustache

@@ -9,12 +9,12 @@
 <th>id</th>
 <th>message</th>
 </tr>
-{{#fortunes}}
+{{#.}}
 <tr>
 <td>{{id}}</td>
 <td>{{message}}</td>
 </tr>
-{{/fortunes}}
+{{/.}}
 </table>
 </body>
 </html>