客户端axis2调用cxf服务端过验证

小强119 2013-08-20 09:46:36
因为jar版本冲突,两边都不能换jar包,所以只能用axis2来实现,下面的是对方给我们的客户端范例,试过用他们提供的jar是能连上,求axis2的范例代码.
	public static void main(String[] args) {  
// 以下和服务端配置类似,不对,应该说服务端和这里的安全验证配置一致
Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION,
WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, "zxfw");
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
// 指定在调用远程ws之前触发的回调函数WsClinetAuthHandler,其实类似于一个拦截器
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,
WsClinetAuthHandler.class.getName());
ArrayList list = new ArrayList();
// 添加cxf安全验证拦截器,必须
list.add(new SAAJOutInterceptor());
list.add(new WSS4JOutInterceptor(outProps));

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// WebServiceSample服务端接口实现类,这里并不是直接把服务端的类copy过来,具体请参考http://learning.iteye.com/blog/1333223
factory.setServiceClass(IZxfwWebService.class);
// 设置ws访问地址 ,隐秘下吧,要不这接口就完全曝光了
factory.setAddress("http://183.xx.xxx.xxx:xxxx/xxxxxxxxx/xxxxx/ZxfwWebService");
//注入拦截器,用于加密安全验证信息
factory.getOutInterceptors().addAll(list);
IZxfwWebService service = (IZxfwWebService) factory.create();
String response;
File file = new File("C:/Users/Administrator/Desktop/测试咨询第三方接口数据.txt");
try {
FileInputStream in = new FileInputStream(file);
InputStreamReader reader = null;
StringBuffer sb = new StringBuffer();
reader = new InputStreamReader (new FileInputStream(file),"GBK");
BufferedReader bufReader = new BufferedReader(reader);
String tempString = null;
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = bufReader.readLine()) != null) {
sb.append(tempString);
// 显示行号
System.out.println("line " + line + ": " + tempString);
line++;
}
reader.close();
response = service.requestZxfw(sb.toString());
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
}
}

@WebService(targetNamespace = "http://com.foresee.portal.zyywService.zxfw.service.impl/ZxfwService")
public interface IZxfwWebService {

/**
* @param requestxml
* @return
*/
public @WebResult(name = "requestxml")
String requestZxfw(@WebParam(name = "requestxml") String requestxml)
throws Exception;

/**
* @param requestxml
* @return
*/
public @WebResult(name = "requestxml2")
String testPush(@WebParam(name = "requestxml2") String requestxml)
throws Exception;

}

public class WsClinetAuthHandler implements CallbackHandler {  

public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
System.out.println("identifier: " + pc.getIdentifier());
pc.setPassword("foresee-zxfw-service");
}
}
}
...全文
277 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