Search in sources :

Example 56 with ClientHttpResponse

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);
}
Also used : Jackson2SockJsMessageCodec(org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec) StompEncoder(org.springframework.messaging.simp.stomp.StompEncoder) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) MessageHeaders(org.springframework.messaging.MessageHeaders) CloseStatus(org.springframework.web.socket.CloseStatus) SockJsFrame(org.springframework.web.socket.sockjs.frame.SockJsFrame) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Example 57 with ClientHttpResponse

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);
}
Also used : HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse)

Example 58 with ClientHttpResponse

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);
}
Also used : ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Test(org.junit.Test)

Example 59 with ClientHttpResponse

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);
}
Also used : ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Test(org.junit.Test)

Example 60 with ClientHttpResponse

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;
}
Also used : ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse)

Aggregations

ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)71 Test (org.junit.Test)35 IOException (java.io.IOException)25 ResponseErrorHandler (org.springframework.web.client.ResponseErrorHandler)21 HttpHeaders (org.springframework.http.HttpHeaders)18 URI (java.net.URI)17 DefaultResponseErrorHandler (org.springframework.web.client.DefaultResponseErrorHandler)15 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)14 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)11 RestTemplate (org.springframework.web.client.RestTemplate)11 ResponseExtractor (org.springframework.web.client.ResponseExtractor)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)7 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)6 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)6 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)6 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)6 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)6 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)6 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)6