Question

In web.xml I have the following:

<servlet>
        <description>JAX-WS endpoint - EARM</description>
        <display-name>jaxws-servlet</display-name>
        <servlet-name>jaxws-servlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>jaxws-servlet</servlet-name>
        <url-pattern>/webServices/*</url-pattern>
    </servlet-mapping>

In my application context I have the following definitions:

<bean id="helloService" class="com.foo.HelloServiceImpl">        
    <property name="regularService" ref="regularService" />
</bean>

<wss:binding url="/webServices/helloService" service="#helloService" />

I get a NullPointerException when trying to access the WSDL:

java.lang.NullPointerException
at com.sun.xml.ws.transport.http.HttpAdapter.<init>(HttpAdapter.java:145)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.<init>(ServletAdapter.java:76)
at com.sun.xml.ws.transport.http.servlet.ServletAdapterList.createHttpAdapter(ServletAdapterList.java:5 0)
at com.sun.xml.ws.transport.http.servlet.ServletAdapterList.createHttpAdapter(ServletAdapterList.java:4 7)
at com.sun.xml.ws.transport.http.HttpAdapterList.createAdapter(HttpAdapterList.java:73)
at com.sun.xml.ws.transport.http.servlet.SpringBinding.create(SpringBinding.java:24)
at com.sun.xml.ws.transport.http.servlet.WSSpringServlet.init(WSSpringServlet.java:46) 

Strange ... appears to be a configuration error but the darn thing just dies with a NullPointerException!!!!!!!! No logging is provided.

Deployed in Resin.

Was it helpful?

Solution

UPDATE: I finally figured out the real answer to this problem and posted it here: http://forum.springsource.org/showthread.php?p=286701

In short, Resin 3x ships with an XSD-unaware parser and you have to replace it with Apache Xerces or some other parser (see above forum post).

=========================

The following bean definitions get the Spring JAX-WS working (without using the "stupid" xbean / namespace magic). To come by this, I had to read the source and figure out the correct classes to use - sometimes by intentionally providing a property value that I knew would cause an exception (such as an invalid Class - this allowed me to see the stack trace which lead back to the bean class).

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="webServiceMethodInterceptor"
    class="com.webservice.util.interceptors.WebServiceMethodInterceptor">
    <property name="userId" value="hello" />
    <property name="password" value="world" />
    <property name="roles" value="ROLE_ANONYMOUS,ROLE_MICKEY_MOUSE" />
</bean>

<bean id="webServiceLoggingInterceptor"
    class="com.webservice.util.interceptors.LoggingInterceptor">
    <property name="level" value="debug" />
</bean>

<bean id="webServiceExceptionTranslator"
    class="com.webservice.util.interceptors.WebServiceExceptionTranslator"/>

<!-- The list of interceptors to apply to all web methods -->
<bean id="webServiceInterceptors" class="java.util.LinkedList">
    <constructor-arg index="0">
        <list>
            <value>webServiceExceptionTranslator</value>
            <value>webServiceLoggingInterceptor</value>
            <value>webServiceMethodInterceptor</value>
        </list>
    </constructor-arg>
</bean>

<!-- Proxied ExampleWebService -->
<bean id="exampleWebService" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="target">
        <bean class="com.webservice.ExampleWebServiceImpl">
            <!-- TODO: add dependencies for web service here, for example:
            <property name="someService" ref="someService" />
            -->
        </bean>
    </property>
    <property name="interceptorNames" ref="webServiceInterceptors" />
    <property name="proxyTargetClass" value="true" />
</bean>

<!-- JAX-WS Endpoint for ExampleWebService -->
<bean class="com.sun.xml.ws.transport.http.servlet.SpringBinding">
    <property name="url" value="/webServices/exampleService" />
    <property name="service">
        <bean class="org.jvnet.jax_ws_commons.spring.SpringService">
            <property name="bean">
                <ref local="exampleWebService" />
            </property>
            <property name="impl"
                value="com.webservice.ExampleWebServiceImpl" />
        </bean>
    </property>
</bean>

Everything else is as in the tutorial linked to above (you add the JAX-WS Spring servlet in web.xml, add the servlet filter so that web service requests get routed to the jaxws servlet).

The key to using the proxied web service instance (thus enabling dependency injection, AOP, etc.) was setting proxyTargetClass="true" to force a CGLIB proxy instead of a JDK dynamic proxy (which requires an interface). JAX-WS seems to not like interfaces for some reason.

I hope this helps some one!

Regards, LES

OTHER TIPS

LES2: Your implementation seem most complex. What's wrong with simple usage of SpringBeanAutowiringSupport, as described in Spring manual

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top