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);
}
}
use of org.springframework.web.client.RestTemplate in project spring-framework by spring-projects.
the class RequestPartIntegrationTests method setup.
@Before
public void setup() {
ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
emptyBodyConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
List<HttpMessageConverter<?>> converters = new ArrayList<>(3);
converters.add(emptyBodyConverter);
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new ResourceHttpMessageConverter());
converters.add(new MappingJackson2HttpMessageConverter());
AllEncompassingFormHttpMessageConverter converter = new AllEncompassingFormHttpMessageConverter();
converter.setPartConverters(converters);
restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
restTemplate.setMessageConverters(Collections.singletonList(converter));
}
use of org.springframework.web.client.RestTemplate in project spring-boot-admin by codecentric.
the class ApplicationRegistratorTest method setup.
@Before
public void setup() {
restTemplate = mock(RestTemplate.class);
adminProps = new AdminProperties();
adminProps.setUrl(new String[] { "http://sba:8080", "http://sba2:8080" });
ApplicationFactory factory = mock(ApplicationFactory.class);
when(factory.createApplication()).thenReturn(Application.create("AppName").withManagementUrl("http://localhost:8080/mgmt").withHealthUrl("http://localhost:8080/health").withServiceUrl("http://localhost:8080").build());
registrator = new ApplicationRegistrator(restTemplate, adminProps, factory);
headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
}
use of org.springframework.web.client.RestTemplate in project goci by EBISPOT.
the class EnsemblRestTemplateService method exec.
public RestResponseResult exec(String url) {
ResponseEntity<String> out;
RestResponseResult result = new RestResponseResult();
RestTemplate restTemplate = this.getRestTemplate();
HttpEntity<Object> entity = this.getEntity();
getLog().debug("Querying " + url);
//and do I need this JSON media type for my use case?
try {
out = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
result.setStatus(out.getStatusCode().value());
result.setUrl(url);
JsonNode body = new JsonNode(out.getBody().toString());
result.setRestResult(body);
getLog().debug("Response: 200");
//result.setValue(out.getBody());
} catch (EnsemblRestClientException erce) {
getLog().debug("EnsemblRestClientException");
result = erce.getEnsemblLookup();
result.setUrl(url);
} catch (Exception e) {
getLog().debug("Exception not managed");
}
return result;
}
use of org.springframework.web.client.RestTemplate in project goci by EBISPOT.
the class EnsemblRestTemplateService method getRestTemplate.
public RestTemplate getRestTemplate() {
// Create a new RestTemplate instance
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new CustomResponseErrorHandler());
// Add the Jackson message converter
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
return restTemplate;
}
Aggregations