`
jrails
  • 浏览: 98551 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

平安保险接口

 
阅读更多
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");
	}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics