Search code examples
tomcat7jax-ws

Deployment Error for JAX-WS Webapp


Bit of a strange one here, that has me completely blocked.

I have a webapp, with some JAX-WS annotated classes. Also, when the webapp is deployed, a third party framework is initialized, using a listener ThirdPartyContextListener in web.xml. So far so good. (For info, the framework is responsible for ORM, caching and data persistence.)

The trouble starts when some of my JAX-WS classes need to use the framework. It seems that the framework has not been initialised (via the ThirdPartyContextListener) early enough. As in, it seems that when the web service classes are instantiated, ThirdPartyContextListener hasn't yet been invoked.

The listeners are definitely in the correct order in my web.xml, so I would expect my ThirdPartyContextListener to be the first piece of code to get executed:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>

    ... stuff here ...

    <listener>
        <listener-class>ThirdPartyContextListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>WSServlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>WSServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    ... stuff here also ...

</web-app>

So I have a couple of questions:

  • Why are the JAX-WS classes instantiated so early? (Or at least look this way)
  • Is there a way to force the framework to be initialised first

Unfortunately I can't really give code samples (security restrictions from my work place).

Thanks very much!


Solution

  • I noticed the following lines in my log:

    Caused by: com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to parse runtime descriptor: java.lang.NullPointerException
        at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:141)
        at com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer.onStartup(WSServletContainerInitializer.java:65)
    

    So it would seem JAX-WS is doing some work before the of the listeners get hit; from the looks of it , it's creating delegates for each of the services endpoints I have defined. I'm fairly certain you cannot alter the order of XxxxContainerInitializer, so I looked at other alternatives. One of these was to use spring to look after the webservices.

    This required a few more JARs, some of which were conflicting with the third party framework we are suing. This was quickly making our solution a little too complex... so I stopped trying to be clever and just used lazy singletons instead.

    (Sounds awful, but it suits us better because each service call requires a call to the third party framework anyway.)