Example usage for org.springframework.http HttpEntity HttpEntity

List of usage examples for org.springframework.http HttpEntity HttpEntity

Introduction

In this page you can find the example usage for org.springframework.http HttpEntity HttpEntity.

Prototype

public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers) 

Source Link

Document

Create a new HttpEntity with the given body and headers.

Usage

From source file:org.cloudfoundry.identity.uaa.login.test.TestClient.java

private void restfulCreate(String adminAccessToken, String json, String url) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Bearer " + adminAccessToken);
    headers.add("Accept", "application/json");
    headers.add("Content-Type", "application/json");

    HttpEntity<String> requestEntity = new HttpEntity<String>(json, headers);
    ResponseEntity<Void> exchange = restTemplate.exchange(url, HttpMethod.POST, requestEntity, Void.class);
    Assert.assertEquals(HttpStatus.CREATED, exchange.getStatusCode());
}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String getClassShema(String classURI) {

    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/class/schema";
    //final String uri = "http://localhost:8090/api/v1/ontology/class/schema";

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entity = new HttpEntity<>(classURI, headers);

    String result = restTemplate.postForObject(uri, entity, String.class);

    return result;
}

From source file:org.obiba.mica.user.UserProfileService.java

private <T> T executeQuery(String serviceUrl, Class<T> returnType) {

    RestTemplate template = newRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.set(APPLICATION_AUTH_HEADER, getApplicationAuth());
    HttpEntity<String> entity = new HttpEntity<>(null, headers);
    ResponseEntity<T> response = template.exchange(serviceUrl, HttpMethod.GET, entity, returnType);

    return response.getBody();
}

From source file:com.garyclayburg.UserRestSmokeTest.java

@Ignore
@Test//  w w w .j a  va2  s.  com
public void testJsonApache() throws Exception {
    RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    SimpleUser user1 = new SimpleUser();
    user1.setFirstname("Tommy");
    user1.setLastname("Deleteme");
    user1.setId("112" + (int) (Math.floor(Math.random() * 10000)));

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Content-Type", "application/json");
    //        HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
    HttpEntity<?> requestEntity = new HttpEntity(user1, requestHeaders);

    ResponseEntity<SimpleUser> simpleUserResponseEntity = rest.exchange(
            "http://" + endpoint + "/audited-users/auditedsave", HttpMethod.POST, requestEntity,
            SimpleUser.class);

    //        ResponseEntity<SimpleUser> userResponseEntity =
    //            rest.postForEntity("http://" + endpoint + "/audited-users/auditedsave",user1,SimpleUser.class);
    log.info("got a response");
    MatcherAssertionErrors.assertThat(simpleUserResponseEntity.getStatusCode(),
            Matchers.equalTo(HttpStatus.OK));

}

From source file:org.cloudfoundry.identity.uaa.login.feature.LoginIT.java

@Test
public void testRedirectAfterFailedLogin() throws Exception {
    RestTemplate template = new RestTemplate();
    LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>();
    body.add("username", testAccounts.getUserName());
    body.add("password", "invalidpassword");
    ResponseEntity<Void> loginResponse = template.exchange(baseUrl + "/login.do", HttpMethod.POST,
            new HttpEntity<>(body, null), Void.class);
    assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode());
}

From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java

@Test
public void nonImplicitGrantClientWithoutSecretIsRejected() throws Exception {
    OAuth2AccessToken token = getClientCredentialsAccessToken("clients.read clients.write");
    HttpHeaders headers = getAuthenticatedHeaders(token);
    BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar",
            "client_credentials", "uaa.none");
    ResponseEntity<UaaException> result = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), UaaException.class);
    assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
    assertEquals("invalid_client", result.getBody().getErrorCode());
}

From source file:org.craftercms.commerce.client.AbstractRestCRUDService.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public ServiceResponse<T> saveAll(T[] entities) throws CrafterCommerceException {
    try {//from   w w  w.  j a v a2 s .  com
        String restUrl = crafterCommerceServerUrl + TypeToPathMapper.path(getTypeArgument())
                + CrafterCommerceConstants.SAVE_ALL_ACTION_REST_MAPPING
                + CrafterCommerceConstants.JSON_EXTENSION;
        HttpEntity<T[]> httpEntity = new HttpEntity<T[]>(entities, httpHeaders);
        ResponseEntity<? extends ServiceResponse> responseEntity = restTemplate.postForEntity(restUrl,
                httpEntity, new ServiceResponse<T>().getClass());
        ServiceResponse<T> response = responseEntity.getBody();
        if (response.isSuccess() == false) {
            throw new CrafterCommerceException(response.getMessage());
        }
        return response;
    } catch (Exception e) {
        throw new CrafterCommerceException(e);
    }
}

