java代码配置证书地址及密码

package com.hellking.study.webservice;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
/**
 * 调用需要验证的Web服务
 */
public class AuthClient {
    static final double salary = 50000;
    public static void main(String[] args) {
        try {
            // 配置证书地址及密码
            String keystorePassword="123456",truststorePassword="123456";
            String keystoreFile = "D:/apache-tomcat-5.5.34/client.keystore";
            String truststoreFile = "D:/apache-tomcat-5.5.34/client.truststore";
            System.setProperty("javax.net.ssl.keyStore", keystoreFile);
            System.setProperty("javax.net.ssl.keyStorePassword",keystorePassword);
            System.setProperty("javax.net.ssl.trustStore", truststoreFile);
            System.setProperty("javax.net.ssl.trustStorePassword",truststorePassword); 
            
            // 服务端的url,需要根据情况更改。
            String endpointURL = "https://localhost:8443/axis/services/PersonalTaxService";// Web服务端点地址
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(new java.net.URL(endpointURL));
            call.setOperationName(new QName("PersonalTaxService", "getTax"));// 设置操作的名称。
            // 由于需要使用SSL认证,因此把用户名和密码注释掉了。
            //call.getMessageContext().setUsername("hellking");// 设置用户名。
            //call.getMessageContext().setPassword("simplewebservices");// 设置密码
            call.addParameter("op1", XMLType.XSD_DOUBLE, ParameterMode.IN);// 参数的类型
            call.setReturnType(XMLType.XSD_DOUBLE);// 返回的数据类型
            Double ret = (Double) call.invoke(new Object[] { new Double(salary) });// 执行调用
            System.out.println("使用HTTP协议来作为Web服务的传输协议!");
            System.out.println("已经成功调用。请参看服务端的输出!");
            System.out.println("输入工资" + salary + "元,应交个人所得税:" + ret);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

转载于:https://my.oschina.net/artong999/blog/357111

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值