users@grizzly.java.net

Re: Session management bug / Static resource as stream

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Tue, 02 Sep 2008 18:44:38 -0400

Salut,

Loic Petit wrote:
> Hi again,
>

Thanks for the patch. I've applied it. Do you need an official release?
I can cut a 1.8.5.x if you need one.


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

Thanks!

>
> 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 !

I agree.

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 ?

I was under the impression the code was working :-) :-) So with your
patch, you make sure the contextPath and the ServletPath are compared
against the original URI. But fullPathURI is computed as:

> if (fullUrlPath == null){
> fullUrlPath = contextPath + servletPath;
> }

What is the difference? Sorry that might be a stupid question....

>
> Here is my personal ServletAdapter (attachment).

BTW You don't have to call:

request.getRequest().action(ActionCode.ACTION_POST_REQUEST, null);

as StaticResourceAdapter.postService will do it for you:

https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/tcp/StaticResourcesAdapter.html#210

Same for res.finish();

I like the getResourceAsStream :-) I need to make sure I don't break any
existing application, but I will for sure add/work on your recommendation.


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 :)

This is a good recommendation. Sorry for asking again, but can you file
an RFE? I suspect I can re-use the Jetty one (Apache2 licence). I just
need to learn how Greg did it.

Keep the recommendations coming!

A+

-- Jeanfrancois



>
>
>
>
> 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
>
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net