spring-ws
spring-ws copied to clipboard
Not possible to stream attachments via WebServiceTemplate and WebServiceMessageSender
Using ClientHttpRequestMessageSender and setting 'setBufferRequestBody' to false:
HttpWebServiceMessageSenderBuilder httpWebServiceMessageSenderBuilder = new HttpWebServiceMessageSenderBuilder();HttpWebServiceMessageSenderBuilder httpWebServiceMessageSenderBuilder = new HttpWebServiceMessageSenderBuilder(); httpWebServiceMessageSenderBuilder.requestFactory(() -> { HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( configureHttpClient(HttpClients.custom(), endpointConfiguration, messageContextHolder)); httpComponentsClientHttpRequestFactory.setBufferRequestBody(false); return httpComponentsClientHttpRequestFactory; });
There is an exception thrown: UnsupportedOperationException("getBody not supported");Which is caused by ClientHttpRequestConnection#getRequestOutputStream calling: AbstractClientHttpRequest#getBody -> HttpComponentsStreamingClientHttpRequest#getBodyInternal
When using HttpComponentsMessageSender instead, it seems hardcoded to use an mem buffer for the actual attachment:
@Override protected void onSendAfterWrite(WebServiceMessage message) throws IOException { httpPost.setEntity(new ByteArrayEntity(requestBuffer.toByteArray()));