Issue
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
Solution
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
Answered By - adisorhoot
Answer Checked By - Mary Flores (JavaFixing Volunteer)