Search in sources :

Example 21 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method rootUriShouldApply.

@Test
public void rootUriShouldApply() throws Exception {
    RestTemplate restTemplate = this.builder.rootUri("http://example.com").build();
    MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
    server.expect(requestTo("http://example.com/hello")).andRespond(withSuccess());
    restTemplate.getForEntity("/hello", String.class);
    server.verify();
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) Test(org.junit.Test)

Example 22 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method requestFactoryClassShouldApply.

@Test
public void requestFactoryClassShouldApply() throws Exception {
    RestTemplate template = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).build();
    assertThat(template.getRequestFactory()).isInstanceOf(SimpleClientHttpRequestFactory.class);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 23 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate.

@Test
public void unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    RestTemplate template = this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory)).build();
    assertThat(template.getRequestFactory()).isInstanceOf(BufferingClientHttpRequestFactory.class);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.Test)

Example 24 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method defaultMessageConvertersShouldSetDefaultList.

@Test
public void defaultMessageConvertersShouldSetDefaultList() throws Exception {
    RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(new StringHttpMessageConverter()));
    this.builder.defaultMessageConverters().configure(template);
    assertThat(template.getMessageConverters()).hasSameSizeAs(new RestTemplate().getMessageConverters());
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Test(org.junit.Test)

Example 25 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-data-document-examples by spring-projects.

the class RestTemplateActivity method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView view = new TextView(this);
    view.append("Running tests...\n\n");
    setContentView(view);
    try {
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
        converters.add(new MappingJacksonHttpMessageConverter());
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setMessageConverters(converters);
        Map response = restTemplate.getForObject("http://127.0.0.1:5984", Map.class);
        view.append(response.toString());
        /*
			URL url = new URL("http:/127.0.0.1:5984");
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod("GET");
			BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String line;
			List<String> lines= new ArrayList<String>();
			while((line = reader.readLine()) != null){
			    lines.add(line);
			}
			reader.close();
			view.append(lines.toString());*/
        view.append("all ok!");
    } catch (Exception e) {
        view.append(e.toString());
        Log.e("rest-template", "this is bad", e);
    }
}
Also used : MappingJacksonHttpMessageConverter(org.springframework.http.converter.json.MappingJacksonHttpMessageConverter) ArrayList(java.util.ArrayList) MappingJacksonHttpMessageConverter(org.springframework.http.converter.json.MappingJacksonHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) TextView(android.widget.TextView) Map(java.util.Map)

Aggregations

RestTemplate (org.springframework.web.client.RestTemplate)189 Test (org.junit.Test)107 URI (java.net.URI)39 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)29 ArrayList (java.util.ArrayList)24 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)20 HashMap (java.util.HashMap)19 MapPropertySource (org.springframework.core.env.MapPropertySource)15 StandardEnvironment (org.springframework.core.env.StandardEnvironment)15 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)15 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)13 HttpHeaders (org.springframework.http.HttpHeaders)13 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)13 IOException (java.io.IOException)12 JSONObject (org.json.JSONObject)12 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)11 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)11 JSONException (org.json.JSONException)10 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)10