@ -16,6 +16,11 @@
@@ -16,6 +16,11 @@
package org.springframework.web.socket.sockjs.client ;
import java.io.ByteArrayOutputStream ;
import java.io.IOException ;
import java.io.InputStream ;
import java.net.URI ;
import org.springframework.core.task.SimpleAsyncTaskExecutor ;
import org.springframework.core.task.TaskExecutor ;
import org.springframework.http.HttpHeaders ;
@ -38,11 +43,6 @@ import org.springframework.web.socket.WebSocketHandler;
@@ -38,11 +43,6 @@ import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession ;
import org.springframework.web.socket.sockjs.frame.SockJsFrame ;
import java.io.ByteArrayOutputStream ;
import java.io.IOException ;
import java.io.InputStream ;
import java.net.URI ;
/ * *
* An { @code XhrTransport } implementation that uses a
* { @link org . springframework . web . client . RestTemplate RestTemplate } .
@ -76,12 +76,9 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
@@ -76,12 +76,9 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
/ * *
* Configure the { @code TaskExecutor } to use to execute XHR receive requests .
*
* < p > By default { @link org . springframework . core . task . SimpleAsyncTaskExecutor
* SimpleAsyncTaskExecutor } is configured which creates a new thread every
* time the transports connects .
*
* @param taskExecutor the task executor , cannot be { @code null }
* /
public void setTaskExecutor ( TaskExecutor taskExecutor ) {
Assert . notNull ( this . taskExecutor ) ;
@ -147,6 +144,24 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
@@ -147,6 +144,24 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
}
/ * *
* A simple ResponseExtractor that reads the body into a String .
* /
private final static ResponseExtractor < ResponseEntity < String > > textExtractor =
new ResponseExtractor < ResponseEntity < String > > ( ) {
@Override
public ResponseEntity < String > extractData ( ClientHttpResponse response ) throws IOException {
if ( response . getBody ( ) = = null ) {
return new ResponseEntity < String > ( response . getHeaders ( ) , response . getStatusCode ( ) ) ;
}
else {
String body = StreamUtils . copyToString ( response . getBody ( ) , SockJsFrame . CHARSET ) ;
return new ResponseEntity < String > ( body , response . getHeaders ( ) , response . getStatusCode ( ) ) ;
}
}
} ;
/ * *
* A RequestCallback to add the headers and ( optionally ) String content .
* /
@ -156,7 +171,6 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
@@ -156,7 +171,6 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
private final String body ;
public XhrRequestCallback ( HttpHeaders headers ) {
this ( headers , null ) ;
}
@ -166,7 +180,6 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
@@ -166,7 +180,6 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
this . body = body ;
}
@Override
public void doWithRequest ( ClientHttpRequest request ) throws IOException {
if ( this . headers ! = null ) {
@ -178,23 +191,6 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
@@ -178,23 +191,6 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
}
}
/ * *
* A simple ResponseExtractor that reads the body into a String .
* /
private final static ResponseExtractor < ResponseEntity < String > > textExtractor =
new ResponseExtractor < ResponseEntity < String > > ( ) {
@Override
public ResponseEntity < String > extractData ( ClientHttpResponse response ) throws IOException {
if ( response . getBody ( ) = = null ) {
return new ResponseEntity < String > ( response . getHeaders ( ) , response . getStatusCode ( ) ) ;
}
else {
String body = StreamUtils . copyToString ( response . getBody ( ) , SockJsFrame . CHARSET ) ;
return new ResponseEntity < String > ( body , response . getHeaders ( ) , response . getStatusCode ( ) ) ;
}
}
} ;
/ * *
* Splits the body of an HTTP response into SockJS frames and delegates those
@ -204,12 +200,10 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
@@ -204,12 +200,10 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
private final XhrClientSockJsSession sockJsSession ;
public XhrReceiveExtractor ( XhrClientSockJsSession sockJsSession ) {
this . sockJsSession = sockJsSession ;
}
@Override
public Object extractData ( ClientHttpResponse response ) throws IOException {
if ( ! HttpStatus . OK . equals ( response . getStatusCode ( ) ) ) {
@ -262,4 +256,3 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
@@ -262,4 +256,3 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport implements Xh
}
}