why doesn't Tomcat 7x require WSServletContextListener and WSServlet configured in web.xml for Jax-ws service deployment?
Asked Answered
R

2

7

I'm deploying and testing a simple Jax-ws service in both Tomcat6x and Tomcat7x with the jaxws-ri-2.2.8 added to both the server lib directories .
Tomcat6x requires the WSServletContextListener and WSServlet and configured in web.xml whereas in Tomcat 7x the webservices gets deployed without the WSServletContextListener and WSServlet configuration.
Whats different in Tomcat7 that makes the web.xml configuration optional?

Rios answered 17/3, 2014 at 13:56 Comment(0)
R
9

If you are using Tomcat 7.x and Servlet 3.0, the listener com.sun.xml.ws.transport.http.servlet.WSServletContextListener is dynamically loaded. Since Java EE 6, a new component was added: javax.servlet.ServletContainerInitializer

Interface which allows a library/runtime to be notified of a web application's startup phase and perform any required programmatic registration of servlets, filters, and listeners in response to it.

The file jaxws-rt.jar contains in \META-INF\services a simple file text named javax.servlet.ServletContainerInitializer with one line:

com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer

This is the fully qualified class name which loads the required listener.

See also Using Servlets 3.0 ServletContainerInitializer.

Relationship answered 18/3, 2014 at 2:4 Comment(4)
Thanks very Much Paul. This answer clears a lot of questions of mine, though i have a question regarding the URL mapping.If we do not have a WSServlet to map a url-pattern , are all the requests verified against the url-patterns configured against the endpoints in the sun-jaxws.xml file ?Rios
If you see the code, you will find that the file sun-jaxws.xml is loaded as if you'd configured it in the normal way..Relationship
I did see the code where the sun-jaxws.xml is being loaded but failed to notice the method private void registerWSServlet(List<ServletAdapter> adapters, ServletContext context) which registers a WsServlet dynamically if there are any unregistered URL patterns. Thanks PaulRios
This is configured without a path prefix. The services' mappings (actually, for the servlet) are taken from the configuration file. If the sun-jaxws.xml does not have endpoints, the servlet is not added.Relationship
V
1

Tomcat 7 supports Servlet 3.0 that enables annotations to be used to configure various components of a web application including Servlets and Listeners.

Venesection answered 17/3, 2014 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.