use of org.springframework.http.HttpEntity in project java-chassis by ServiceComb.
the class JaxrsClient method testExchange.
private static void testExchange(RestTemplate template, String cseUrlPrefix) {
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", MediaType.APPLICATION_JSON);
Person person = new Person();
person.setName("world");
HttpEntity<Person> requestEntity = new HttpEntity<>(person, headers);
ResponseEntity<Person> resEntity = template.exchange(cseUrlPrefix + "/compute/sayhello", HttpMethod.POST, requestEntity, Person.class);
TestMgr.check("hello world", resEntity.getBody());
ResponseEntity<String> resEntity2 = template.exchange(cseUrlPrefix + "/compute/addstring?s=abc&s=def", HttpMethod.DELETE, null, String.class);
TestMgr.check("abcdef", resEntity2.getBody());
}
use of org.springframework.http.HttpEntity in project java-chassis by ServiceComb.
the class CodeFirstRestTemplate method testCodeFirstReduce.
protected void testCodeFirstReduce(RestTemplate template, String cseUrlPrefix) {
Map<String, String> params = new HashMap<>();
params.put("a", "5");
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.COOKIE, "b=3");
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
ResponseEntity<Integer> result = template.exchange(cseUrlPrefix + "reduce?a={a}", HttpMethod.GET, requestEntity, Integer.class, params);
TestMgr.check(2, result.getBody());
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestConsentRepository method findConsentDecision.
@Override
public ConsentDecision findConsentDecision(final Service service, final RegisteredService registeredService, final Authentication authentication) {
try {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
headers.put("service", CollectionUtils.wrap(service.getId()));
headers.put("principal", CollectionUtils.wrap(authentication.getPrincipal().getId()));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<ConsentDecision> result = restTemplate.exchange(this.endpoint, HttpMethod.GET, entity, ConsentDecision.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
return result.getBody();
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestConsentRepository method deleteConsentDecision.
@Override
public boolean deleteConsentDecision(final long decisionId, final String principal) {
try {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
final HttpEntity<Map> entity = new HttpEntity<>(headers);
final String deleteEndpoint = this.endpoint.concat("/" + Long.toString(decisionId));
final ResponseEntity<Boolean> result = restTemplate.exchange(deleteEndpoint, HttpMethod.DELETE, entity, Boolean.class);
return result.getStatusCodeValue() == HttpStatus.OK.value();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestPasswordManagementService method getSecurityQuestions.
@Override
public Map<String, String> getSecurityQuestions(final String username) {
final PasswordManagementProperties.Rest rest = properties.getRest();
if (StringUtils.isBlank(rest.getEndpointUrlSecurityQuestions())) {
return null;
}
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
headers.put("username", CollectionUtils.wrap(username));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<Map> result = restTemplate.exchange(rest.getEndpointUrlSecurityQuestions(), HttpMethod.GET, entity, Map.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value() && result.hasBody()) {
return result.getBody();
}
return null;
}
Aggregations