title: Grizzly http server fails some request
body: <p>I created a grizzly web server, to run my jersey application out of tomcat, to speed up tests.</p>
  
  <p>I'm a grizzly beginner, but looking through the net I put some code lines together, to make a grizzly web server up and running in less than a working day :)</p>
  
  <p>Unfortunately my class has some troubles on concurrent request, often one or more fails in an inexplicable <strong>NullPointerException</strong>. </p>
  
  <p>Troubles are typically when I refresh my web page, where grizzly must return about 25 non cached files. This is registered exception:</p>
  
  <pre><code>9-set-2010 10.45.21 com.sun.grizzly.http.servlet.ServletAdapter doService
  GRAVE: service exception:
  java.lang.NullPointerException
      at com.sun.grizzly.http.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:178)
      at com.sun.grizzly.http.servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:139)
      at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:376)
      at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:324)
  .....
  </code></pre>
  
  <p>Static files are served from a class of mine, but logs tells me everithing is ok and when I use application under tomcat, everything is ok. 
  I really don't know how to solve this problem..</p>
  
  <p>This is the code I created/copied from internet, to startup project:</p>
  
  <pre><code>public class LaunchApp {
  
  /** Find in internet, used to use argument port as default, only if there is no JERSEY_HTTP_PORT env port enabled*/
  private static int getPort(int defaultPort) {
      String port = System.getenv("JERSEY_HTTP_PORT");
      if (null != port) {
          try {
              return Integer.parseInt(port);
          } catch (NumberFormatException e) {
          }
      }
      return defaultPort;
  }
  
  private static URI getBaseURI() {
      return UriBuilder.fromUri("http://localhost/").port(getPort(8080)).build();
  }
  
  public static final URI BASE_URI = getBaseURI();
  
  protected static GrizzlyWebServer startServer() throws IOException {
      final String rootFolder = "/Users/davide/dev/my-project/src/main/webapp";
      GrizzlyWebServer ws = new GrizzlyWebServer("/Users/davide/dev/my-project/src/main/webapp");
      try{
          ServletAdapter adapter = new ServletAdapter();
          adapter.addContextParameter( "contextConfigLocation","classpath:applicationContext.xml" );
          adapter.addServletListener("org.springframework.web.context.ContextLoaderListener");
          adapter.addServletListener("org.springframework.web.context.request.RequestContextListener");
          adapter.addInitParameter( "com.sun.jersey.config.property.packages", "it.treis.zero.web.rest");
          adapter.addInitParameter( "com.sun.jersey.spi.container.ContainerRequestFilters","com.sun.jersey.api.container.filter.LoggingFilter");
          adapter.addInitParameter( "com.sun.jersey.spi.container.ContainerResponseFilters","com.sun.jersey.api.container.filter.LoggingFilter");
          adapter.setProperty( "load-on-startup", 1 );
          adapter.setServletInstance( new SpringServlet() );
          adapter.setRootFolder(rootFolder);
  
          // Add Open Session In View Hibernate Filter.
          adapter.addFilter(new org.springframework.orm.hibernate3.support.OpenSessionInViewFilter(), "openSessionInViewFilter", null);
  
          ws.addGrizzlyAdapter(adapter);
  
          ws.start();
      } catch(IOException ex){
          ex.printStackTrace();
      }
      return ws;
  }
  
  public static void main(String[] args) throws IOException {
      System.out.println("Starting Jersey");
      GrizzlyWebServer ws = startServer();
      System.out.println("Jersey rightly started, press any key to shutdown");
      System.in.read();
      ws.stop();
      System.exit(0);
  }
  }
  </code></pre>
  
  <p>Any suggestions are appreciated.</p>
  
  <p>Ciao, Davide.</p>