Java客户端调用Https Webservice(ZZ)

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的方法。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值