Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Using ServletBridge with Tomcat 7 (Servlet 3.0)
Using ServletBridge with Tomcat 7 (Servlet 3.0) [message #1699544] Wed, 24 June 2015 23:35 Go to next message
Jennifer Mising name is currently offline Jennifer Mising nameFriend
Messages: 6
Registered: July 2009
Junior Member
Hi,

I have a web application running in OSGi. I use the servlet bridge library (version 1.2) for deploying my application to Tomcat. I have been registering my servlets by contributing to the extension point org.eclipse.equinox.http.registry in my plugin and adding the following packages to manifest.mf:

Import-Package: javax.servlet,
 javax.servlet.http


Things have been going perfect so far with this approach.

~~~~~

Now, I would like to make one of my servlets async-supported. I tried to do this by adding the following annotation to my servlet class:

@WebServlet(name = "OrderServlet", urlPatterns = {"/order"}, asyncSupported = true)
public class OrderServlet extends HttpServlet {
...
}


This requires javax.servlet.annotation to be added to the manifest:

Import-Package: javax.servlet,
 javax.servlet.annotation,
 javax.servlet.http


When I re-deploy my WAR with this change, my plugin fails to load. OSGi console shows the following error when I try to manually start the bundle:

id      State       Bundle
5       INSTALLED   abc.asyncServlet_1.0.0
osgi> start 5
gogo: BundleException: The bundle "abc.asyncServlet_1.0.0 [5]" could not be resolved. Reason: Missing Constraint: Import-Package: javax.servlet.annotation; version="0.0.0"
osgi> diag 5
update@plugins/abc.asyncServlet_1.0.0.jar [5]
  Direct constraints which are unresolved:
    Missing imported package javax.servlet.annotation_0.0.0.


I am using Tomcat 7 and verified that the servlet-api.jar (version 3.0) in my tomcat/lib directory has the annotation package, so the problem does not seem to be related to my Tomcat.

I then try to drill down to the equinox-related plugins that I package with my WAR. I found that org.eclipse.equinox.servletbridge.FrameworkLauncher generates org.eclipse.equinox.servletbridge.extensionbundle_1.2.0 with the following package exports:

Export-Package: org.eclipse.equinox.servletbridge; version=1.1, javax.
 servlet; version=3.0, javax.servlet.http; version=3.0, javax.servlet.
 resources; version=3.0


So my guess is that it is the missing java.servlet.annotation in Export-Package that causes the problem.

I try to play around with the FrameworkLauncher code - get a newer version of servlet bridge (1.3), make some changes to the generateExtensionBundle() method in FrameworkLauncher, so that javax.servlet.annotation is included in Export-Package. My plugin is finally in RESOLVED state and all my servlets, including the one with asyncSupported=true, are working as before.

Am I correct that there is some issue with the servlet bridge I am using, or I am in a totally wrong direction?

Thanks for the help!!
Re: Using ServletBridge with Tomcat 7 (Servlet 3.0) [message #1699634 is a reply to message #1699544] Thu, 25 June 2015 12:28 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 486
Registered: July 2009
Senior Member
The OSGi HttpService implementation is the container for your serlvet in this environment. Tomcat knows nothing about your servlet so it will not process the annotations. The OSGi HttpService implementation does not process annotations either.

For the Mars release the Equinox Http Service implementation also supports the new OSGi Http Whiteboard specification that allows you to register your servlets as OSGi services instead of programmatically with the HttpService (or you may be using the Equinox Http registry extension).

With the Http Whiteboard specification you can register your servlets with a service property that indicates that it is an async servlet. But you must register your servlets as OSGi services (I would recommend using declarative services to do so). Using the HttpService directly to register your servlet will not provide you a way to support async.

The final R6 compendium/enterprise spec will be released very soon. But you can get access to the final drafts at http://www.osgi.org/Specifications/Drafts
Re: Using ServletBridge with Tomcat 7 (Servlet 3.0) [message #1699699 is a reply to message #1699634] Fri, 26 June 2015 00:05 Go to previous messageGo to next message
Jennifer Mising name is currently offline Jennifer Mising nameFriend
Messages: 6
Registered: July 2009
Junior Member
Thank you very much Thomas for the info! It is very helpful! I was initially wondering why I cannot specify asyncSupported=true through the Equinox Http registry extension.

Do I have a workaround for now? Can I register my async servlet directly with tomcat through web.xml? I am going to try it out but I wonder how well it will play with OSGi....
Re: Using ServletBridge with Tomcat 7 (Servlet 3.0) [message #1699764 is a reply to message #1699699] Fri, 26 June 2015 12:20 Go to previous message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 486
Registered: July 2009
Senior Member
I'm not entirely sure how you will go about registering your servlet from the OSGi container with tomcat.

The right way to do this is to move to using the Http Whiteboard Equinox implementation in your servlet bridge war. I know this works because that is one of the main usecases that motivated Ray Auge from Liferay to contribute the implementation of the new spec to Equinox.
Previous Topic:ProvisioningJob and Invalid thread access
Next Topic:Local path for p2 repository after product exprt
Goto Forum:
  


Current Time: Tue Sep 25 01:40:45 GMT 2018

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

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

Back to the top