Cxf.Security.Wsse4j.Demo
Cxf生成web service加入安全性验证。(参见:http://cxf.apache.org/docs/ws-security.html)
官网代码没有完善,完整代码如下:(SRC)
package com.zte.eip.common.test;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
import com.zte.eip.common.gl.DemoSrv.DemoSrvOutputCollection;
import com.zte.eip.common.gl.DemoSrv.DemoSrvOutputItem;
import com.zte.eip.common.gl.DemoSrv.DemoSrvRequest;
import com.zte.eip.common.gl.DemoSrv.DemoSrvResponse;
import com.zte.eip.common.gl.InquiryDemoSrv.DemoSrv;
import com.zte.eip.common.gl.InquiryDemoSrv.DemoSrv_Service;
import com.zte.eip.common.wsse.ClientConstants;
import com.zte.eip.common.wsse.ClientPasswordHandler;
/**
* This class was generated by Apache CXF 2.1.3 Thu Sep 03 09:47:26 CST 2009
* Generated source version: 2.1.3
*
*/
/**
* @author
*
*/
public final class TestClient {
private static final QName SERVICE_NAME = new QName(
"http://eip.zte.com/common/gl/InquiryDemoSrv", "InquiryDemoSrv");
private TestClient() {
}
@SuppressWarnings("unchecked")
public static void main(String args[]) throws Exception {
URL wsdlURL = DemoSrv_Service.WSDL_LOCATION;
if (args.length > 0) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
DemoSrv_Service ss = new DemoSrv_Service(wsdlURL, SERVICE_NAME);
DemoSrv port = ss.getDemoSrvPort();
Client client = ClientProxy.getClient(port);
Endpoint cxfEndpoint = client.getEndpoint();
Map outProps = new HashMap();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, ClientConstants.USERNAME);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
DemoSrvRequest request = new DemoSrvRequest();
DemoSrvResponse response = port.process(request);
out(response);
}
public static void out(DemoSrvResponse response) {
DemoSrvOutputCollection collection = response.getDemoSrvOutputCollection();
List<DemoSrvOutputItem> items = collection.getDemoSrvOutputItem();
for (DemoSrvOutputItem item : items) {
System.out.println(item.getORGNAME());
}
}
}
分享到:
相关推荐
Springboot整合CXF发布Web service和客户端调用(用户和密码验证)打开及用
Apache CXF Web Service Development
Web Service学习-CXF开发Web Service实例demo(一)
CXF Spring Web Service 程序,希望对大家有用!!
Apache CXF Web Service Development 源码
Spring MVC、CXF、Web Service
使用CXF开发Web Service,包含服务器端和客户端
实战Web Service 之 CXF 实战Web Service 之 CXF
SpringBoot+mybatis+CXF开发web service接口,数据库用的是mysql,表结构在图片中,附上的还有自动生成的客户端代码
cxf生成客户端 服务端代码
apache-cxf-web-serviceapache-cxf-web-service
web service apache-cxf-2.4.1.rar 框架依赖包
cxf生成webservice客户端代码
电子书:Apache cxf web service development
早先用java做web service找的一个教程,排版清晰且详细,适合没开发过web servcie的新手。
系统地演示了Qt的大量特性,包括资源处理、多线程、调试支持、中文支持、参数传递、工具栏、状态栏、菜单、自定义信号和槽、居中窗口、操作友好性支持等,还集成了gSOAP,成功实现了同Java实现的CXF的Web Service的...