将xml消息发送到Web服务时获取异常

时间:2014-10-28 21:30:42

标签: java ssl certificate ssl-certificate client-certificates

System.setProperty("javax.net.ssl.trustStore",ERPGetProperty.erpGetProperty("pathToKeyStore"));
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

SSLSocketFactory ssf = (SSLSocketFactory)SSLSocketFactory.getDefault();

URL url = new URL(address);
HttpsURLConnection con  = (HttpsURLConnection) url.openConnection();
con.setSSLSocketFactory(ssf);


con.setRequestMethod("POST");
con.setUseCaches(true);
con.setRequestProperty("Content-type", "text/xml");
con.setRequestProperty("Host", "pwspg.newcorp.com");
con.setRequestProperty("Content-Length", Integer.toString(xml.length()));
con.setRequestProperty("SOAPAction", address);
con.setDoOutput(true);
con.setDoInput(true);

userPass = username + ":" + password;
byte[] encodeBytes = Base64.encodeBase64(userPass.getBytes());
String encode = new String(encodeBytes);
con.setRequestProperty("Authorization", "Basic " + encode);

out = con.getOutputStream();

这是我用来连接到网络服务的代码,但是当我发送消息时我一直收到此异常

  

16:24:15,186 ERROR [stderr](DefaultQuartzScheduler_Worker-5)   java.net.ConnectException:操作超时16:24:15,187 ERROR   [stderr](DefaultQuartzScheduler_Worker-5)at   java.net.PlainSocketImpl.socketConnect(Native Method)16:24:15,187   ERROR [stderr](DefaultQuartzScheduler_Worker-5)at   java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)   16:24:15,188 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)   16:24:15,188 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)   16:24:15,189 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)   16:24:15,189 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   java.net.Socket.connect(Socket.java:579)16:24:15,190 ERROR [stderr]   (DefaultQuartzScheduler_Worker-5)at   sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)   16:24:15,197 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)   16:24:15,197 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.net.NetworkClient.doConnect(NetworkClient.java:180)16:24:15,198   ERROR [stderr](DefaultQuartzScheduler_Worker-5)at   sun.net.www.http.HttpClient.openServer(HttpClient.java:432)   16:24:15,198 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.net.www.http.HttpClient.openServer(HttpClient.java:527)   16:24:15,198 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.net.www.protocol.https.HttpsClient。(HttpsClient.java:275)   16:24:15,199 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:371)   16:24:15,199 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)   16:24:15,200 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at   sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)   16:24:15,202 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)   16:24:15,202 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1091)   16:24:15,203 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)   16:24:15,203 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   hot.com.mhd.erp.action.client.PushStatusClient.pushXML(PushStatusClient.java:483)   16:24:15,203 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   main.com.mhd.erp.sched.StatusPushJob.execute(StatusPushJob.java:73)   16:24:15,204 ERROR [stderr](DefaultQuartzScheduler_Worker-5)at at   org.quartz.core.JobRunShell.run(JobRunShell.java:202)16:24:15,204   ERROR [stderr](DefaultQuartzScheduler_Worker-5)at   org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:525)

带有Web服务的公司向我提供了4个证书,我已将其导入密钥库" JKS"类型。

请帮忙!抱歉第一次在stackoverflow中发帖

0 个答案:

没有答案