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();
}
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);
}
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);
}
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());
}
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);
}
}
Aggregations