Spring WS 2.0.2:将StAX与@Endpoint一起使用

时间:2011-06-09 13:56:53

标签: java web-services spring-ws

我正在尝试将StAX与Spring WS 2.0.2一起使用,但我没有运气好。我在网上找到了一个示例here,但它使用的是AbstractStaxStreamPayloadEndpoint,现在在Spring WS 2.x中已弃用。我正在尝试使用@Endpoint注释方法,但我收到以下错误:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring xml:lang="en">No adapter for endpoint [public void com.endpoint.AddressTypeEndpoint.handleReadAddressTypeRequest(javax.xml.stream.XMLStreamReader,javax.xml.stream.XMLStreamWriter) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我的终端的代码:

package com.endpoint;

import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;

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

@Endpoint
public class AddressTypeEndpoint {
    private static final String NAMESPACE_URI = "http://client/AddressType";

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "ReadAddressTypeRequest")
    public void handleReadAddressTypeRequest(XMLStreamReader streamreader, XMLStreamWriter streamwriter) throws Exception {
        System.out.println("Got to the endpoint");
    }
}

有没有人知道如何使用@Endpoint将StAX与Spring WS一起使用?

2 个答案:

答案 0 :(得分:2)

您可以尝试注释方法参数:

 @PayloadRoot(namespace = NAMESPACE_URI, localPart = "ReadAddressTypeRequest")
 public void handleReadAddressTypeRequest(
      @RequestPayload XMLStreamReader streamreader) throws Exception {... }

[编辑]对于回复,请使用@ResponsePayload为方法添加注释,并返回此处列出的对象之一http://static.springsource.org/spring-ws/site/reference/html/server.html#d4e1220(而不是void

答案 1 :(得分:0)

尝试使用@ResponsePayload,如Spring WS doc中所述:http://static.springsource.org/spring-ws/sites/2.0/reference/html/server.html