17.13. 如何在 PAYLOAD 模式中获取和设置 SOAP 标头


我们已在 PAYLOAD 模式中以 CxfPayload 对象的形式显示如何以 CxfPayload 对象来访问 SOAP 消息,第 How to processing the message for a camel-cxf endpoint in PAYLOAD data format.

获取 CxfPayload 对象后,您可以调用返回 DOM Elements (SOAP 标头)列表的 CxfPayload.getHeaders ()方法。

例如,请参阅 CxfPayLoadSoapHeaderTest

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 Clipboard Toggle word wrap

您还可以使用与子章节" How to set SOAP header 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" 中删除它们。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat