如何使用 jax-ws commons 配置 jax-ws 以与 Spring 一起使用?

发布于 2024-08-05 17:06:43 字数 1713 浏览 6 评论 0原文

在 web.xml 中,我有以下内容:

<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>

在我的应用程序上下文中,我有以下定义:

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

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

尝试访问 WSDL 时出现 NullPointerException:

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) 

奇怪...似乎是配置错误,但该死的事情就因为 NullPointerException 而死了!!!!!!!!!不提供日志记录。

部署在 Resin 中。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偏爱你一生 2024-08-12 17:06:43

更新:我终于找到了这个问题的真正答案并发布了
它在这里:
http://forum.springsource.org/showthread.php?p=286701

简而言之,Resin 3x 附带了
XSD-unaware 解析器,你必须
将其替换为 Apache Xerces 或其他
其他解析器(参见上面的论坛帖子)。

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

以下 bean 定义使 Spring JAX-WS 正常工作(不使用“愚蠢的”xbean/命名空间魔法)。为此,我必须阅读源代码并找出要使用的正确类 - 有时通过故意提供一个我知道会导致异常的属性值(例如无效的类) - 这使我能够看到堆栈跟踪回到 bean 类)。

<?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>

其他一切都与上面链接的教程中相同(您在 web.xml 中添加 JAX-WS Spring servlet,添加 servlet 过滤器,以便将 Web 服务请求路由到 jaxws servlet)。

使用代理 Web 服务实例(从而启用依赖项注入、AOP 等)的关键是设置 proxyTargetClass="true" 以强制使用 CGLIB 代理而不是 JDK 动态代理(需要一个接口)。由于某种原因,JAX-WS 似乎不喜欢接口。

我希望这对某人有所帮助!

问候,
莱斯

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

情绪少女 2024-08-12 17:06:43

LES2:您的实现看起来最复杂。
简单使用 SpringBeanAutowiringSupport 有什么问题,如 Spring 手册

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文