gpt4 book ai didi

java - 连接到需要证书的 Web 服务时出错

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:03 24 4
gpt4 key购买 nike

我正在尝试连接到一家公司的 Web 服务,该公司为我提供了 4 个 .cert 格式的证书,我已将这些证书放入 keystore 中,并在我的客户端代码上建立了 Https 连接

    System.setProperty("javax.net.ssl.trustStore",ERPGetProperty.erpGetProperty("pathToKeyStore"));
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStore", ERPGetProperty.erpGetProperty("pathToKeyStore"));
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("https.protocols", "TLSv1.2");

SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();

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

con.setSSLSocketFactory(sslSocketFactory);
con.setRequestMethod("POST");
con.setUseCaches(true);
con.setRequestProperty("Content-type", "text/xml");
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();

out.write(b);

我总是遇到这个异常

 10:21:15,591 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) java.net.ConnectException:  Operation timed out

10:21:15,591 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at java.net.PlainSocketImpl.socketConnect(Native Method)
10:21:15,591 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
10:21:15,592 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
10:21:15,592 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
10:21:15,593 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
10:21:15,593 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at java.net.Socket.connect(Socket.java:579)
10:21:15,593 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
10:21:15,594 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)
10:21:15,594 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
10:21:15,594 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
10:21:15,595 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
10:21:15,595 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:275)
10:21:15,595 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:371)
10:21:15,596 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
10:21:15,596 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
10:21:15,596 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
10:21:15,597 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1091)
10:21:15,597 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
10:21:15,598 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at hot.com.mhd.erp.action.client.PushStatusClient.pushXML(PushStatusClient.java:492)
10:21:15,598 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at main.com.mhd.erp.sched.StatusPushJob.execute(StatusPushJob.java:73)
10:21:15,598 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
10:21:15,599 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)

这是我在抛出异常之前从 Debug模式中得到的一些结果

10:21:00,034 INFO  [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
10:21:00,034 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA
10:21:00,035 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
10:21:00,035 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
10:21:00,036 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
10:21:00,036 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
10:21:00,036 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
10:21:00,036 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
10:21:00,037 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
10:21:00,037 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
10:21:00,037 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256
10:21:00,037 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
10:21:00,038 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
10:21:00,038 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
10:21:00,038 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA
10:21:00,038 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
10:21:00,039 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
10:21:00,039 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
10:21:00,039 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
10:21:00,039 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA
10:21:00,040 INFO [stdout] (DefaultQuartzScheduler_Worker-4) Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256

请帮帮我!我没时间解决这个问题了!谢谢!

最佳答案

  10:21:15,591 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) java.net.ConnectException:  Operation timed out
10:21:15,591 ERROR [stderr] (DefaultQuartzScheduler_Worker-2) at java.net.PlainSocketImpl.socketConnect(Native Method)

您已经在普通套接字级别获得连接超时。请确保服务器已启动并为来自外部的连接打开,并且您的应用程序和服务器之间没有防火墙阻止访问。尝试使用另一个客户端连接到服务器,以确保问题出在您的应用程序上。

关于java - 连接到需要证书的 Web 服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26634458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com