使用带注释的端点时,spring ws 找不到适配器

发布于 2024-10-09 07:07:58 字数 5273 浏览 4 评论 0原文

我正在使用 Java 6 和 spring-ws 创建一个非常简单的 Web 服务,它接收 BusquedaRequest Jaxb 对象形式的 2 个参数并返回相同的对象。

该对象是使用 xjc 编译器创建的,我使用 Jaxb2Marshaller 作为 mashaller 和 GenericMarshallingMethodEndpointAdapter 来转换为传入的 xml 并输出。我在扩展 AbstractMarshallingPayloadEndpoint 类时进行了此操作,但当我切换到使用 Endpoint 和有效负载注释时,它总是失败。

Web 服务启动正常,但当与客户端连接时,我收到此异常。

java.lang.IllegalStateException: No adapter for endpoint [public package.busqueda.ws.BusquedaRequest package.busqueda.ws.BusquedaEndpoint.getResultas(package.busqueda.ws.BusquedaRequest)]: Does your endpoint implement a supported interface like MessageHandler or PayloadEndpoint?
 at org.springframework.ws.server.MessageDispatcher.getEndpointAdapter(MessageDispatcher.java:286)
 at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:227)
 at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:170)
 at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88)
 at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:57)
 at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:230)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
 at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
 at java.lang.Thread.run(Thread.java:662)

我已经看到对此问题的答复,建议使用我已经完成的 xjc 编译器来编译对象。还有人建议说适配器尚未在 spring-ws-servlet.xml 中定义,我也这样做了。请参阅下面定义的 spring-ws-servlet.xml:

    <?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="busquedaEndpoint" class="package.BusquedaEndpoint" />

 <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
        <constructor-arg ref="marshaller"/>
    </bean>

    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
            <list>
                <value>package.BusquedaRequest</value>
            </list>
        </property>
    </bean>

 <bean id="busqueda"
  class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
  <property name="schema" ref="schema" />
  <property name="portTypeName" value="Busqueda" />
  <property name="locationUri" value="/BusquedaService/" />
 </bean>

 <bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
  <property name="xsd" value="/WEB-INF/busqueda.xsd" />
 </bean>

 <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
</beans>

类端点如下:

package package.busqueda.ws;

import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

    @Endpoint
public class BusquedaEndpoint {

 @PayloadRoot(localPart = "BusquedaRequest", namespace = "http://busqueda/schemas")
 public BusquedaRequest getResultas( BusquedaRequest aRequest ) {
  return aRequest;
 }

}

我生成的 BusqeudaRequest 对象的 xsd 如下:

     <?xml version="1.0" encoding="UTF-8"?>
     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified"
 attributeFormDefault="qualified" 
 xmlns="http://busqueda/schemas"
 targetNamespace="http://busqueda/schemas">
 <xs:element name="BusquedaRequest">
  <xs:complexType>
   <xs:all>
    <xs:element name="Consulta" type="xs:string" />
    <xs:element name="Permisos" type="xs:string" />
   </xs:all>
  </xs:complexType>
 </xs:element>
</xs:schema> 

有人有任何想法可以扩展我已经实现的建议吗?

I am using Java 6 and spring-ws to create a very simple web service which receives 2 parameters in the form of a BusquedaRequest Jaxb object and returns the same object.

The object has been created with xjc compiler and I am using Jaxb2Marshaller as the mashaller and GenericMarshallingMethodEndpointAdapter to convert to incoming xml and out going. I had this working when extending the AbstractMarshallingPayloadEndpoint class but when I switch to using the Endpoint and payload annotations it always fails.

The web service starts up fine but when hitting it with a client I recieve this exception.

java.lang.IllegalStateException: No adapter for endpoint [public package.busqueda.ws.BusquedaRequest package.busqueda.ws.BusquedaEndpoint.getResultas(package.busqueda.ws.BusquedaRequest)]: Does your endpoint implement a supported interface like MessageHandler or PayloadEndpoint?
 at org.springframework.ws.server.MessageDispatcher.getEndpointAdapter(MessageDispatcher.java:286)
 at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:227)
 at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:170)
 at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88)
 at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:57)
 at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:230)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
 at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
 at java.lang.Thread.run(Thread.java:662)