From source file:de.swm.nis.logicaldecoding.gwc.GWCInvalidator.java

private void postSeedRequest(Envelope envelope) {

    String gwcurl = gwcBaseUrl + "seed/" + layername + ".json";

    Bounds bounds = new Bounds(
            new Coordinates(envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY()));
    Srs srs = new Srs(epsgCode);
    SeedRequest request = new SeedRequest(layername, bounds, srs, zoomStart, zoomStop, imageFormat, operation,
            numThreads);//w  ww. j a  v a  2 s .  co m

    HttpEntity<GwcSeedDAO> httpentity = new HttpEntity<GwcSeedDAO>(new GwcSeedDAO(request),
            createHeaders(gwcUserName, gwcPassword));
    ResponseEntity response = template.exchange(gwcurl, HttpMethod.POST, httpentity, String.class);
    HttpStatus returncode = response.getStatusCode();
    if (!returncode.is2xxSuccessful()) {
        log.warn("HTTP Call to " + gwcurl + " was not successfull, Status code: " + response.getStatusCode());
    } else {
        log.debug("HTTP Call to " + gwcurl + "succeeded");
    }

}

From source file:com.epam.reportportal.gateway.CompositeInfoEndpoint.java

@RequestMapping(value = "/composite/{endpoint}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody//  ww w  .  j a v a  2 s.c  o m
public Map<String, ?> compose(@PathVariable("endpoint") String endpoint) {
    return discoveryClient.getServices().stream()
            .map((Function<String, AbstractMap.SimpleImmutableEntry<String, Object>>) service -> {
                try {
                    List<ServiceInstance> instances = discoveryClient.getInstances(service);
                    if (instances.isEmpty()) {
                        return new AbstractMap.SimpleImmutableEntry<>(service, "DOWN");
                    }
                    ServiceInstance instance = instances.get(0);
                    String protocol = instance.isSecure() ? "https" : "http";
                    HttpHeaders headers = new HttpHeaders();
                    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
                    return new AbstractMap.SimpleImmutableEntry<>(instance.getServiceId(),
                            loadBalancedRestTemplate.exchange(protocol + "://{service}/{endpoint}",
                                    HttpMethod.GET, new HttpEntity<>(null, headers), Map.class,
                                    instance.getServiceId(), endpoint).getBody());
                } catch (Exception e) {
                    return new AbstractMap.SimpleImmutableEntry<>(service, "DOWN");
                }
            }).collect(toMap(AbstractMap.SimpleImmutableEntry::getKey,
                    AbstractMap.SimpleImmutableEntry::getValue, (value1, value2) -> value2));

}

From source file:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsServiceEnabledPredefinedTests.java

@Test
public void basicAuthenticationRemoteLogServiceEnabledTest() throws Exception {
    TestLoginInfo loginInfo = login();/*from   w  w w .ja va 2  s.  co m*/

    RemoteLogRequestVO logRequestVO = new RemoteLogRequestVO();
    logRequestVO.setMessage("Test mesage!");
    logRequestVO.setLogLevel("DEBUG");

    // This test requires the test CSRF Token. This implies passing JSESSIONID and CSRF Token
    HttpHeaders headers = new HttpHeaders();
    headers.set("Cookie", loginInfo.getJsessionid());
    HttpEntity<RemoteLogRequestVO> entity = new HttpEntity<RemoteLogRequestVO>(logRequestVO, headers);

    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl("http://localhost:" + port + baseApiPath + remoteLogEndpointPath)
            .queryParam(DEFAULT_CSRF_PARAMETER_NAME, loginInfo.getXsrfToken());
    ResponseEntity<String> responseEntity = restTemplate.exchange(builder.build().encode().toUri(),
            HttpMethod.POST, entity, String.class);
    assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}