|Shared ServletContexts in HTTPService [message #921969]
||Mon, 24 September 2012 15:54
|| Ralf Sternberg
Registered: July 2009
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 .
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: "
+ " "
+ httpContext2.hashCode() );
System.out.println( "ServletContext: "
+ " "
+ 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
Is this difference intended or would you consider it a bug?
Professional services for RAP and RCP?
|Re: Shared ServletContexts in HTTPService [message #922696 is a reply to message #921969]
||Tue, 25 September 2012 08:37
|| Gunnar Wagenknecht
Registered: July 2009
Location: San Francisco ✈ Germany
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
> 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
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.
Powered by FUDForum
. Page generated in 0.02385 seconds