万一有人偶然发现类似问题,我自己弄清楚了。我能够通过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/
本文链接:https://www.f2er.com/2917293.html