Skip to content

Not possible to stream attachments via WebServiceTemplate and WebServiceMessageSender #1211

@koen-serneels

Description

@koen-serneels

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()));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions