Using ServletBridge with Tomcat 7 (Servlet 3.0) [message #1699544] |
Wed, 24 June 2015 19:35  |
Eclipse User |
|
|
|
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 #1699764 is a reply to message #1699699] |
Fri, 26 June 2015 08:20  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03512 seconds