2

I am using OAuth2RestTemplate with JDK11 to make a POST request with Json data (860 lines and 26 KB). Strangely the code works fine with < 700 Json lines (or 20 KB) on production server and with < 500 lines (15 KB) on local machine. But as soon I increase few more data blocks in the JSON it start giving exception. Exception is based on the HttpRequestFactory implementation used with RestTemplate. In case I use HttpComponentsClientHttpRequestFactory then it is NoHttpResponseException XXX.XXX:443 failed to respond and if I use SimpleClientHttpRequestFactory then java.net.SocketException Unexpected end of file from server

restTemplate.postForEntity(Url, dataBytes, byte[].class);

Strangely this works with lower versions of JDK 8, 9 and 10. Also I have tried other Http client like Spring Webclient with JDK11 and same data works with it. Apart from that same data also works with Curl/Postman. But not able to identify why it is creating issue with RestTemplate beyond certain data limit.

Below are some of the main dependencies I am using (Dependency wise can't change much in existing project).

Spring-core 5.1.6.RELEASE
org.apache.httpcomponents.httpclient 4.5.6
spring-security-core 5.1.4.RELEASE
spring-security-oauth2-client 5.1.4.RELEASE
JDK11

Any help or idea will be much appreciated. TIA

Jogger
  • 397
  • 5
  • 15
  • Please check https://stackoverflow.com/questions/10558791/apache-httpclient-interim-error-nohttpresponseexception – jcamsler Nov 06 '20 at 15:55
  • @jcamsler Thanks for coming up with suggestion. I checked this link, seems it is related to some stale connection issue with HTTPClient 4.4 and I am using 4.5.6. My one seems Resttemplate/Httpclient compatibility issue with Java 11.0.2 till 11.0.4. After that it appears to be fixed. Looking for any workaround meanwhile else would left with no choice to upgrade – Jogger Nov 08 '20 at 08:15

1 Answers1

2

I have had the same issue with the following JDK11 versions:

IMPLEMENTOR="AdoptOpenJDK" IMPLEMENTOR_VERSION="AdoptOpenJDK" JAVA_VERSION="11.0.2"

IMPLEMENTOR="AdoptOpenJDK" IMPLEMENTOR_VERSION="AdoptOpenJDK" JAVA_VERSION="11.0.4"

but the issue no longer appears in 11.0.9.11. I have not yet found what the fix was

adisorhoot
  • 86
  • 2
  • Thanks for replying. Yes this is working with 11.0.9. Seems Java has broken something in their earlier Java 11 minor release version. Though it would be hard for us to upgrade jars at this point. Meanwhile It will be helpful if there is some workaround for this. – Jogger Nov 07 '20 at 14:52
  • 1
    It is working with JDK 11.0.5 onwards. Seems Java fixed this issue with the security patch update of 11.0.5 – Jogger Nov 08 '20 at 08:17
  • 1
    Thanks for the info, will look into what the fix was, maybe can find a solution – adisorhoot Nov 08 '20 at 18:10
  • We are going with the upgrade but it would be interesting to know the change Java did. So that we are aware there is no plan to revert it again. – Jogger Nov 09 '20 at 04:22
  • I think it's this fix: https://bugs.openjdk.java.net/browse/JDK-8216326. The close method was not called on a socket, when closing the associated outputStream, so it was reused for subsequent calls and hence the error – adisorhoot Nov 09 '20 at 12:39