use of org.springframework.web.client.RestTemplate in project openmrs-module-pihcore by PIH.
the class RestBiometricEngine method lookup.
@Override
public BiometricSubject lookup(String subjectId) {
RestTemplate restTemplate = new RestTemplate();
String url = getSubjectUrl() + "/" + subjectId;
ResponseEntity<BiometricSubject> response = restTemplate.getForEntity(url, BiometricSubject.class);
if (HttpStatus.OK.equals(response.getStatusCode())) {
return response.getBody();
} else if (HttpStatus.NOT_FOUND.equals(response.getStatusCode())) {
return null;
} else {
throw new IllegalStateException("Error looking up biometric subject at URL <" + url + ">. Response status code: " + response.getStatusCode());
}
}
use of org.springframework.web.client.RestTemplate in project incubator-servicecomb-java-chassis by apache.
the class DynamicConfigurationIT method releaseConfiguration.
public int releaseConfiguration() {
String release = url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/releases";
RestTemplate rest = new RestTemplate();
Map<String, String> body = new HashMap<>();
body.put("releaseTitle", "release-configuration");
body.put("releasedBy", "apollo");
HttpEntity<?> entity = new HttpEntity<Object>(body, headers);
ResponseEntity<String> exchange = rest.exchange(release, HttpMethod.POST, entity, String.class);
return exchange.getStatusCodeValue();
}
use of org.springframework.web.client.RestTemplate in project incubator-servicecomb-java-chassis by apache.
the class ServiceCenterExample method main.
public static void main(String[] args) throws Exception {
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("X-Tenant-Name", "default");
RequestEntity<String> requestEntity = new RequestEntity<String>(headers, HttpMethod.GET, new URI("http://127.0.0.1:9980/registry/v3/microservices"));
ResponseEntity<String> stringResponseEntity = template.exchange(requestEntity, String.class);
System.out.println(stringResponseEntity.getBody());
ResponseEntity<MicroserviceArray> microseriveResponseEntity = template.exchange(requestEntity, MicroserviceArray.class);
MicroserviceArray microserives = microseriveResponseEntity.getBody();
System.out.println(microserives.getServices().get(1).getServiceId());
// instance
headers.add("X-ConsumerId", microserives.getServices().get(1).getServiceId());
requestEntity = new RequestEntity<String>(headers, HttpMethod.GET, new URI("http://127.0.0.1:9980/registry/v3/microservices/" + microserives.getServices().get(1).getServiceId() + "/instances"));
ResponseEntity<String> microserviceInstanceResponseEntity = template.exchange(requestEntity, String.class);
System.out.println(microserviceInstanceResponseEntity.getBody());
}
use of org.springframework.web.client.RestTemplate in project spring-security-oauth by spring-projects.
the class RemoteTokenServicesTest method loadAuthenticationWhenIntrospectionResponseContainsActiveTrueThenReturnAuthentication.
// gh-838
@Test
public void loadAuthenticationWhenIntrospectionResponseContainsActiveTrueThenReturnAuthentication() throws Exception {
Map responseAttrs = new HashMap();
// "active" is the only required attribute as per RFC 7662 (https://tools.ietf.org/search/rfc7662#section-2.2)
responseAttrs.put("active", true);
ResponseEntity<Map> response = new ResponseEntity<Map>(responseAttrs, HttpStatus.OK);
RestTemplate restTemplate = mock(RestTemplate.class);
when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(HttpEntity.class), any(Class.class))).thenReturn(response);
this.remoteTokenServices.setRestTemplate(restTemplate);
OAuth2Authentication authentication = this.remoteTokenServices.loadAuthentication("access-token-1234");
assertNotNull(authentication);
}
use of org.springframework.web.client.RestTemplate in project spring-security-oauth by spring-projects.
the class RemoteTokenServicesTest method loadAuthenticationWhenIntrospectionResponseMissingActiveAttributeThenThrowInvalidTokenException.
// gh-838
@Test(expected = InvalidTokenException.class)
public void loadAuthenticationWhenIntrospectionResponseMissingActiveAttributeThenThrowInvalidTokenException() throws Exception {
Map responseAttrs = new HashMap();
ResponseEntity<Map> response = new ResponseEntity<Map>(responseAttrs, HttpStatus.OK);
RestTemplate restTemplate = mock(RestTemplate.class);
when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(HttpEntity.class), any(Class.class))).thenReturn(response);
this.remoteTokenServices.setRestTemplate(restTemplate);
this.remoteTokenServices.loadAuthentication("access-token-1234");
}
Aggregations