I have an application which sends a pdf file with JMF data to a Fiery (for printing) as a HttpPost request. When I used HttpClient 4, everything works fine. As soon as I migrate to HttpClient 5, sometimes (for small files), it works but it largely doesn't.
I migrated to HttpClient 5 because I upgraded Spring Boot to version 3 from 2.8. So maybe it isn't even a HttpClient problem but I can't find any other probable source of the error
On a wireshark I get this :
8271 20.705106793 192.168.3.23 192.168.65.35 TCP 76 [TCP Retransmission] 57714 → 8010 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=193348333 TSecr=0 WS=128
and sometimes a ZeroWindow which means the TCP buffer is full if I got that right. I tried to wait a long time but the request ends after a few minutes in a timeout and the tcp buffer stays full. As soon as I switch back on HttpClient4 (same Fiery, same Http URL), it works again.
I tried to check if the connection between my application and the Fiery is different in Wireshark but everything is the same. So I put the HttpClient in DEBUG and what I see is that the connection to the Fiery is established but, on HttpClient 5, only some part of the PDF file is sent as Base64, and then it breaks down. I am sure of this because when I send the same file in HttpClient4, the end of the stream sent on HttpClient 5 is :
17:24:47.938 [.springframework.jms.JmsListenerEndpointContainer#4-1] [] DEBUG [.apache.hc.client5.http.wire] - http-outgoing-1 >> "OdN3r/pOftY4Ud2f2SDCbWjaOePhoBX"
Whereas on HttpClient 4, it continues :
17:22:29.239 [.springframework.jms.JmsListenerEndpointContainer#4-1] [] DEBUG [.apache.http.wire] - http-outgoing-3 >> "bwICxW8RW/6+2QxzkWe+P5+ydfnV46XPub8vgC94gBAAAAACwJCDEUT1L4AhXD+ybPdgkK[\r][\n]"
17:22:29.239 [.springframework.jms.JmsListenerEndpointContainer#4-1] [] DEBUG [.apache.http.wire] - http-outgoing-3 >> "OdN3r/pOftY4Ud2f2SDCbWjaOePhoBXiNpS779cHmQbLdSx70+CrYzqrJHcqsn1364OTtpXncY6h[\r][\n]"
17:22:29.239 [.springframework.jms.JmsListenerEndpointContainer#4-1] [] DEBUG [.apache.http.wire] - http-outgoing-3 >> "HsXys2gDDSEGAAAAALAkIMRQPG1R9PomH/B2Y5obx/wuwZra/TnGOIHuz/5gRjaZvpMzrGy021Dm[\r][\n]"
17:22:29.239 [.springframework.jms.JmsListenerEndpointContainer#4-1] [] DEBUG [.apache.http.wire] - http-outgoing-3 >> "OmbbVq5jlf1eR6959Fl7hlnR3zy65jP1Vb1rkoQ3BUIMAAAAACBpQIihePqC3fDl8mB5lrCxdRfZ[\r][\n]"
17:22:29.239 [.springframework.jms.JmsListenerEndpointContainer#4-1] [] DEBUG [.apache.http.wire] - http-outgoing-3 >> "dlm6BIuh3Z95/2Ua55AtbOnGEcGMgWzDGl+fKmvdhgGvozoNvVlRPI6aozzvPX1tOlWeYVINawOd[\r][\n]"
17:22:29.239 [.springframework.jms.JmsListenerEndpointContainer#4-1] [] DEBUG [.apache.http.wire] - http-outgoing-3 >> "lJQVpCYCAAAAACQACDEUSxFiPFCxzPsmH/IVpSgNJRsoZ9vDK2O6+3Nf9AtzLnkiomacVzxWMZBt[\r][\n]"
I tried multiple implementations of HttpClient but nothing fixed this. I saw that maybe I need to send the file as chunks but as soon as the file has a length, HttpClient sends it without chunks.
HttpClient is built like this :
HttpClientBuilder builder = HttpClientBuilder
.create()
.setDefaultRequestConfig(
RequestConfig
.custom()
.setResponseTimeout(getTimeout("http.readTimeout", DEFAULT_READ_TIMEOUT))
.setConnectionRequestTimeout(
getTimeout("http.connectTimeout", DEFAULT_CONNECT_TIMEOUT)
)
.setConnectionKeepAlive(getTimeValue("http.keepAlive", DEFAULT_KEEP_ALIVE))
.build()
);
builder.setRetryStrategy(new DefaultHttpRequestRetryStrategy(3, RETRY_DELAY));
return new HttpTransport(builder.build())
And sent with :
private void postJmfFile(String jmfUrl, File mjmFile) throws IOException {
log.debug("Envoi du fichier MJM à l'URL : {}", jmfUrl);
try (HttpTransport httpTransport = httpTransportFactory.create()) {
httpTransport.postFile(jmfUrl, mjmFile, new UploadedFileHandler());
}
}
Inside UploadedFileHandler I have EntityUtils.consume(entity); which consumes the response
I don't understand why it does work sometimes/rarely but almost never on large files with HttpClient 5 but always on HttpClient 4.
I don't know if it is my way of sending the data that is wrong, I don't think I need to split the file (the large one is only 9mb).
Feel free to ask if you need more information about my code, I do not want to overload this post with too much unneeded information.