http://hi.baidu.com/sunshibing/blog/item/08f873f0d41e67c37931aa84.html
Java 要调用远程Https webservice 必需具用远程服务器提供的客户端信任书及密钥.
将client.keystore和client.truststore拷贝到classes\test目录下.
package test;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class TestEcVoteNotice
{
public static void main(String [] args) throws Exception {
System.setProperty("javax.net.ssl.keyStore", "test\\client.keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "abc");
System.setProperty("javax.net.ssl.trustStore", "test\\client.truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "abc");
//System.setProperty("javax.net.debug", "ssl");
//System.setProperty("https.protocols", "TLSv1");
//System.setProperty("java.protocol.handler.pkgs","javax.net.ssl");
String endpoint = "https://localhost:" +"8443"+ "/axis/services/EcVoteNotice";
//String endpoint = "http://localhost:" +"8080"+ "/axis/services/EcVoteNotice";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName("toStringP");
String res = (String) call.invoke( new Object[] {"Box"} );
call.setOperationName("toString");
String res2 = (String) call.invoke( new Object[] {} );
System.out.println( res+"/"+res2 );
}
}
在classes目录下执行.
java -cp %AXISCLASSPATH% test.TestEcVoteNotice
===========================================================
通过JAVA调用加密的webservice服务,需要进行如下配置。
1、在IE中访问WSDL的URL,弹出“安全警报”窗口,查看证书->详细信息标签页->复制到文件->下一步->下一步->指定文件名,将证书下载保存为.cer文件,例如:test.cer
2、用下载到的证书文件生成信任库文件:
在 keytool -import -file test.cer -storepass 111111 -keystore c:\client.truststore -alias aaa -noprompt
3、在调用WebService代码前指定信任库文件的路径:
System.setProperty("javax.net.ssl.trustStore", "/c:/client.truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "111111");
4、执行调用webservice的方法。