Java 中的 HttpMethodDirectory executeWithRetry 和 SSLProtocolException

HttpMethodDirectory executeWithRetry and SSLProtocolException in Java

我正在使用 httpclient-3.0 库将数据解析到云端。当我 运行 本地机器上的应用程序 (Windows 10) 时,它工作正常并且数据被解析到服务器并且我收到成功响应,但是当我将它部署到我们的服务器时 运行s 在 Windows 服务器 2012 R2 上,抛出以下错误。我也使用了相同的 JDK 我尝试了很多方法,比如在我的 java.security jdk 文件中添加 -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2",但问题仍然没有已解决。

这是我的代码

PostMethod post = new PostMethod(apiUrl);
post.setParameter("authtoken", authToken);
post.setParameter("dateFormat", dateTimeFormat);
post.setParameter("data", emloyeesAttendanceJsonArr.toString());
HttpClient httpclient = new HttpClient();
// Configuring proxy
httpclient.getHostConfiguration().setProxy("**.**.**.**", ****);
try {
    long timeTrace = System.currentTimeMillis();
    int result = httpclient.executeMethod(post);
    System.out.println(">> HTTP Response status code: "+result);
    System.out.println(">> Response Time: "+(System.currentTimeMillis() - timeTrace));
.......
.......
.......
}

感谢任何快速帮助和指南。

这是我得到的错误

Mar 11, 2020 4:23:08 PM org.apache.commons.httpclient.HttpMethodDirector execute
WithRetry
INFO: I/O exception (javax.net.ssl.SSLProtocolException) caught when processing
request: Connection reset
Mar 11, 2020 4:23:08 PM org.apache.commons.httpclient.HttpMethodDirector execute
WithRetry
INFO: Retrying request
Mar 11, 2020 4:23:23 PM org.apache.commons.httpclient.HttpMethodDirector execute
WithRetry
INFO: I/O exception (javax.net.ssl.SSLProtocolException) caught when processing
request: Connection reset
Mar 11, 2020 4:23:23 PM org.apache.commons.httpclient.HttpMethodDirector execute
WithRetry
INFO: Retrying request
Mar 11, 2020 4:23:38 PM org.apache.commons.httpclient.HttpMethodDirector execute
WithRetry
INFO: I/O exception (javax.net.ssl.SSLProtocolException) caught when processing
request: Connection reset
Mar 11, 2020 4:23:38 PM org.apache.commons.httpclient.HttpMethodDirector execute
WithRetry
INFO: Retrying request
javax.net.ssl.SSLProtocolException: Connection reset
        at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:126)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.ja
va:321)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.ja
va:264)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.ja
va:259)
        at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:137)

        at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:11
52)
        at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocke
tImpl.java:1063)
        at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl
.java:402)
        at java.base/sun.security.ssl.SSLSocketImpl.ensureNegotiated(SSLSocketIm
pl.java:716)
        at java.base/sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSoc
ketImpl.java:970)
        at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStre
am.java:81)
        at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.jav
a:142)
        at java.base/java.io.FilterOutputStream.flush(FilterOutputStream.java:15
3)
        at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequ
estBody(EntityEnclosingMethod.java:502)
        at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodB
ase.java:1973)
        at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.j
ava:993)
        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Htt
pMethodDirector.java:397)
        at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMe
thodDirector.java:170)
        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
a:396)
        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
a:324)
        at af.aib.etl.AttendanceETL.fetchAndParseAttendanceRecord(AttendanceETL.
java:99)
        at af.aib.attendance.ApplicationStartPoint.main(ApplicationStartPoint.ja
va:28)
Caused by: java.net.SocketException: Connection reset
        at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)

        at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)

        at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRe
cord.java:448)
        at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInput
Record.java:165)
        at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:108)

本地代理和服务器代理不同,这就是为什么 运行 在我的本地机器上正常但在服务器上不行,一旦我将代理更改为服务器正在使用的特定代理,然后应用程序运行良好。