use of org.springframework.http.client.ClientHttpResponse in project spring-framework by spring-projects.
the class RestTemplateXhrTransportTests method connectReceiveAndCloseWithStompFrame.
@Test
public void connectReceiveAndCloseWithStompFrame() throws Exception {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
accessor.setDestination("/destination");
MessageHeaders headers = accessor.getMessageHeaders();
Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(StandardCharsets.UTF_8), headers);
byte[] bytes = new StompEncoder().encode(message);
TextMessage textMessage = new TextMessage(bytes);
SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload());
String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]";
ClientHttpResponse response = response(HttpStatus.OK, body);
connect(response);
verify(this.webSocketHandler).afterConnectionEstablished(any());
verify(this.webSocketHandler).handleMessage(any(), eq(textMessage));
verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
verifyNoMoreInteractions(this.webSocketHandler);
}
use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class MultipartAutoConfigurationTests method verify404.
private void verify404() throws Exception {
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
ClientHttpRequest request = requestFactory.createRequest(new URI("http://localhost:" + this.context.getWebServer().getPort() + "/"), HttpMethod.GET);
ClientHttpResponse response = request.execute();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class HttpHeaderInterceptorTests method intercept.
@Test
public void intercept() throws IOException {
ClientHttpResponse result = this.interceptor.intercept(this.request, this.body, this.execution);
assertThat(this.request.getHeaders().getFirst(this.name)).isEqualTo(this.value);
assertThat(result).isEqualTo(this.response);
}
use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method cannotReadClassPathFiles.
@Test
public void cannotReadClassPathFiles() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
this.webServer = factory.getWebServer(exampleServletRegistration());
this.webServer.start();
ClientHttpResponse response = getClientResponse(getLocalUrl("/org/springframework/boot/SpringApplication.class"));
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method getClientResponse.
protected ClientHttpResponse getClientResponse(String url, HttpMethod method, HttpComponentsClientHttpRequestFactory requestFactory, String... headers) throws IOException, URISyntaxException {
ClientHttpRequest request = requestFactory.createRequest(new URI(url), method);
request.getHeaders().add("Cookie", "JSESSIONID=" + "123");
for (String header : headers) {
String[] parts = header.split(":");
request.getHeaders().add(parts[0], parts[1]);
}
ClientHttpResponse response = request.execute();
return response;
}
Aggregations