Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAX-WS Web service on Tomcat without sun-jaxws.xml

I am trying to minimize required configuration while deploying JAX-WS-based Web service on Tomcat. With the introduction of Servlet 3.0 (supported by Tomcat 7+), web.xml can be thrown out, but there is still sun-jaxws.xml. This blog post is interesting:

Of course, with the use of jax-ws annotations, even configuration sun-jaxws.xml can be made optional making it completely descriptor free, but that requires specifying a default url-pattern like in JSR-109 or custom pattern like in Jersey REST services, in the JAX-WS specification.

Is it possible to avoid sun-jaxws.xml on Tomcat, and how?

like image 418
Miljen Mikic Avatar asked May 14 '13 07:05

Miljen Mikic


People also ask

What is Sun JAX-WS XML?

sun-jaxws. xml is a proprietary deployment descriptor needed when web services are deployed as a standard WAR archive on a non-Java EE5 servlet container using the SUN's reference implementation.

Does Tomcat support SOAP?

In this example, the Eclipse Java EE IDE is used to create a new Java SOAP service. The Apache Tomcat web server is used to deploy and run the Java SOAP service and SOAP-UI is used to test the service operations.


1 Answers

Sadly, the configuration must exist somewhere. That is mandatory, per the source. Believe it or not, the location of the sun-jaxws.xml file is hard-coded to /WEB-INF/sun-jaxws.xml (thanks, guys @ Metro).

Effectively, you need to take control of the following classes

  • public final class WSServletContextListener

  • public class WSServlet


What needs to happen:

  1. WSServletContextListener will obviously not be extended. This listener performs most of the initializations per the sun-jaxws.xml and jaxws-catalog file. Like I mentioned earlier, the location is hard coded. So your path of least resistance here is to

    • implement your own vanilla servlet listener (with @WebListener) and call a new WSServletContextListener(). You'll then delegate your own contextInitialized(ServletContext ctxt) and contextDestroyed() methods to the ones in your instance of WSServletContextListener.

    • Generate the file on instantiation of the listener, on the fly, using an @XmlRootElement class that'll represent the sun-jaxws file(I'll provide a sample of this in a short while, don't have the time right now :) ).

It's a lot of trouble for such a dispensable convenience, IMO, but it should work in theory. I'll write some samples and see how they play shortly.

like image 150
kolossus Avatar answered Oct 04 '22 02:10

kolossus