Package org.springframework.web.client

Examples of org.springframework.web.client.RestTemplate


  public void setup() {
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new StringHttpMessageConverter());
    converters.add(new MappingJacksonHttpMessageConverter());

    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);

    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
  }
View Full Code Here


    this.people.add("performers", new Person("Yehudi Menuhin"));

    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new MappingJacksonHttpMessageConverter());

    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);

    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
  }
View Full Code Here

  public void setup() {
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new StringHttpMessageConverter());
    converters.add(new MappingJacksonHttpMessageConverter());

    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);

    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
  }
View Full Code Here

    this.people = new PeopleWrapper(composers, performers);

    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new Jaxb2RootElementHttpMessageConverter());

    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);

    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
  }
View Full Code Here

    this.people = new PeopleWrapper(composers);

    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new Jaxb2RootElementHttpMessageConverter());

    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);

    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
  }
View Full Code Here

    /**
     * Create a JSON REST Template for requests
     * @return a RestTemplate configured to process JSON data
     */
    private RestTemplate getRestJsonTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
        // Add JSON message handler
        MappingJacksonHttpMessageConverter json = new MappingJacksonHttpMessageConverter();
        List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
        supportedMediaTypes.add(new MediaType("application","json", Charset.forName("UTF-8")));
        // Add default media type in case marketplace uses incorrect MIME type, otherwise
        // Spring refuses to process it, even if its valid JSON
        supportedMediaTypes.add(new MediaType("application","octet-stream", Charset.forName("UTF-8")));
        json.setSupportedMediaTypes(supportedMediaTypes);
        mc.add(json);
        restTemplate.setMessageConverters(mc);
        return restTemplate;
    }
View Full Code Here

        ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
                requestFactory.getAuthScope(), new UsernamePasswordCredentials(uid, pwd));
    }

    private RestTemplate getAnonymousRestTemplate() {
        RestTemplate template = new RestTemplate(httpClientFactory);
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
        converters.add(mappingJacksonHttpMessageConverter);
        template.setMessageConverters(converters);
        template.setErrorHandler(new SyncopeClientErrorHandler());
        return template;
    }
View Full Code Here

      return new HttpTunnel(url, host, port, auth, createRestTemplate());
    }
  }

  private RestTemplate createRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    CommonsClientHttpRequestFactory requestFactory = new CommonsClientHttpRequestFactory();
    requestFactory.setConnectTimeout(TIMEOUT);
    requestFactory.setReadTimeout(TIMEOUT);
    if (httpProxyConfiguration != null) {
      requestFactory.getHttpClient().getHostConfiguration().setProxy(httpProxyConfiguration.getProxyHost(),
          httpProxyConfiguration.getProxyPort());
    }
    restTemplate.setRequestFactory(requestFactory);
    return restTemplate;
  }
View Full Code Here

    if (SKIP_INJVM_PROXY) {
      return; //inJvm Proxy test skipped.
    }
    assertTrue(SocketDestHelper.isSocketRestrictionFlagActive());

    RestTemplate restTemplate = new RestTemplate();

    // When called directly without a proxy, expect an exception to be thrown due to byteman rules
    assertNetworkCallFails(restTemplate, new HttpComponentsClientHttpRequestFactory());
    // Repeat that with different request factory used in the code as this exercises different byteman rules
    assertNetworkCallFails(restTemplate, new SimpleClientHttpRequestFactory());
    // 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
    assertEquals("expected network calls to make it through the inJvmProxy.", 1, nbInJvmProxyRcvReqs.get());
    nbInJvmProxyRcvReqs.set(0); //reset for next test
View Full Code Here

      Thread.sleep(1000);
      app = connectedClient.getApplication(appName);
    }
    assertEquals(1, app.getRunningInstances());
    RestUtil restUtil = new RestUtil();
    RestTemplate rest = restUtil.createRestTemplate(httpProxyConfiguration, false);
    String results = rest.getForObject("http://" + app.getUris().get(0), String.class);
    assertTrue(results.contains("Hello world!"));
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.client.RestTemplate

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.