Package org.springframework.http.client

Examples of org.springframework.http.client.ClientHttpResponse


  protected String getLocalUrl(int port, String resourcePath) {
    return "http://localhost:" + port + resourcePath;
  }

  protected String getResponse(String url) throws IOException, URISyntaxException {
    ClientHttpResponse response = getClientResponse(url);
    try {
      return StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8"));
    }
    finally {
      response.close();
    }
  }
View Full Code Here


  }

  protected String getResponse(String url,
      HttpComponentsClientHttpRequestFactory requestFactory) throws IOException,
      URISyntaxException {
    ClientHttpResponse response = getClientResponse(url, requestFactory);
    try {
      return StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8"));
    }
    finally {
      response.close();
    }
  }
View Full Code Here

  protected ClientHttpResponse getClientResponse(String url,
      HttpComponentsClientHttpRequestFactory requestFactory) throws IOException,
      URISyntaxException {
    ClientHttpRequest request = requestFactory.createRequest(new URI(url),
        HttpMethod.GET);
    ClientHttpResponse response = request.execute();
    return response;
  }
View Full Code Here

      String resourcePath) throws Exception {
    SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
    ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI(
        "http://localhost:" + context.getEmbeddedServletContainer().getPort()
            + resourcePath), HttpMethod.GET);
    ClientHttpResponse response = request.execute();
    try {
      String actual = StreamUtils.copyToString(response.getBody(),
          Charset.forName("UTF-8"));
      assertThat(actual, equalTo("Hello World"));
    }
    finally {
      response.close();
    }
  }
View Full Code Here

  public void assertContent(String url, int port, Object expected) throws Exception {
    SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
    ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI(
        "http://localhost:" + port + url), HttpMethod.GET);
    try {
      ClientHttpResponse response = request.execute();
      try {
        String actual = StreamUtils.copyToString(response.getBody(),
            Charset.forName("UTF-8"));
        assertThat(actual, equalTo(expected));
      }
      finally {
        response.close();
      }
    }
    catch (Exception ex) {
      if (expected == null) {
        if (SocketException.class.isInstance(ex)
View Full Code Here

  public boolean hasHeader(String url, int port, String header) throws Exception {
    SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
    ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI(
        "http://localhost:" + port + url), HttpMethod.GET);
    ClientHttpResponse response = request.execute();
    return response.getHeaders().containsKey(header);
  }
View Full Code Here

  }

  @Test
  public void bufferRequests() throws Exception {
    ClientHttpRequest mockRequest = mock(ClientHttpRequest.class);
    ClientHttpResponse mockResponse = mock(ClientHttpResponse.class);
    when(mockResponse.getBody()).thenReturn(new ByteArrayInputStream("Test Body".getBytes()));
    when(mockRequest.getHeaders()).thenReturn(new HttpHeaders());
    when(mockRequest.getBody()).thenReturn(new ByteArrayOutputStream());
    when(mockRequest.execute()).thenReturn(mockResponse);
    ClientHttpRequestFactory mockRequestFactory = mock(ClientHttpRequestFactory.class);
    when(mockRequestFactory.createRequest(new URI("http://somehost.com/test"), HttpMethod.GET)).thenReturn(mockRequest);
    ClientHttpRequestFactory bufferingRequestFactory = ClientHttpRequestFactorySelector.bufferRequests(mockRequestFactory);
    ClientHttpRequest request = bufferingRequestFactory.createRequest(new URI("http://somehost.com/test"), HttpMethod.GET);
    ClientHttpResponse response = request.execute();
    response.getBody();
    response.getBody();
    response.getBody();
    verify(mockRequest, times(1)).getBody();
  }
View Full Code Here

        //@Override
        public ClientHttpResponse intercept(HttpRequest request,
            byte[] body, ClientHttpRequestExecution execution)
            throws IOException {
          ClientHttpResponse res = execution.execute(request, body);
          System.out.println("==== Github: "+request.getURI()+ "  =========");
          for (Entry<String, List<String>> header : res.getHeaders().entrySet()) {
            if (header.getKey().contains("RateLimit")) {
              System.out.print(header.getKey()+":");
              for (String value : header.getValue()) {
                System.out.print(" "+value);
              }
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.