Example usage for org.springframework.web.client RestOperations exchange

List of usage examples for org.springframework.web.client RestOperations exchange

Introduction

In this page you can find the example usage for org.springframework.web.client RestOperations exchange.

Prototype

<T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
        ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException;

Source Link

Document

Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity .

Usage

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

@Test
public void userInfoSucceeds() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", "*/*");
    RestOperations client = serverRunning.getRestTemplate();
    ResponseEntity<Void> result = client.exchange(serverRunning.getUrl("/userinfo"), HttpMethod.GET,
            new HttpEntity<Void>(null, headers), null, joe.getId());
    assertEquals(HttpStatus.OK, result.getStatusCode());

}

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

@Test
public void changePasswordSucceeds() throws Exception {

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

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

}

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

@SuppressWarnings("rawtypes")
private ResponseEntity<Map> deleteUser(RestOperations client, String id, int version) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("If-Match", "\"" + version + "\"");
    return client.exchange(serverRunning.getUrl(usersEndpoint + "/{id}"), HttpMethod.DELETE,
            new HttpEntity<Void>(headers), Map.class, id);
}

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

@BeforeOAuth2Context
@OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class)
public void setUpUserAccounts() {

    // If running against vcap we don't want to run these tests because they create new user accounts
    // Assume.assumeTrue(!testAccounts.isProfileActive("vcap"));

    RestOperations client = serverRunning.getRestTemplate();

    ScimUser user = new ScimUser();
    user.setUserName(JOE);//w  w  w. j  a v  a2s .com
    user.setName(new ScimUser.Name("Joe", "User"));
    user.addEmail("joe@blah.com");

    ResponseEntity<ScimUser> newuser = client.postForEntity(serverRunning.getUrl(usersEndpoint), user,
            ScimUser.class);

    joe = newuser.getBody();
    assertEquals(JOE, joe.getUserName());

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

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

    // The implicit grant for vmc requires extra parameters in the authorization request
    context.setParameters(Collections.singletonMap("credentials",
            testAccounts.getJsonCredentials(joe.getUserName(), "password")));

}

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

@BeforeOAuth2Context
@OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class)
public void setUpUserAccounts() {

    // If running against vcap we don't want to run these tests because they create new user accounts
    // Assume.assumeTrue(!testAccounts.isProfileActive("vcap"));

    RestOperations client = serverRunning.getRestTemplate();

    ScimUser user = new ScimUser();
    user.setUserName(JOE);/*w w w. j a v  a 2 s  . c o  m*/
    user.setName(new ScimUser.Name("Joe", "User"));
    user.addEmail("joe@blah.com");
    user.setGroups(Arrays.asList(new Group(null, "uaa.user"), new Group(null, "orgs.foo")));

    ResponseEntity<ScimUser> newuser = client.postForEntity(serverRunning.getUrl(userEndpoint), user,
            ScimUser.class);

    joe = newuser.getBody();
    assertEquals(JOE, joe.getUserName());

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

    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());

    // The implicit grant for vmc requires extra parameters in the authorization request
    context.setParameters(Collections.singletonMap("credentials",
            testAccounts.getJsonCredentials(joe.getUserName(), "password")));

}

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

@BeforeOAuth2Context
@OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class)
public void setUpUserAccounts() {

    // If running against vcap we don't want to run these tests because they
    // create new user accounts
    Assume.assumeTrue(!testAccounts.isProfileActive("vcap"));

    RestOperations client = serverRunning.getRestTemplate();

    ScimUser user = new ScimUser();
    user.setPassword("password");
    user.setUserName(JOE);/*from   w w w.  ja va  2 s .c o  m*/
    user.setName(new ScimUser.Name("Joe", "User"));
    user.addEmail("joe@blah.com");
    user.setVerified(true);

    userForLoginServer = new ScimUser();
    userForLoginServer.setPassword("password");
    userForLoginServer.setUserName(LOGIN_SERVER_JOE);
    userForLoginServer.setName(new ScimUser.Name("Joe_login_server", "User"));
    userForLoginServer.addEmail("joe_ls@blah.com");
    userForLoginServer.setVerified(true);
    userForLoginServer.setOrigin(LOGIN_SERVER);

    ResponseEntity<ScimUser> newuser = client.postForEntity(serverRunning.getUrl(userEndpoint), user,
            ScimUser.class);
    userForLoginServer = client
            .postForEntity(serverRunning.getUrl(userEndpoint), userForLoginServer, ScimUser.class).getBody();

    joe = newuser.getBody();
    assertEquals(JOE, joe.getUserName());

    PasswordChangeRequest change = new PasswordChangeRequest();
    change.setPassword("Passwo3d");

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

    // The implicit grant for cf requires extra parameters in the
    // authorization request
    context.setParameters(Collections.singletonMap("credentials",
            testAccounts.getJsonCredentials(joe.getUserName(), "Passwo3d")));

}