Search in sources :

Example 91 with HttpEntity

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());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Person(io.servicecomb.demo.compute.Person)

Example 92 with HttpEntity

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());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap)

Example 93 with HttpEntity

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ToString(lombok.ToString)

Example 94 with HttpEntity

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ToString(lombok.ToString) Map(java.util.Map)

Example 95 with HttpEntity

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) Map(java.util.Map)

Aggregations

HttpEntity (org.springframework.http.HttpEntity)104 HttpHeaders (org.springframework.http.HttpHeaders)81 Test (org.junit.Test)46 RestTemplate (org.springframework.web.client.RestTemplate)17 URI (java.net.URI)15 ArrayList (java.util.ArrayList)13 ResponseEntity (org.springframework.http.ResponseEntity)12 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)12 Map (java.util.Map)11 MediaType (org.springframework.http.MediaType)11 HashMap (java.util.HashMap)10 List (java.util.List)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 MultiValueMap (org.springframework.util.MultiValueMap)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)7 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)7 HttpStatus (org.springframework.http.HttpStatus)6 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)6 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)6