Skip to content

JdkClientHttpRequestFactory not compatible with BufferingClientHttpRequestFactory in 6.1 M3 #31027

Closed as not planned
@alexcrownus

Description

@alexcrownus

In Spring Framework 6.1 M3, using BufferingClientHttpRequestFactory with JdkClientHttpRequestFactory throws an exception

java.lang.IllegalArgumentException: non-positive contentLength: 0.

The issue seems to be from class BufferingClientHttpResponseWrapper, method

    @Override
    public InputStream getBody() throws IOException {
        if (this.body == null) {
            this.body = StreamUtils.copyToByteArray(this.response.getBody()) 
        }
        return new ByteArrayInputStream(this.body);
    }

Since BufferingClientHttpResponseWrapper is not public, I copied the class and was able to fix the issue with

    @Override
    public InputStream getBody() throws IOException {
        if (this.body == null) {
            this.body = StreamUtils.copyToByteArray((this.response.getBody() != null) ? this.response.getBody() : new ByteArrayInputStream(new byte[0]));
        }
        return new ByteArrayInputStream(this.body);
    }

Not sure if this is a good fix but it works.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions