From b296545af82f0bd1e35e77dcdf897386d6bbcc5c Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 7 Jun 2019 16:40:58 -0400 Subject: [PATCH] Handler StreamingHttpOutputMessage in XHR transport Closes gh-23030 --- .../sockjs/client/RestTemplateXhrTransport.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java index d31abd4283..b8c7ff3620 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.http.StreamingHttpOutputMessage; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; import org.springframework.lang.Nullable; @@ -182,7 +183,13 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport { public void doWithRequest(ClientHttpRequest request) throws IOException { request.getHeaders().putAll(this.headers); if (this.body != null) { - StreamUtils.copy(this.body, SockJsFrame.CHARSET, request.getBody()); + if (request instanceof StreamingHttpOutputMessage) { + ((StreamingHttpOutputMessage) request).setBody(outputStream -> + StreamUtils.copy(this.body, SockJsFrame.CHARSET, outputStream)); + } + else { + StreamUtils.copy(this.body, SockJsFrame.CHARSET, request.getBody()); + } } } }