cmdbuild webservice接口相关的一些问题.

官方用的axis2是1.4.1版本,所以客户端最好也是1.4.1的版本.
因为版本迭代的速度比较快,所以官方的文档和实际代码有很大的区别甚至错误.
1.创建一个web项目,将axis2-1.4.1 和 rampart-1.4 中lib的包全部拷贝至项目的lib下.
2.在WEB-INF下创建modules文件夹,并将rampart-1.4 中modules的两个文件rahas-1.4和rampart-1.4拷贝至项目的modules中.
3.将http://localhost:8081/cmdbuild/services/soap/Webservices?wsdl 用axis2的 java2wsdl 生成客户端代码.
java2wsdl http://localhost:8081/cmdbuild/services/soap/Webservices?wsdl -uri

4.调用的代码
File file = new File("");
			String path = file.getAbsolutePath();

			ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
					path + "/WebContent/WEB-INF", null);

			WebservicesImplServiceStub stub = new WebservicesImplServiceStub(configContext, ENDPOINT);

			stub._getServiceClient().engageModule("rampart");

			Options options = stub._getServiceClient().getOptions();
			options.setUserName("admin");
			options.setPassword("admin");

			StAXOMBuilder builder = new StAXOMBuilder("C:/Users/liukai/Desktop/policy.xml");
			
			options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
					PolicyEngine.getPolicy(builder.getDocumentElement()));


5.policy.xml

<?xml version="1.0" encoding="UTF-8"?> 
<wsp:Policy wsu:Id="UTOverTransport" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> 
    <wsp:ExactlyOne> 
        <sp:SignedSupportingTokens xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
                <wsp:Policy> 
                    <sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"> 
                             <wsp:Policy> 
                                <sp:HashPassword/> 
                             </wsp:Policy> 
                    </sp:UsernameToken> 
               </wsp:Policy> 
        </sp:SignedSupportingTokens> 
    </wsp:ExactlyOne> 
</wsp:Policy>

你可能感兴趣的:(webservice)