Java 11上的SSL协议异常

Java 11上的SSL协议异常,java,spring-boot,ssl-certificate,tls1.2,Java,Spring Boot,Ssl Certificate,Tls1.2,我最近将我的springboot应用程序从springboot 1,Java 8迁移到springboot 2,Java 11。到目前为止,这项技术在8号上运行良好。 这个springboot应用程序是一个cron作业,每天运行并处理数千条记录。 对于每条记录,此应用程序调用另一个应用程序来检索一些响应(两个应用程序都在Java11上运行) 奇怪的是,我只是在处理很少的记录(比如说100秒)时才得到这个异常,rest工作正常 以下是异常堆栈跟踪: javax.net.ssl.SSLProtoco

我最近将我的springboot应用程序从springboot 1,Java 8迁移到springboot 2,Java 11。到目前为止,这项技术在8号上运行良好。 这个springboot应用程序是一个cron作业,每天运行并处理数千条记录。 对于每条记录,此应用程序调用另一个应用程序来检索一些响应(两个应用程序都在Java11上运行)

奇怪的是,我只是在处理很少的记录(比如说100秒)时才得到这个异常,rest工作正常

以下是异常堆栈跟踪:

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.java:321)
         at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
         at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:259)
         at java.base/sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1314)
         at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:839)
         at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
         at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
         at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
         at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
         at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
         at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
         at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
         at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153)
         at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
         at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
         at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
         at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
         at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
         at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
         at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
         at com.win.billpayalerts.service.EcmService.getEcmInfoWithRetryCount(EcmService.java:171)
         at com.win.billpayalerts.service.EcmService.getEcmAccountInfoByEcmContactId(EcmService.java:91)
         at com.win.billpayalerts.service.EcmService.getEcmAccountInfoByEcmContactId(EcmService.java:362)
         at com.win.billpayalerts.service.AlertService.getEcmInfoForCustomer(AlertService.java:233)
         at com.win.billpayalerts.service.InvoiceAlertProcessor.processInvoice(InvoiceAlertProcessor.java:48)
         at com.win.billpayalerts.service.AlertProcessor.invokeNotificationAlert(AlertProcessor.java:70)
         at com.win.billpayalerts.service.AlertProcessor.run(AlertProcessor.java:44)
         at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:779)
         at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:763)
         at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213)
         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202)
         at com.win.billpayalerts.BillpayAlertsApplication.main(BillpayAlertsApplication.java:10)
         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
         at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)
         at org.springframework.boot.loader.Launcher.launch(Launcher.java:86)
         at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
         at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
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(SSLSocketInputRecord.java:448)
         at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:68)
         at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1104)
         at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:823)
         ... 39 common frames omitted
这是源应用程序的gradle文件:

