使用CXF处理SOAPAction

时间:2013-05-31 19:55:39

标签: soap cxf apache-camel

我正在试图弄清楚如何处理SOAP请求,其中SOAPAction在消息头中指定,但不在消息体中。以下是我需要处理的示例请求。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.afis.com/">
   <soapenv:Header/>
   <soapenv:Body>
         <String>12</String>
   </soapenv:Body>
</soapenv:Envelope>

SOAPAction位于上述请求的标题中,如下:

  

SOAPAction:“urn:process”

以下是有效的请求。注意“process”元素(AKA SOAPAction)。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.afis.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <soap:process>
         <String>12</String>
      </soap:process>
   </soapenv:Body>
</soapenv:Envelope>

这是CXF端点:

<cxf:cxfEndpoint id="afisProcessEndpoint"
                     address="/wildcat"
                     serviceClass="com.afis.CCHEndpointImpl"/>

以下是实施:

@WebService(serviceName = "com.CCHEndpoint")
public class CCHEndpointImpl implements CCHEndpoint {
    @Override
    @WebMethod(operationName = "process", action = "urn:process")
    public String process(@WebParam(partName = "String", name = "String") String string) {
        return "sd";
    }
}

这是界面:

@WebService
public interface CCHEndpoint {
    @WebMethod(operationName = "process", action = "urn:process")
    public String process(@WebParam(partName = "String", name = "String")String string);
}

如果我在XML中提交没有process元素的请求(但在SOAP标题中),我会得到以下内容:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Unexpected wrapper element String found.   Expected {http://soap.afis.com/}process.</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

请注意,使用Axis2,我能够处理此类请求,因为services.xml将操作映射到我们的操作,但我无法将Axis2用于此项目。我需要一个与CXF等效的机制。我觉得cxfEndpoint中的额外配置,或者可能是注释,但我找不到解决方案。

1 个答案:

答案 0 :(得分:2)

请求中的<soap:process>元素实际上与操作无关。这是一个包装元素。根据JAX-WS规范,默认情况下,服务是在“包装”模式下创建的,其中有一个包装元素作为soap Body的直接子元素。如果你不想这样,只想直接操作参数,那么你需要在界面上添加@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)注释。