使用Apache Camel拦截cxf Web服务标头(Java DSL)

时间:2016-12-12 15:48:08

标签: apache-camel cxf wss4j

我创建了一个Web服务客户端,用apache camel处理cxf soap web服务。

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">

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

我的问题:

  • 如何使用Camel Java-DSL添加拦截器来处理标头属性?

  • 这是否足以摆脱SOAP Fault?

1 个答案:

答案 0 :(得分: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)在容器中运行Camel,则可以使用

中的扩展名
org.apache.cxf.interceptor.security.JAASLoginInterceptor

需要回调处理程序。 从JBOSS用户验证WSS标头的用户/密码的简单示例:

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");

  }

}
相关问题