2013-05-31 42 views
2

我想弄清楚如何處理一個SOAP請求,其中SOAPAction在消息頭中指定,但不在消息正文中。以下是我需要處理的示例請求。用CXF處理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: 「甕:過程」

以下是一個可行的請求。請注意「process」元素(也稱爲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中的流程元素(但在SO中AP頭),我得到如下:

<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中的額外配置,或者可能是一個註釋,但我找不到解決方案。

回答

2

請求中的<soap:process>元素確實與操作無關。這是一個包裝元素。根據JAX-WS規範,默認情況下,服務是以「包裝」模式創建的,其中有一個包裝元素作爲soap Body的直接子元素。如果你不需要,只需要直接操作參數,那麼你需要將@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)註釋添加到界面上。

+0

謝謝!這正是我需要的 – DKerr