Package org.springframework.http.client

Examples of org.springframework.http.client.ClientHttpRequestFactory


  public void afterPropertiesSet() throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();
    BasicCredentialsProvider credentialsProvider =  new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(adminUser, adminPass));
    client.setCredentialsProvider(credentialsProvider);
    ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(client);

    RestTemplate template = new RestTemplate(rf);

    String fullUri = "http://" + hostUri + ":8091/pools/default/buckets/default";
View Full Code Here


    return interceptors;
  }

  @Override
  public ClientHttpRequestFactory getRequestFactory() {
    ClientHttpRequestFactory delegate = super.getRequestFactory();
    if (!CollectionUtils.isEmpty(getInterceptors())) {
      return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
    }
    else {
      return delegate;
View Full Code Here

  protected String getUrl(String path) {
    return cloudControllerUrl + (path.startsWith("/") ? path : "/" + path);
  }

  protected void configureCloudFoundryRequestFactory(RestTemplate restTemplate) {
    ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
    if (!(requestFactory instanceof CloudFoundryClientHttpRequestFactory)) {
      restTemplate.setRequestFactory(
          new CloudFoundryClientHttpRequestFactory(requestFactory));
    }
  }
View Full Code Here

    // And with the actual one used by RestUtil, without a proxy configured
    assertNetworkCallFails(restTemplate, new RestUtil().createRequestFactory(null, false));

    // Test with the in-JVM proxy configured
    HttpProxyConfiguration localProxy = new HttpProxyConfiguration("127.0.0.1", inJvmProxyPort);
    ClientHttpRequestFactory requestFactory = new RestUtil().createRequestFactory(localProxy, CCNG_API_SSL);

    restTemplate.setRequestFactory(requestFactory);
    restTemplate.execute(CCNG_API_URL + "/info", HttpMethod.GET, null, null);

    // then executes fine, and the jetty proxy indeed received one request
View Full Code Here

  public void init() throws Exception {
    resource.setClientId("client");
    resource.setClientSecret("secret");
    resource.setAccessTokenUri("http://nowhere/token");
    response = new StubHttpClientResponse();
    support.setRequestFactory(new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(response);
      }
    });
  }
View Full Code Here

  }

  @Test(expected = AccessTokenRequiredException.class)
  public void testNoRetryAccessDeniedExceptionForNoExistingToken() throws Exception {
    restTemplate.setAccessTokenProvider(new StubAccessTokenProvider());
    restTemplate.setRequestFactory(new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        throw new AccessTokenRequiredException(resource);
      }
    });
    restTemplate.doExecute(new URI("http://foo"), HttpMethod.GET, new NullRequestCallback(),
View Full Code Here

  @Test
  public void testRetryAccessDeniedException() throws Exception {
    final AtomicBoolean failed = new AtomicBoolean(false);
    restTemplate.getOAuth2ClientContext().setAccessToken(new DefaultOAuth2AccessToken("TEST"));
    restTemplate.setAccessTokenProvider(new StubAccessTokenProvider());
    restTemplate.setRequestFactory(new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        if (!failed.get()) {
          failed.set(true);
          throw new AccessTokenRequiredException(resource);
        }
View Full Code Here

  }

  @Test
  public void testGetAccessTokenFromJson() throws Exception {
    final OAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
    requestFactory = new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(new ObjectMapper().writeValueAsString(token));
      }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
View Full Code Here

  }

  @Test
  public void testGetErrorFromJson() throws Exception {
    final InvalidClientException exception = new InvalidClientException("FOO");
    requestFactory = new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(HttpStatus.BAD_REQUEST,
            new ObjectMapper().writeValueAsString(exception));
      }
    };
View Full Code Here

  @Test
  public void testGetAccessTokenFromForm() throws Exception {
    final OAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
    final HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    requestFactory = new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(responseHeaders, "access_token=FOO");
      }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
View Full Code Here

TOP

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

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.