plugins {
  id 'org.springframework.boot' version '2.1.6.RELEASE'
  id 'java'
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'jdepend'

sourceCompatibility = 1.11
targetCompatibility = 1.11


bootJar {
  archiveBaseName = 'alerts'
}


repositories {
  mavenCentral()
}

dependencies {
  compile('org.springframework.boot:spring-boot-starter-data-jpa')
  compile('org.springframework.boot:spring-boot-starter-jdbc') {
    exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
  }
  compile('org.springframework.boot:spring-boot-starter-web')
  compile('org.springframework.boot:spring-boot-starter-mail')

  compile("org.apache.axis:axis:1.4")
  compile('org.apache.commons:commons-lang3:3.5')
  compile('org.apache.httpcomponents:httpclient:4.3.4')
  compile('org.apache.pdfbox:pdfbox:2.0.1')

  compile("net.sf.ehcache:ehcache:2.10.3")

  compile("commons-discovery:commons-discovery:0.5")
  compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.4")

  compile('ch.qos.logback:logback-core:1.1.8')
  compile('ch.qos.logback:logback-classic:1.1.8')
  compile("wsdl4j:wsdl4j:1.6.2")


  runtime('com.microsoft:sqljdbc4:4.0')

  testRuntime('com.h2database:h2')
  testCompile('org.springframework.boot:spring-boot-starter-test')
  testCompile group: 'junit', name: 'junit', version: '4.4'
}
 plugins {
   id 'org.springframework.boot' version '2.1.6.RELEASE'
   id 'java'
 }

 apply plugin: 'io.spring.dependency-management'
 apply plugin: 'java'
 apply plugin: 'eclipse'
 apply plugin: 'org.springframework.boot'
 apply plugin: 'jacoco'
 apply plugin: 'checkstyle'
 apply plugin: 'jdepend'

 sourceCompatibility = 1.11

 bootJar {
   baseName = 'accounts'
 } 


 repositories {
   mavenCentral()
 }

 dependencies {
   implementation('org.springframework.boot:spring-boot-starter')
   compile('org.springframework.boot:spring-boot-starter-actuator')
   compile('org.springframework.boot:spring-boot-starter-cache')
   compile('org.springframework.boot:spring-boot-starter-web')
   compile('org.springframework.boot:spring-boot-starter-mail')
   compile("io.springfox:springfox-swagger2:2.7.0")
   compile("io.springfox:springfox-swagger-ui:2.7.0")

   compile('org.springframework.boot:spring-boot-starter-jdbc') {
      exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
   }

   compile('org.apache.commons:commons-lang3:3.5')
   compile('org.springframework.boot:spring-boot-starter-data-jpa')
   compile('org.apache.commons:commons-collections4:4.0')
   compile group: 'net.sf.jt400', name: 'jt400-jdk8', version: '9.5'
   compile('org.apache.httpcomponents:httpclient:4.3.4')
   compile('log4j:log4j:1.2.17')
   compile('org.projectlombok:lombok')
   runtime('com.microsoft:sqljdbc4:4.0')

   testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
   testCompile group: 'junit', name: 'junit'
 }
这是另一个应用程序的gradle文件:

plugins {
  id 'org.springframework.boot' version '2.1.6.RELEASE'
  id 'java'
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'jdepend'

sourceCompatibility = 1.11
targetCompatibility = 1.11


bootJar {
  archiveBaseName = 'alerts'
}


repositories {
  mavenCentral()
}

dependencies {
  compile('org.springframework.boot:spring-boot-starter-data-jpa')
  compile('org.springframework.boot:spring-boot-starter-jdbc') {
    exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
  }
  compile('org.springframework.boot:spring-boot-starter-web')
  compile('org.springframework.boot:spring-boot-starter-mail')

  compile("org.apache.axis:axis:1.4")
  compile('org.apache.commons:commons-lang3:3.5')
  compile('org.apache.httpcomponents:httpclient:4.3.4')
  compile('org.apache.pdfbox:pdfbox:2.0.1')

  compile("net.sf.ehcache:ehcache:2.10.3")

  compile("commons-discovery:commons-discovery:0.5")
  compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.4")

  compile('ch.qos.logback:logback-core:1.1.8')
  compile('ch.qos.logback:logback-classic:1.1.8')
  compile("wsdl4j:wsdl4j:1.6.2")


  runtime('com.microsoft:sqljdbc4:4.0')

  testRuntime('com.h2database:h2')
  testCompile('org.springframework.boot:spring-boot-starter-test')
  testCompile group: 'junit', name: 'junit', version: '4.4'
}
 plugins {
   id 'org.springframework.boot' version '2.1.6.RELEASE'
   id 'java'
 }

 apply plugin: 'io.spring.dependency-management'
 apply plugin: 'java'
 apply plugin: 'eclipse'
 apply plugin: 'org.springframework.boot'
 apply plugin: 'jacoco'
 apply plugin: 'checkstyle'
 apply plugin: 'jdepend'

 sourceCompatibility = 1.11

 bootJar {
   baseName = 'accounts'
 } 


 repositories {
   mavenCentral()
 }

 dependencies {
   implementation('org.springframework.boot:spring-boot-starter')
   compile('org.springframework.boot:spring-boot-starter-actuator')
   compile('org.springframework.boot:spring-boot-starter-cache')
   compile('org.springframework.boot:spring-boot-starter-web')
   compile('org.springframework.boot:spring-boot-starter-mail')
   compile("io.springfox:springfox-swagger2:2.7.0")
   compile("io.springfox:springfox-swagger-ui:2.7.0")

   compile('org.springframework.boot:spring-boot-starter-jdbc') {
      exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
   }

   compile('org.apache.commons:commons-lang3:3.5')
   compile('org.springframework.boot:spring-boot-starter-data-jpa')
   compile('org.apache.commons:commons-collections4:4.0')
   compile group: 'net.sf.jt400', name: 'jt400-jdk8', version: '9.5'
   compile('org.apache.httpcomponents:httpclient:4.3.4')
   compile('log4j:log4j:1.2.17')
   compile('org.projectlombok:lombok')
   runtime('com.microsoft:sqljdbc4:4.0')

   testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
   testCompile group: 'junit', name: 'junit'
 }
我尝试通过JVM参数禁用TLSv1.3,但没有成功:

-Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"

我如何解决这个问题?提前谢谢。

这不是一个真正的答案,更多的是一种怀疑,而且评论时间太长:

由于您得到的是
连接重置
,而不是对等方的
连接重置
,因此我怀疑重置是由java应用程序本身或其运行的服务器完成的。我查看了
SocketInputStream.read的源代码。它是基于超时值读取的:

try {
    n = socketRead(fd, b, off, length, timeout);
    if (n > 0) {
        return n;
    }
} catch (ConnectionResetException rstExc) {
    impl.setConnectionReset();
} finally {
    impl.releaseFD();
}
我的猜测是,
ConnectionResetException
是由于服务器的重置而引发的,这也设置了超时值(在连接上,而不是在读取上)


我不知道你是否有成功记录和失败记录的日志,但是如果你有,也许你可以检查时间戳,看看我的怀疑是否正确。

很可能服务器不喜欢你的客户端证书。你的新java 11安装程序和你的旧安装程序在同一台服务器上运行吗?@Scratte:No,它在不同的地方server@user207421:A在某种程度上同意,但我在处理rest工作之间的少数记录时遇到此异常。感谢您的提示,我看到引发连接重置异常的呼叫的响应时间为~4秒,而连续记录的其余部分仅花费~1秒。不过,我没有看到任何504错误。如果您可以在同一台服务器上运行Java 8版本的应用程序,并且出现相同的错误,那么这一定是服务器上的配置问题。如果你不能做到这一点,也许可以检查两台服务器上协议的配置。我也会尝试一下,谢谢你的时间,谢谢。