Package org.springframework.http.client

Examples of org.springframework.http.client.ClientHttpResponse



  @Test
  public void connectReceiveAndClose() throws Exception {
    String body = "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
    ClientHttpResponse response = response(HttpStatus.OK, body);
    connect(response);

    verify(this.webSocketHandler).afterConnectionEstablished(any());
    verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
    verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
View Full Code Here


    StringBuilder sb = new StringBuilder(2048);
    for (int i=0; i < 2048; i++) {
      sb.append('h');
    }
    String body = sb.toString() + "\n" + "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
    ClientHttpResponse response = response(HttpStatus.OK, body);
    connect(response);

    verify(this.webSocketHandler).afterConnectionEstablished(any());
    verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
    verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
View Full Code Here

    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!")));
View Full Code Here

  }

  @Test
  public void responseClosedAfterDisconnected() throws Exception {
    String body = "o\n" + "c[3000,\"Go away!\"]\n" + "a[\"foo\"]\n";
    ClientHttpResponse response = response(HttpStatus.OK, body);
    connect(response);

    verify(this.webSocketHandler).afterConnectionEstablished(any());
    verify(this.webSocketHandler).afterConnectionClosed(any(), any());
    verifyNoMoreInteractions(this.webSocketHandler);
View Full Code Here

    return transport.connect(request, this.webSocketHandler);
  }

  private ClientHttpResponse response(HttpStatus status, String body) throws IOException {
    ClientHttpResponse response = mock(ClientHttpResponse.class);
    InputStream inputStream = getInputStream(body);
    given(response.getStatusCode()).willReturn(status);
    given(response.getBody()).willReturn(inputStream);
    return response;
  }
View Full Code Here

  protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback,
      ResponseExtractor<T> responseExtractor) throws RestClientException {

    Assert.notNull(url, "'url' must not be null");
    Assert.notNull(method, "'method' must not be null");
    ClientHttpResponse response = null;
    try {
      ClientHttpRequest request = createRequest(url, method);
      if (requestCallback != null) {
        requestCallback.doWithRequest(request);
      }
      response = request.execute();
      if (!getErrorHandler().hasError(response)) {
        logResponseStatus(method, url, response);
      }
      else {
        handleResponseError(method, url, response);
      }
      if (responseExtractor != null) {
        return responseExtractor.extractData(response);
      }
      else {
        return null;
      }
    }
    catch (IOException ex) {
      throw new ResourceAccessException("I/O error: " + ex.getMessage(), ex);
    }
    finally {
      if (response != null) {
        response.close();
      }
    }
  }
View Full Code Here

        // holder for the headers...
        HttpHeaders headers = new HttpHeaders();

        // Mock guts of RestTemplate so no need to actually hit the web...
        ClientHttpResponse resp = mock(ClientHttpResponse.class);
        when(resp.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
        when(resp.getHeaders()).thenReturn(new HttpHeaders());

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ClientHttpRequest client = mock(ClientHttpRequest.class);
        when(client.getHeaders()).thenReturn(headers);
        when(client.getBody()).thenReturn(buffer);
View Full Code Here

        // holder for the headers...
        HttpHeaders headers = new HttpHeaders();

        // Mock guts of RestTemplate so no need to actually hit the web...
        ClientHttpResponse resp = mock(ClientHttpResponse.class);
        when(resp.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
        when(resp.getHeaders()).thenReturn(new HttpHeaders());

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ClientHttpRequest client = mock(ClientHttpRequest.class);
        when(client.getHeaders()).thenReturn(headers);
        when(client.getBody()).thenReturn(buffer);
View Full Code Here

  protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback,
      ResponseExtractor<T> responseExtractor) throws RestClientException {

    Assert.notNull(url, "'url' must not be null");
    Assert.notNull(method, "'method' must not be null");
    ClientHttpResponse response = null;
    try {
      ClientHttpRequest request = createRequest(url, method);
      if (requestCallback != null) {
        requestCallback.doWithRequest(request);
      }
      response = request.execute();
      if (!getErrorHandler().hasError(response)) {
        logResponseStatus(method, url, response);
      }
      else {
        handleResponseError(method, url, response);
      }
      if (responseExtractor != null) {
        return responseExtractor.extractData(response);
      }
      else {
        return null;
      }
    }
    catch (IOException ex) {
      throw new ResourceAccessException("I/O error: " + ex.getMessage(), ex);
    }
    finally {
      if (response != null) {
        response.close();
      }
    }
  }
View Full Code Here

    MimeMappings mimeMappings = new MimeMappings();
    mimeMappings.add("xxcss", "text/css");
    factory.setMimeMappings(mimeMappings);
    this.container = factory.getEmbeddedServletContainer();
    this.container.start();
    ClientHttpResponse response = getClientResponse(getLocalUrl("/test.xxcss"));
    assertThat(response.getHeaders().getContentType().toString(), equalTo("text/css"));
    response.close();
  }
View Full Code Here

TOP

Related Classes of org.springframework.http.client.ClientHttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.