Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Enabling Session

Thanks for your awnser..

Looks like ServletContextHandler has what i need.

best regards,
Felipe

2009/11/6 Michael Gorovoy <michael@xxxxxxxxxxx>
Felipe,

ServletContextHandler already implements session support, so it would be the easiest route. All the methods of the Request object that you could possibly need in a servlet are available through javax.servlet.http.HttpServletRequest interface. To get the target of a request for example, you would call request.getRequestURI().

In the handle() method of a ContextHandler you get two different references to possibly the same object. The request parameter references it through the interface that it implements, and potentially it could pass a wrapped request object. Whereas baseRequest parameter is needed to obtain the original request object while performing internal processing inside the core handlers.

If you still want to use a handler and need session support, you would have to implement your handler, instantiate org.eclipse.jetty.server.SessionHandler (that implements HandlerWrapper interface) and chain it with your handler as follows.

MyHandler myHandler = new MyHandler();

SessionHandler sessionHandler = new SessionHandler();
sessionHandler.setHandler(myHandler);

server.setHandler(sessionHandler);

-Michael


Michael Gorovoy / michael@xxxxxxxxxxx


On Thu, Nov 5, 2009 at 11:13 PM, Felipe Cruz <felipecruz@xxxxxxxxxxx> wrote:
But with servlethandler, my servlet signature is

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

With ContexHandler, my handler signature is

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
I don't have 'target' and baseRequest arguments using servlets.. is there some workaround in order to use servlets and still
get baseRequest and target?

best regards.
Felipe

2009/11/5 Michael Gorovoy <michael@xxxxxxxxxxx>

Felipe,

Below are the examples of embedded ServletContextHandler usage you may find useful.

http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContext.java

http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java

Michael Gorovoy / michael@xxxxxxxxxxx


On Thu, Nov 5, 2009 at 12:43 PM, Felipe Cruz <felipecruz@xxxxxxxxxxx> wrote:
Hello everyone,

I'm starting a new project with jetty and after reading jetty documentation I picked ContextHandler to implement what I need.

My question is: is there someway to have Session and Cookies suport (with HashSessionManager for example) together with ContextHandler?

I know that ServletContextHandler will give me Session suppor but my code does not work.

        Server server = new Server(8080);

        ServletContextHandler context = new ServletContextHandler(server,"/",ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.setResourceBase(".");
        context.setClassLoader(Thread.currentThread().getContextClassLoader());
        context.setHandler(new Adapter(BasicApp.class)); // Adapter extends AbstractHandler
       
        server.setHandler(context);


Can anyone help me?

Thanks,
Felipe

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



Back to the top