Apache Camel CXF在更新元素列表时调用RPC /编码的WSDL的困难

问题描述 投票:0回答:1

尽管没有得到正式的支持,但是对WSDL进行了一些小的修改,我就能够成功地为WSDL生成CXF对象,并使Camel CXF与RPC /编码的WSDL端点进行对话。该代码非常简单,大多数请求/响应都可以正常工作,除了尝试发送元素列表的更新。服务期望如下:

<elements arrayType="UpdateElement">

VS这是发送的内容:

<elements>

我需要将arrayType添加到外发消息中。我研究了多种方法:

1] CXF发送SOAP消息之前的拦截器,然后使用XPath添加元素,但是我不清楚如何使用Apache Camel + Camel CXF完成此操作。如何从骆驼上下文中检索CXF客户端?

MyService client = ???

2)通过WSDL修复吗?是否可以将此元素添加到WSDL,以便将其作为CXF对象的一部分生成?目前定义如下:

<message name="wsdlElementRequest"> <part name="elements" type="tns:UpdateElements" /></message>

“消息”和“部分”来自http://schemas.xmlsoap.org/wsdl/

任何想法或建议,将不胜感激。谢谢!

apache-camel wsdl cxf soap-client camel-cxf
1个回答
0
投票

[如果有人偶然发现类似问题,我自己弄清楚。我能够通过CamelContext检索CxfEndpoint:

camelContext.getEndpoint(endpointUrl, CxfEndpoint.class);

然后,我能够添加我创建的拦截器:

public class MyCxfInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
...

使用CxfEndpoint方法:

cxfEndpoint.getOutInterceptors().add(new MyCxfInterceptor());

在我的拦截器中,我还合并了另一个拦截器SAAJOutInterceptor,它将SOAP转换为易于使用的对象:

private List<PhaseInterceptor<? extends Message>> extras = new ArrayList<>(1);

public MyCxfInterceptor() {
    super(Phase.USER_PROTOCOL);
    extras.add(new SAAJOutInterceptor());
}

public Collection<PhaseInterceptor<? extends Message>> getAdditionalInterceptors() {
    return extras;
}

易于使用的SOAP消息:

@Override
public void handleMessage(SoapMessage soapMessage) throws Fault {
    SOAPMessage msg = soapMessage.getContent(SOAPMessage.class);

    try {
        SOAPBody soapBody = msg.getSOAPBody();

然后,使用XPATH对传出的SOAP消息进行更正很简单。

private XPath xpath = XPathFactory.newInstance().newXPath();
...
NodeList nodeList = soapBody.getElementsByTagName("tagName");
for (int x = 0; x < nodeList.getLength(); x++) {
    Node node = nodeList.item(x);
    ((Element) node).setAttribute("missingAttributeName", "missingAttributeValue");
}

我希望这对使用具有挑战性的SOAP服务的人有所帮助!

对在使我能够实施此解决方案中起很大作用的博客的信用:https://xceptionale.wordpress.com/2016/06/26/message-interceptor-to-modify-outbound-soap-request/

© www.soinside.com 2019 - 2024. All rights reserved.