from(getRouterEndpointURI()).process(new Processor() {
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);
List<Source> elements = payload.getBodySources();
assertNotNull(elements, "We should get the elements here");
assertEquals(1, elements.size(), "Get the wrong elements size");
Element el = new XmlConverter().toDOMElement(elements.get(0));
elements.set(0, new DOMSource(el));
assertEquals("http://camel.apache.org/pizza/types",
el.getNamespaceURI(), "Get the wrong namespace URI");
List<SoapHeader> headers = payload.getHeaders();
assertNotNull(headers, "We should get the headers here");
assertEquals(1, headers.size(), "Get the wrong headers size");
assertEquals("http://camel.apache.org/pizza/types",
((Element) (headers.get(0).getObject())).getNamespaceURI(), "Get the wrong namespace URI");
// alternatively you can also get the SOAP header via the camel header:
headers = exchange.getIn().getHeader(Header.HEADER_LIST, List.class);
assertNotNull(headers, "We should get the headers here");
assertEquals(1, headers.size(), "Get the wrong headers size");
assertEquals("http://camel.apache.org/pizza/types",
((Element) (headers.get(0).getObject())).getNamespaceURI(), "Get the wrong namespace URI");
}
})
.to(getServiceEndpointURI());
from(getRouterEndpointURI()).process(new Processor() {
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);
List<Source> elements = payload.getBodySources();
assertNotNull(elements, "We should get the elements here");
assertEquals(1, elements.size(), "Get the wrong elements size");
Element el = new XmlConverter().toDOMElement(elements.get(0));
elements.set(0, new DOMSource(el));
assertEquals("http://camel.apache.org/pizza/types",
el.getNamespaceURI(), "Get the wrong namespace URI");
List<SoapHeader> headers = payload.getHeaders();
assertNotNull(headers, "We should get the headers here");
assertEquals(1, headers.size(), "Get the wrong headers size");
assertEquals("http://camel.apache.org/pizza/types",
((Element) (headers.get(0).getObject())).getNamespaceURI(), "Get the wrong namespace URI");
// alternatively you can also get the SOAP header via the camel header:
headers = exchange.getIn().getHeader(Header.HEADER_LIST, List.class);
assertNotNull(headers, "We should get the headers here");
assertEquals(1, headers.size(), "Get the wrong headers size");
assertEquals("http://camel.apache.org/pizza/types",
((Element) (headers.get(0).getObject())).getNamespaceURI(), "Get the wrong namespace URI");
}
})
.to(getServiceEndpointURI());
Copy to ClipboardCopied!Toggle word wrapToggle overflow
您还可以使用与子选择 " How to get and set SOAP headers in POJO 模式"中所述的方法一样设置或获取 SOAP 标头。因此,您可以使用标头 "org.apache.cxf.headers.Header.list" 来获取和设置 SOAP 标头列表。这也意味着,如果您有一个从一个 Camel-cxf 端点转发到另一个 Camel-cxf 端点的路由(SOAP Client Camel CXF 服务),现在也会将 SOAP 客户端发送的 SOAP 标头转发到 CXF 服务。如果您不想转发这些标头,则必须在 Camel 标头 "org.apache.cxf.headers.Header.list" 中删除它们。