Jetty
  1. Jetty
  2. JETTY-203

Regression: Servlet Not Initialized

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 6.0.2
    • Fix Version/s: 6.1.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      Fedora Core 6, Sun JVM 1.5.0_09
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      Upgrading from Jetty 6.0.1 to 6.0.2 gives me the following exception:
      2006-12-21 08:34:43.995::WARN: EXCEPTION
      javax.servlet.UnavailableException: Servlet Not Initialized
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:434)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:629)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
      at org.mortbay.jetty.Server.handle(Server.java:303)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:452)
      at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:721)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:509)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:349)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:320)
      at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)

      The unit test that triggers this:

      public void testJettyBang() throws Exception {
      // setup test servlet container
      Server server = new Server();
      Connector connector = new SelectChannelConnector();
      connector.setPort(0);
      server.setConnectors(new Connector[]

      { connector }

      );

      ContextHandler context = new ContextHandler();
      context.setContextPath("/");
      server.setHandler(context);

      ServletHandler handler = new ServletHandler();
      context.setHandler(handler);

      ServletHolder servletHolder = new ServletHolder();
      servletHolder.setClassName(TestServlet.class.getName());
      servletHolder.setName("TestServlet");
      handler.addServlet(servletHolder);

      ServletMapping servletMapping = new ServletMapping();
      servletMapping.setServletName("TestServlet");
      servletMapping.setPathSpecs(new String[]

      { "/*" }

      );
      handler.addServletMapping(servletMapping);

      server.start();

      int port = connector.getLocalPort();
      LOG.debug("port: " + port);

      String location = "http://localhost:" + port + "/";

      HttpClient httpClient = new HttpClient();
      GetMethod getMethod = new GetMethod(location);
      int result = httpClient.executeMethod(getMethod);
      LOG.debug("result: " + result);

      server.stop();

      assertEquals(200, result);
      String resultBody = getMethod.getResponseBodyAsString();
      assertEquals("Hello World", resultBody);
      }

      public static class TestServlet extends HttpServlet {

      private static final long serialVersionUID = 1L;

      @Override
      protected void doGet(HttpServletRequest request,
      HttpServletResponse response) throws ServletException,
      IOException

      { PrintWriter writer = response.getWriter(); writer.print("Hello World"); }

      }

        Activity

        Hide
        Greg Wilkins added a comment -

        Fixed in 6.1.0

        For 6.0.2 you can work around the issue if you code like:

        Context context = new Context(...);
        ServletHandler handler = context.getServletHandler();
        ...

        Show
        Greg Wilkins added a comment - Fixed in 6.1.0 For 6.0.2 you can work around the issue if you code like: Context context = new Context(...); ServletHandler handler = context.getServletHandler(); ...
        Hide
        Frank Cornelis added a comment -

        Hi Greg,

        I've tried:
        ...
        Server server = new Server();
        Connector connector = new SelectChannelConnector();
        connector.setPort(0);
        server.addConnector(connector);

        ContextHandler contextHandler = new ContextHandler();
        contextHandler.setContextPath("/");
        server.addHandler(contextHandler);

        Context context = new Context();
        ServletHandler handler = context.getServletHandler();
        contextHandler.setHandler(handler);
        ...

        but I still get "HTTP/1.1 404 Servlet_Not_Initialized".
        Could you post the entire sequence that I should use to initialize Jetty 6.0.x?

        I saw your blog entry http://blogs.webtide.com/gregw/2006/12/16/1166307599250.html
        Jetty is indeed the perfect environment to test servlets. I use(d) it to test a servlet that implements the TSP protocol.

        Regards,
        Frank

        Show
        Frank Cornelis added a comment - Hi Greg, I've tried: ... Server server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(0); server.addConnector(connector); ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath("/"); server.addHandler(contextHandler); Context context = new Context(); ServletHandler handler = context.getServletHandler(); contextHandler.setHandler(handler); ... but I still get "HTTP/1.1 404 Servlet_Not_Initialized". Could you post the entire sequence that I should use to initialize Jetty 6.0.x? I saw your blog entry http://blogs.webtide.com/gregw/2006/12/16/1166307599250.html Jetty is indeed the perfect environment to test servlets. I use(d) it to test a servlet that implements the TSP protocol. Regards, Frank
        Hide
        Greg Wilkins added a comment -

        Server server = new Server();
        Connector connector = new SelectChannelConnector();
        connector.setPort(0);
        server.addConnector(connector);

        Context context = new Context();
        contextHandler.setContextPath("/");
        server.addHandler(context);

        ServletHandler handler = context.getServletHandler();

        ServletHolder servletHolder = new ServletHolder();
        servletHolder.setClassName(TestServlet.class.getName());
        servletHolder.setName("TestServlet");
        handler.addServlet(servletHolder);

        ServletMapping servletMapping = new ServletMapping();
        servletMapping.setServletName("TestServlet");
        servletMapping.setPathSpecs(new String[]

        { "/*" }

        );
        handler.addServletMapping(servletMapping);

        Show
        Greg Wilkins added a comment - Server server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(0); server.addConnector(connector); Context context = new Context(); contextHandler.setContextPath("/"); server.addHandler(context); ServletHandler handler = context.getServletHandler(); ServletHolder servletHolder = new ServletHolder(); servletHolder.setClassName(TestServlet.class.getName()); servletHolder.setName("TestServlet"); handler.addServlet(servletHolder); ServletMapping servletMapping = new ServletMapping(); servletMapping.setServletName("TestServlet"); servletMapping.setPathSpecs(new String[] { "/*" } ); handler.addServletMapping(servletMapping);
        Hide
        Frank Cornelis added a comment -

        When replacing
        contextHandler.setContextPath("/");
        with
        context.setContextPath("/");
        in your given sequence it seems to work as expected. Thanks Greg.

        Show
        Frank Cornelis added a comment - When replacing contextHandler.setContextPath("/"); with context.setContextPath("/"); in your given sequence it seems to work as expected. Thanks Greg.

          People

          • Assignee:
            Greg Wilkins
            Reporter:
            Frank Cornelis
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: