Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Shared ServletContexts in HTTPService
Shared ServletContexts in HTTPService [message #921969] Mon, 24 September 2012 15:54 Go to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1296
Registered: July 2009
Senior Member

Hi,

I've noticed that when registering servlets with the HTTPService, all
registered servlets have the same ServletContext, even when they are
registered with different HTTPContexts. I'm not sure if this is correct
behavior, at least it differs from Felix [1].

I've checked the code below both in Equinox from Kepler M1 and Apache
Karaf 2.2.9 using Jetty:

HttpServlet servlet1 = new TestServlet();
HttpContext httpContext1 = httpService.createDefaultHttpContext();
httpService.registerServlet( "/foo", servlet1, null, httpContext1 );

HttpServlet servlet2 = new TestServlet();
HttpContext httpContext2 = httpService.createDefaultHttpContext();
httpService.registerServlet( "/bar", servlet2, null, httpContext2 );

System.out.println( "HttpContext: "
+ httpContext1.hashCode()
+ " "
+ httpContext2.hashCode() );
System.out.println( "ServletContext: "
+ servlet1.getServletContext().hashCode()
+ " "
+ servlet2.getServletContext().hashCode() );

In both environments, the HttpContext instances are different, as
expected. But while the ServletContexts differ in Karaf, they are the
same in Equinox. Both servlets also get different HttpSessions in Karaf.
This behavior allows to isolate web applications within the same OSGi
instance.

Is this difference intended or would you consider it a bug?

Thanks,
Ralf

[1]
http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-ServletContextNotes

--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Shared ServletContexts in HTTPService [message #922696 is a reply to message #921969] Tue, 25 September 2012 08:37 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 453
Registered: July 2009
Location: Germany ✈ Vancouver
Senior Member

Hi Ralf,

Am 24.09.2012 17:54, schrieb Ralf Sternberg:
> In both environments, the HttpContext instances are different, as
> expected. But while the ServletContexts differ in Karaf, they are the
> same in Equinox. Both servlets also get different HttpSessions in Karaf.
> This behavior allows to isolate web applications within the same OSGi
> instance.
>
> Is this difference intended or would you consider it a bug?

I read the OSGi specification as not being very strict about it. Here is
the relevant paragraph:

"[The ServletContext] is created by the implementation of the Http
Service for each unique HttpContext object with which a Servlet object
is registered. Thus, Servlet objects registered with the same
HttpContext object must also share the same ServletContext object."

It looks like the only hard requirement is to use the same
ServletContext for the same HttpContext objects but that's it. Although
the PAX Web behavior seems intuitive and I can see in the source code
how they create new contexts in Jetty for each HttpContext, I'd say it's
an implementation detail in PAX Web.

BTW, the OSGi Http Service spec doesn't mention the word "session" at
all. That's why I don't use the HttpService concept in a
multi-application environment.

I wonder if a feature request should be opened. It's an interesting idea
to support multiple applications with the same HttpService. However, I
don't see it easily supported using the current generic HttpService
implementation in Equinox. It's based on a Servlet itself and shared
between ServletBridge and Jetty.

-Gunnar



--
Gunnar Wagenknecht
gunnar@xxxxxxxx
http://wagenknecht.org/
Re: Shared ServletContexts in HTTPService [message #923243 is a reply to message #922696] Tue, 25 September 2012 18:47 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1296
Registered: July 2009
Senior Member

Thanks for your insights, Gunnar.

Yes, the spec is not very clear about this detail, so the current
behavior can probably not be considered a bug. On the other hand, having
separate "web applications" in one OSGi instance seems like the idea
behind the design and I was surprised to find that it is not implemented
this way in Equinox.

I agree that the PAX Web behavior is more intuitive, and also more
useful, and it would be great to have a similar behavior in Equinox.
I've opened an an enhancement request for it [1].

Regards, Ralf


[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=390381

--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Shared ServletContexts in HTTPService [message #925003 is a reply to message #923243] Thu, 27 September 2012 09:55 Go to previous message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 453
Registered: July 2009
Location: Germany ✈ Vancouver
Senior Member

Am 25.09.2012 20:47, schrieb Ralf Sternberg:
> [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=390381

FYI, I pushed a modified Equinox HttpService:
https://github.com/eclipseguru/rt.equinox.bundles/tree/gunnar/bug390381

You can try by cloning the repo and importing bundle
"org.eclipse.equinox.http.servlet" into your workspace.

-Gunnar


--
Gunnar Wagenknecht
gunnar@xxxxxxxx
http://wagenknecht.org/
Previous Topic:Adding reference to other repostiories from p2.inf
Next Topic:Static content files outside bundle
Goto Forum:
  


Current Time: Sat Dec 20 20:18:20 GMT 2014

Powered by FUDForum. Page generated in 0.15122 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software