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:com.golonzovsky.oauth2.google.security.GoogleTokenServices.java

private Map<String, Object> postForMap(String path, MultiValueMap<String, String> formData,
        HttpHeaders headers) {/*from  w  w w.ja v  a 2  s.  c o  m*/
    if (headers.getContentType() == null) {
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    }
    ParameterizedTypeReference<Map<String, Object>> map = new ParameterizedTypeReference<Map<String, Object>>() {
    };
    return restTemplate.exchange(path, HttpMethod.POST, new HttpEntity<>(formData, headers), map).getBody();
}

From source file:org.openbaton.common.vnfm_sdk.rest.VnfmRestHelper.java

private void delete(String path) {
    HttpEntity<String> requestEntity = new HttpEntity<>("", headers);
    ResponseEntity<String> responseEntity = rest.exchange(url + path, HttpMethod.DELETE, requestEntity,
            String.class);
    this.setStatus(responseEntity.getStatusCode());
}

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

@Test
@OAuth2ContextConfiguration(resource = OAuth2ContextConfiguration.Implicit.class, initialize = false)
public void testUserChangesOwnPassword() throws Exception {

    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
    parameters.set("source", "credentials");
    parameters.set("username", joe.getUserName());
    parameters.set("password", "password");
    context.getAccessTokenRequest().putAll(parameters);

    PasswordChangeRequest change = new PasswordChangeRequest();
    change.setOldPassword("password");
    change.setPassword("newpassword");

    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}/password",
            HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, joe.getId());
    assertEquals(HttpStatus.OK, result.getStatusCode());

    // Now try logging in with the new credentials
    headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    String credentials = String.format("{ \"username\":\"%s\", \"password\":\"%s\" }", joe.getUserName(),
            "newpassword");

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("credentials", credentials);
    result = serverRunning.postForResponse(implicitUrl(), headers, formData);

    assertNotNull(result.getHeaders().getLocation());
    assertTrue(result.getHeaders().getLocation().toString()
            .matches("https://uaa.cloudfoundry.com/redirect/vmc#access_token=.+"));
}