I have seen response to this question which suggest to compile objects using the xjc compiler which I have done. Also there has been suggestions that the Adaptor hasn't been defined in the spring-ws-servlet.xml, which I have also done. See the spring-ws-servlet.xml defined below:

    <?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="busquedaEndpoint" class="package.BusquedaEndpoint" />

 <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
        <constructor-arg ref="marshaller"/>
    </bean>

    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
            <list>
                <value>package.BusquedaRequest</value>
            </list>
        </property>
    </bean>

 <bean id="busqueda"
  class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
  <property name="schema" ref="schema" />
  <property name="portTypeName" value="Busqueda" />
  <property name="locationUri" value="/BusquedaService/" />
 </bean>

 <bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
  <property name="xsd" value="/WEB-INF/busqueda.xsd" />
 </bean>

 <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
</beans>

The class endpoint is as follows:

package package.busqueda.ws;

import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

    @Endpoint
public class BusquedaEndpoint {

 @PayloadRoot(localPart = "BusquedaRequest", namespace = "http://busqueda/schemas")
 public BusquedaRequest getResultas( BusquedaRequest aRequest ) {
  return aRequest;
 }

}

The xsd I generated the BusqeudaRequest object is as follows:

     <?xml version="1.0" encoding="UTF-8"?>
     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified"
 attributeFormDefault="qualified" 
 xmlns="http://busqueda/schemas"
 targetNamespace="http://busqueda/schemas">
 <xs:element name="BusquedaRequest">
  <xs:complexType>
   <xs:all>
    <xs:element name="Consulta" type="xs:string" />
    <xs:element name="Permisos" type="xs:string" />
   </xs:all>
  </xs:complexType>
 </xs:element>
</xs:schema> 

Anyone got any thoughts which extend the suggestions I have already implemented?

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

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

发布评论

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

评论(2

白衬杉格子梦 2024-10-16 07:07:58

当遇到同样的问题时,我发现在 EndPoint 实现中的方法的参数中添加 @RequestPayload@ResponsePayload 注解可以解决问题。

When faced with the same problem, I found that adding @RequestPayload and @ResponsePayload annotations to the parameters of the method in the EndPoint implementation would solve the issue.

阪姬 2024-10-16 07:07:58

@whatsthebeef 也许这是题外话,或者晚了,但我看到问题出在哪里,
从我的角度来看,你使用 Marshaller 的方式很糟糕。

为什么使用classesToBeBound?
如果您使用XJC & JAXB生成过程你真的应该“仅仅”指向包,即

<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="contextPaths">
        <list>
            <value>my.package.where.the.jaxb-generated.stub-objects.reside</value>
        </list>
    </property>
</bean>

第二件事是,spring上下文应该如何知道你的编组器?我怀念使用适当的 Marshaller 的时光。

<bean id="endpointAdapter" class="org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
    <constructor-arg ref="jaxb2Marshaller"/>
</bean>

这就是我使用当前的 spring-ws 包所做的方式。
顺便说一句,堆栈跟踪告诉您问题出在 *EndpointAdapter 上。
如果对您有帮助,请告诉我。

@whatsthebeef Maybe it's offtopic, or late, but what I see where the problem is,
the way you use Marshaller from my point of view stinks.

Why do you use classesToBeBound?
If you use XJC & JAXB generating process you really should point 'just' to the package i.e.

<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="contextPaths">
        <list>
            <value>my.package.where.the.jaxb-generated.stub-objects.reside</value>
        </list>
    </property>
</bean>

2nd thing is, how should spring context know about your marshaller? I miss using the appropriate Marshaller.

<bean id="endpointAdapter" class="org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
    <constructor-arg ref="jaxb2Marshaller"/>
</bean>

That's the way i did it with the current spring-ws package.
Btw the stacktrace tells you that the problem is with the *EndpointAdapter.
Please let me know if it helped you.

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