我正在尝试为SOAP服务创建入站网关,该服务接受以下SOAP请求:
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<RequestHeader xmlns="http://test.com/">
<SecurityToken>mytoken</SecurityToken>
<RequestID>1234</RequestID>
</RequestHeader>
</S:Header>
<S:Body>
<BaseRequest xmlns="http://test.com/">
<RequestData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="BalanceRequest">
<CustomerID>1234</CustomerID>
</RequestData>
</BaseRequest>
</S:Body>
</S:Envelope>
我想使用JAXB来编组/解组请求/响应。我已设法使用以下内容配置Spring / Spring集成:
<oxm:jaxb2-marshaller id="soapMarshaller" context-path="com.test" />
<int:channel id="soap-channel"/>
<int-ws:inbound-gateway id="ws-inbound-gateway"
request-channel="soap-channel"
marshaller="soapMarshaller"/>
<int:service-activator input-channel="soap-channel">
<bean class="com.test.SoapServiceActivator"/>
</int:service-activator>
我试图在服务激活器中提取SOAP标头和主体。
@ServiceActivator
public BaseResponse issueResponseFor(BaseRequest body,
@Headers Map<String, Object> headerMap) {
return null;
}
BaseRequest是一个带JAXB注释的类。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"requestData"
})
@XmlRootElement(name = "BaseRequest")
public class BaseRequest {
@XmlElement(name = "RequestData")
protected BaseRequestBody requestData;
}
我的问题是在变量体中,我得到了SOAP请求的主体,但我还是找不到提取SOAP请求的头部。 headerMap变量仅包含标准的Spring-Integration标头(replyChannel,errorChannel,id,timestamp)。通过标头,我的意思是SecurityToken + RequestID,以及带有所请求操作名称的HTTP标头。
知道怎么做吗?
答案 0 :(得分:3)
尝试使用mapped-request-headers="*"
。
默认情况下,DefaultSoapHeaderMapper
仅映射标准标头。在这种情况下,它只是WebServiceHeaders.SOAP_ACTION
<强>更新强>
引用奥马尔: - )
谢谢!以下代码非常有用:
@Autowired
@Qualifier("soapMarshaller")
Jaxb2Marshaller marshaller;
@ServiceActivator
public BaseResponse issueResponseFor(BaseRequest request, @Header("RequestHeader") SoapHeaderElement soapHeader) {
BaseRequestHeader requestHeader = (BaseRequestHeader) JAXBIntrospector.getValue(marshaller.unmarshal(soapHeader.getSource()));`