在服务器端CXF服务实现中设置SOAP寻址头

时间:2016-01-05 14:38:42

标签: cxf soapheader

我在Apache CXF中实现了Web服务。有没有办法如何使用AddressingProperties将SOAP标头设置为请求(服务器端)?

这对我有用:

List<Header> headers = new ArrayList<Header>();
Header messageIDHeader = new Header(new QName("http://www.w3.org/2005/08/addressing", "MessageID", "wsa"), some_messageID, new JAXBDataBinding(String.class));
headers.add(messageIDHeader);
Header relatesToHeader = new Header(new QName("http://www.w3.org/2005/08/addressing", "RelatesTo", "wsa"), some_relatesTo_ID, new JAXBDataBinding(String.class));
headers.add(relatesToHeader);
wsContext.getMessageContext().put(Header.HEADER_LIST, headers);

但我想使用org.apache.cxf.ws.addressing.AddressingProperties - 就像这样:

RelatesToType soapRelatesTo = new RelatesToType();
soapRelatesTo.setValue(some_relatesTo_ID);
soapAddressingHeaders.setRelatesTo(soapRelatesTo);

AttributedURIType soapMsgId = new AttributedURIType();
soapMsgId.setValue(some_messageID);
soapAddressingHeaders.setMessageID(soapMsgId);

如何通过该请求?我无法通过MessageContext设置它

1 个答案:

答案 0 :(得分:0)

将soapAddressingHeaders添加到MessageContext

messageContext.put("http://www.w3.org/2005/08/addressing", soapAddressingHeaders);

正常工作,但我忘了为CXF启用WS-A寻址:

<jaxws:features>
        <wsa:addressing xmlns:wsa="http://cxf.apache.org/ws/addressing"/>
</jaxws:features>