2016-12-12 119 views
1

我创建了一个Web服务客户端来处理带有apache骆驼的cxf soap web服务。使用Apache Camel拦截cxf Web服务标头(Java DSL)

String serviceUri = "cxf:http://localhost:10000/myservice?serviceClass=" + 
    MyRequest.class.getCanonicalName(); 

from(uri).to("mock:xyz"); 

Web服务接收SOAP调用,但因为请求需要WSS的操纵抛出异常。

org.apache.cxf.binding.soap.SoapFault: MustUnderstand headers: [{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood.

的原因是,该服务需要WS安全性,这可以通过在请求lloking看到。

<SOAP-ENV:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" SOAP-ENV:mustUnderstand="1"> 

我发现我需要实现一个拦截器来处理标题属性。

我的问题:

  • 我如何添加一个拦截器来处理标头骆驼Java的DSL属性?

  • 这是否足以摆脱SOAP错误?

回答

1

你可以做到这一点通过 cxfEndpointConfigurer选项@see:Camel-CXF configuration

(我使用Spring(这是很容易)),但我想对于DSL URI的样子:

String serviceUri = "cxf:http://localhost:10000/myservice?serviceClass=" + 
MyRequest.class.getCanonicalName() + 
"&cxfEndpointConfigurer="+ MyConfigurer.class.getCanonicalName(); 

通过实现org.apache.camel.component.cxf.CxfEndpointConfigurer你可以在configureServer方法内添加拦截器

server.getEndpoint().getInInterceptors().add(new MyJAASLoginInterceptor()); 

,如果你用JAAS(如JBoss)中运行你的骆驼集装箱可以从

org.apache.cxf.interceptor.security.JAASLoginInterceptor 

使用扩展与所需的回调处理程序。 ,其验证用户/从WSS头对JBOSS用户密码的简单示例:

public class MyJAASLoginInterceptor extends javax.security.auth.callback.JAASLoginInterceptor { 

    @Override 
    protected CallbackHandler getCallbackHandler(String name, String password) { 

    return new org.apache.cxf.interceptor.security.NamePasswordCallbackHandler(name, password, "setCredential"); 

    } 

} 
+0

不幸 “&cxfEndpointConfigurer =” + MyConfigurer.class.getCanonicalName();没有工作,我得到错误信息“无法找到一个合适的setter属性:cxfEndpointConfigurer,因为没有一个setter方法具有相同的类型:java.lang.String也没有可能的类型转换:” – ABX

+0

pls。阅读:http://camel.465427.n5.nabble.com/cxfEndpointConfigurer-in-an-URI-td5773083.html – Vadim