Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Handling several /path* with different handler in the most efficient method possible

Please note that when I try to run this code (jetty 7.2.2) I'm getting null pointer exception 

public class Launcher {
    public static void main(String[] args) throws Exception
    {
        Server server = new Server();
        Connector connector = new SocketConnector();
        connector.setPort(8080);
        server.setConnectors(new Connector[]
        { connector });

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

        handler.addServletWithMapping(HelloServlet.class, "/");

        server.start();
        server.join();
    }

    public static class HelloServlet extends HttpServlet
    {
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        {
            response.setContentType("text/html");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().println("<h1>Hello SimpleServlet</h1>");
        }
    }
}


WARN  org.eclipse.jetty.util.log - /
java.lang.NullPointerException: null
at org.eclipse.jetty.servlet.ServletHolder.makeUnavailable(ServletHolder.java:408) ~[jetty-servlet-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:450) ~[jetty-servlet-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:331) ~[jetty-servlet-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) ~[jetty-servlet-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:475) [jetty-servlet-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:405) [jetty-servlet-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) [jetty-server-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:114) [jetty-server-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.server.Server.handle(Server.java:352) [jetty-server-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:596) [jetty-server-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1051) [jetty-server-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:590) [jetty-http-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:212) [jetty-http-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:426) [jetty-server-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:241) [jetty-server-7.2.2.v20101205.jar:7.2.2.v20101205]
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:451) [jetty-util-7.2.2.v20101205.jar:7.2.2.v20101205]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_22]



On Wed, Jan 19, 2011 at 11:20 AM, Maxim Veksler <maxim@xxxxxxxxxxxx> wrote:
Hello list,

I'm moving code that is implemented using several servlets to be jetty (embedded) based service.
I've looked at the various examples / documentation where it mentioned that using ServletContextHandler is often too much of an overhead solution for something simple as context routing.

I don't need sessions / security in my request handling.

I have several Servlets (Servlet1, Servlet2, Servlet3) which I would like to configure handlers for on the following paths:

/servlet1 = Servlet1
/test/servlet2 = Servlet2
/ = Servlet3

How would you recommend me implementing this with jetty?

Thank you,
Maxim.


Back to the top