Package org.springframework.http.client

Examples of org.springframework.http.client.ClientHttpRequestFactory


  @Test
  public void testGetErrorFromForm() throws Exception {
    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(HttpStatus.BAD_REQUEST, responseHeaders,
            "error=invalid_client&error_description=FOO");
      }
    };
View Full Code Here


    }

    @Test(expected = IllegalArgumentException.class)
    public void testCreateFactoryWrapperIllegalRequest() throws Exception {
        ClientHttpFactoryProcessorParam params = new ClientHttpFactoryProcessorParam();
        final ClientHttpRequestFactory factoryWrapper = restrictUrisProcessor.createFactoryWrapper(params, requestFactory);
        factoryWrapper.createRequest(new URI("http://www.google.com/q"), HttpMethod.GET);
    }
View Full Code Here

        ClientHttpRequest client = mock(ClientHttpRequest.class);
        when(client.getHeaders()).thenReturn(headers);
        when(client.getBody()).thenReturn(buffer);
        when(client.execute()).thenReturn(resp);

        ClientHttpRequestFactory factory = mock(ClientHttpRequestFactory.class);
        when(factory.createRequest(any(URI.class), any(HttpMethod.class))).thenReturn(client);

        // add the new interceptor...
        BasicAuthInterceptor interceptor = new BasicAuthInterceptor();
        interceptor.setPropertyResolver(resolver);
        interceptor.setId(id);
View Full Code Here

        ClientHttpRequest client = mock(ClientHttpRequest.class);
        when(client.getHeaders()).thenReturn(headers);
        when(client.getBody()).thenReturn(buffer);
        when(client.execute()).thenReturn(resp);

        ClientHttpRequestFactory factory = mock(ClientHttpRequestFactory.class);
        when(factory.createRequest(any(URI.class), any(HttpMethod.class))).thenReturn(client);

        // add the new interceptor...
        ZeroLeggedOAuthInterceptor interceptor = new ZeroLeggedOAuthInterceptor();
        interceptor.setPropertyResolver(resolver);
        interceptor.setId(id);
View Full Code Here

  /**
   * The read timeout for the underlying URLConnection to the twitter stream.
   */
  public void setReadTimeout(int millis) {
    // Hack to get round Spring's dynamic loading of http client stuff
    ClientHttpRequestFactory f = getRequestFactory();
    if (f instanceof SimpleClientHttpRequestFactory) {
      ((SimpleClientHttpRequestFactory) f).setReadTimeout(millis);
    }
    else {
      ((HttpComponentsClientHttpRequestFactory) f).setReadTimeout(millis);
View Full Code Here

  /**
   * The connection timeout for making a connection to Twitter.
   */
  public void setConnectTimeout(int millis) {
    ClientHttpRequestFactory f = getRequestFactory();
    if (f instanceof SimpleClientHttpRequestFactory) {
      ((SimpleClientHttpRequestFactory) f).setConnectTimeout(millis);
    }
    else {
      ((HttpComponentsClientHttpRequestFactory) f).setConnectTimeout(millis);
View Full Code Here

   * This implementation creates a RestTemplate with a minimal set of HTTP message converters ({@link FormHttpMessageConverter} and {@link MappingJackson2HttpMessageConverter}).
   * May be overridden to customize how the RestTemplate is created.
   * For example, if the provider returns data in some format other than JSON for form-encoded, you might override to register an appropriate message converter.
   */
  protected RestTemplate createRestTemplate() {
    ClientHttpRequestFactory requestFactory = ClientHttpRequestFactorySelector.getRequestFactory();
    RestTemplate restTemplate = new RestTemplate(requestFactory);
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(2);
    converters.add(new FormHttpMessageConverter());
    converters.add(new FormMapHttpMessageConverter());
    converters.add(new MappingJackson2HttpMessageConverter());
View Full Code Here

    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

        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), new UsernamePasswordCredentials("user1", "user1Pass"));
        final CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).setDefaultCredentialsProvider(credentialsProvider).build();

        final ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(client);
        restTemplate = new RestTemplate(requestFactory);
    }
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.