users@grizzly.java.net

Re: Session management bug / Static resource as stream

From: Loic Petit <loic.petit_at_gmail.com>
Date: Tue, 2 Sep 2008 23:32:28 +0100

Hi again,

As you may have seen I submitted the bugs via the issues trackers.

I also noticed something weird... when you have multiple adapters
(different context path). When you want to access to the second one
you have the message "Resource not found" and the generated page.
Because you have this :

             if (!uri.startsWith(fullUrlPath)) {
                 customizeErrorPage(response, "Resource Not Found",
404);
                 return;
             }

Ok we need to set the code to 404 for the ServletAdapterChain but we
do not need to print ResourceNotFound each time I think ! In the file
I send I overrided this problem by treating the context path
correctly. Should I send a patch too or is it my fault ?

Here is my personal ServletAdapter (attachment). Actually I'm using
ResourceAsStream because I keep everything in my classpath so it's
easier for me. I would suggest to create a resource class and a
factory to create them (jetty-like) but do as you want :)






Le 2 sept. 08 à 22:36, Jeanfrancois Arcand a écrit :

> Salut,
>
> switching to users list.
>
> Loic Petit wrote:
>> Hi,
>> I'm using the wicket framework with Grizzly. And I discovered that
>> when the session manager wants to bind a session it raises an NPE
>> in HttpSessionImpl.access() because there is no GrizzlySession
>> attached (GrizzlySession.getSession(false) returned null). After
>> some researchs I found the problem... The cookie containing the
>> session id (JSESSIONID) is never parsed thus it is not possible for
>> httpSession (in HttpServletRequestImpl) to be initialized.
>> Here is what I have changed :
>> in ServletAdapter:
>> public void service(GrizzlyRequest request, GrizzlyResponse
>> response) {
>> ....
>> if (httpRequest == null) {
>> ....
>> Cookie[] cookies = request.getCookies();
>> if (cookies != null) for (Cookie c : cookies) {
>> if
>> (Constants.SESSION_COOKIE_NAME.equals(c.getName())) {
>> request.setRequestedSessionId(c.getValue());
>> request.setRequestedSessionCookie(true);
>> break;
>> }
>> }
>> httpRequest.initSession();
>> ....
>> in HttpServletRequestImpl :
>> public void initSession() {
>> GrizzlySession session = request.getSession(false);
>> if (session != null) {
>> httpSession = new HttpSessionImpl(contextImpl);
>> httpSession.setSession(session);
>> httpSession.access();
>> }
>> }
>> It may not be at the right place into the whole project but for me
>> it's working.
>
> Can you send a svn diff? Better, just file an issue here:
>
> https://grizzly.dev.java.net/issues/
>
> and attach your patch. So far your changes looks good but just be be
> 100% sure.
>
>
>> I also discovered that you use the class java.io.File for the
>> static content. Thus you can't allow reading in jar files for
>> example (it's my case) by passing an URI. To handle that I've build
>> my own adapter to handle the static content with
>> MyClass.class.getResourceAsStream. It's working but it's not that
>> beautifull :s.
>
> Can you share the code snipped you used? Just curious. I wonder how
> I can determine from the StaticResourceAdapter if the application is
> running inside a jar or not. I did some work on the ClassLoaderUtil:
>
> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/util/ClassLoaderUtil.html
>
> I suspect I can improve to support what you are recommending.
>
>> Do you plan to do handle them via URI ?
>
> That's a really good point. Which Grizzly version are you using? I
> can certainly give it a try. Can you file an RFE here:
>
> https://grizzly.dev.java.net/issues/
>
> Merci!
>
> -- Jeanfrancois
>
>
>
>> Enjoy !
>> Loïc
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: issues-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: issues-help_at_grizzly.dev.java.net

Enjoy !

Loïc