平安保险接口


import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class WebClientDevWrapper {

//CN=bis_front_stg, OU=SSL, DC=UM, DC=COM
private static final String PAIS_HTTPS_URI = "https://XXX.XXX.XXX.XXX:8007";
private static final String PAIS_JKS_TRUST = "EXV_BIS_IFRONT_PCIS_PTPTAOBAO_001_STG.jks";
private static final String TRUSTSTORE_PASSWORD = "XXXXXX";

public void wrapClient(String datafile) throws Exception {
System.setProperty("javax.net.ssl.trustStore", PAIS_JKS_TRUST);
System.setProperty("javax.net.ssl.trustStorePassword",TRUSTSTORE_PASSWORD);
HttpClient httpclient = new DefaultHttpClient();
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream trustStoreInstream = new FileInputStream(PAIS_JKS_TRUST);
try {
trustStore.load(trustStoreInstream, TRUSTSTORE_PASSWORD.toCharArray());
} finally {
if(trustStoreInstream != null)
trustStoreInstream.close();
}
SSLSocketFactory socketFactory = new SSLSocketFactory(new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
return true;
}
});
Scheme sch = new Scheme("https", 8007, socketFactory);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
HttpPost post = new HttpPost(PAIS_HTTPS_URI);
String BK_SERIAL = String.valueOf(System.currentTimeMillis());
System.out.println("BK_SERIAL:" + BK_SERIAL);
String bodyText = "请求正文,xml格式";
System.out.println(bodyText);
StringEntity entity = new StringEntity(bodyText, "text/html", "GBK");
post.setEntity(entity);
HttpResponse res = httpclient.execute(post);
HttpEntity resEntity = res.getEntity();
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
httpclient.getConnectionManager().shutdown();
}

public static void main(String[] args) throws Exception {
WebClientDevWrapper webClientDevWrapper = new WebClientDevWrapper();
webClientDevWrapper.wrapClient("D:/威斯达/cers/test/erhe.txt");
}

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值