Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient()
client.addOutHandler(new DOMOutHandler())
Properties config = new Properties()
// Action to perform : user token
config.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN)
// Password type : plain text
config.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT)
// for hashed password use:
//properties.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST)
// User name to send
config.setProperty(WSHandlerConstants.USER, "serveralias")
// Callback used to retrive password for given user.
config.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordHandler.class.getName())
client.addOutHandler(new WSS4JOutHandler(properties))
service.doSomething(...)
-------------------------------------------------------------------------------------------------
public class PasswordHandler implements CallbackHandler {
private Map passwords = new HashMap()
public PasswordHandler() {
passwords.put("serveralias", "aliaspass")
passwords.put("client-344-839","client344Password")
}
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]
String id = pc.getIdentifer()
pc.setPassword((String) passwords.get(id))
}
}
--------------------------------------------
要用到 wss4j 和 bcprov ,如果仅仅是令牌验证的话,可以不用 bcprov,如果做签名和消息级加密的话,就必须要用到 bcprov 或是其他的安全包了
CXF内置了很多拦截器,大部分默认添加到拦截器链中,有些拦截器也可以手动添加,如CXF的日志拦截器。如果需要自定义拦截器,只要继承AbstractPhaseInterceptor或者AbstractPhaseInterceptor的子类(如AbstractSoapInterceptor)
如果是传统的spring+cxf 项目,拦截器的写法是一样的,只是发布和配置的方法在cxf的配置文件的xml中进行
WSDL 地址: http://localhost:8080/SpringBootDemo_eclipse/soap/ihelloService?wsdl
CXF 自动编译解析的客户端
客户端basic 认证调用
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)