Search code examples
javaweb-servicestomcatjax-wsjava-metro-framework

JAX-WS Implementation included with Java?


I have a JAX-WS web service application which deploys as a WAR file for Tomcat 7. It uses a recent version of the Metro libraries, which I include inside the WAR file, and it works fine.

I'm trying to simplify the deployment package. I understand that the Sun JDK includes a copy of Metro (see this question and this one for example), yet for some reason, it's apparently mandatory to replace this copy of metro with one downloaded from the glassfish site. I'm trying to understand if it's possible to get by with just Tomcat and the metro implementation that comes with the JDK, or if not why not.

The WAR contents are as follows (class files removed):

META-INF/MANIFEST.MF
WEB-INF/classes/
WEB-INF/classes/com/[et cetera]
WEB-INF/ibm-web-ext.xml
WEB-INF/lib/
WEB-INF/lib/stax-api.jar
WEB-INF/lib/webservices-api.jar
WEB-INF/lib/webservices-extra-api.jar
WEB-INF/lib/webservices-extra.jar
WEB-INF/lib/webservices-rt.jar
WEB-INF/lib/webservices-tools.jar
WEB-INF/sun-jaxws.xml
WEB-INF/web.xml
wsdl/
wsdl/MyService.wsdl

web.xml contains, in part:

<servlet>
    <servlet-name>MyService</servlet-name>
    <servlet-class>
        com.sun.xml.ws.transport.http.servlet.WSServlet
    </servlet-class>              
</servlet>

When I remove the webservices-* jars--the Metro jars--from the WAR, the web service fails with the error " Wrapper cannot find servlet class com.sun.xml.ws.transport.http.servlet.WSServlet or a class it depends on". This isn't surprising because I can't find that class anywhere in the jars that come with Java 7 SE.

So, what does it mean to say that Java 7 comes with Metro, if you have to download another copy of Metro to make something like this work? Is it possible to run a JAX-WS web service within Tomcat using just the jars that come with Java?


Solution

  • Bundled JAX-WS lacks integration with servlet containers, as it is intended to be used only to offer JAX-WS services inside standalone Java applications (WTF!?!?!?).

    Of course, one could think of implementing a servlet that does that integration, so you would not have to include another copy of Metro in your WAR. But it is easier to just include an external "full" copy, it bloats the WAR but should not have a great performance penalty. Furthermore, in this way you can control which version you use, avoiding to get stuck with the version that was included in your JRE.

    Anyway, Sun usually changed package names in bundled libraries so they would not collide with external ones, Therefore, if the servlet would exist (it does not), it would probably be called:

    com.sun.xml. internal. ws.transport.http.servlet.WSServlet

    This is very annoying as they also changed some configuration properties in the same way (e.g.: timeout related ones), so if you use the bundled JAX-WS you have to use

    com.sun.xml. internal.... style configuration properties,

    but if you use some external JAX-WS you have to use

    com.sun.xml.... style configuration properties.

    Thanks Sun!!