本文介绍了将 ws-security 添加到 wsdl2java 生成的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 CXF 的 wsdl2java 从 WSDL 生成了一堆客户端类.执行以下操作时如何将 WS-Security 添加到标头:

I generated a bunch of client classes from a WSDL with CXF's wsdl2java. How do I add WS-Security to the header when doing something like this:

URL url = new URL("http://fqdn:8080/service/MessageHandler");
MessageHandlerService service = new MessageHandlerService(url);
MessageHandler handler = service.getMessageHandler();
MyMessage message = new MyMessage();
message.setSender("User 1");
handler.sendMessage(message);

我认为 handler 是一个 javax.xml.ws.Service 实例.

I think handler is a javax.xml.ws.Service instance.

推荐答案

<jaxws:client id="client"
    serviceClass="com.mycompany.TheServiceInterface"
    address="http://fqdn/service/Endpoint?wsdl">
    <jaxws:outInterceptors>
        <bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
            <constructor-arg>
                <map>
                    <entry key="action" value="Timestamp UsernameToken"/>
                    <entry key="user" value="test.user"/>
                    <entry key="passwordType" value="PasswordNone"/>
                </map>
            </constructor-arg>
        </bean>
    </jaxws:outInterceptors>
</jaxws:client>

然后,如果您将客户端强制转换为 BindingProvider,您可以根据需要以编程方式更改端点.

Then if you cast the client to a BindingProvider you can change the endpoint as needed programatically.

这篇关于将 ws-security 添加到 wsdl2java 生成的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 23:32