Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 721
Kenster Avatar asked Apr 03 '13 21:04

Kenster


1 Answers

So, what does it mean to say that Java 7 comes with Metro..?

This is not entirely correct. JDK6+ includes JAX-WS RI (reference implementation), and Metro is a superset of it. In other words, Metro = JAX-WS RI + WSIT.

Is it possible to run a JAX-WS web service within Tomcat using just the jars that come with Java?

This is an excellent question. Answer is - no, because WSServlet class extends HttpServlet, and WSServletContextListener implements ServletContextAttributeListener and ServletContextListener interfaces. These interfaces and classes are all part of Java EE, not Java SE - thus not included in JDK/JRE. Sun/Oracle decided not to mix Java SE and Java EE, and that's understandable even though it means that these classes have been actually taken out of JAX-WS RI version that comes with JDK/JRE. Therefore, you have to install JAX-WS dependencies in order to use JAX-WS-based Web services on Tomcat, because Tomcat doesn't come with it (on the other hand, if you choose Glassfish for example, you will find complete Metro distribution bundled with it and you don't have to install anything additionally). Otherwise, you are stuck with Endpoint#publish mechanism.

See also:

  • WSServletContextListener and WSServlet in JRE 6
like image 52
Miljen Mikic Avatar answered Nov 15 '22 15:11

Miljen Mikic