Example usage for org.springframework.http HttpMethod PUT

List of usage examples for org.springframework.http HttpMethod PUT

Introduction

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

Prototype

HttpMethod PUT

To view the source code for org.springframework.http HttpMethod PUT.

Click Source Link

Usage

From source file:org.apache.servicecomb.demo.jaxrs.client.JaxrsClient.java

@SuppressWarnings({ "rawtypes" })
private static void testValidatorSayHiFail(RestTemplate template, String cseUrlPrefix) {
    boolean isExcep = false;
    try {/*from w ww  . j a v a  2  s .  c o m*/
        template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "te");
    } catch (InvocationException e) {
        isExcep = true;
        TestMgr.check(400, e.getStatus().getStatusCode());
        TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase());
        // Message dependends on locale, so just check the short part.
        Map data = (Map) e.getErrorData();
        TestMgr.check(true, data.get("message").toString().contains("propertyPath=sayHi.name"));
    }
    TestMgr.check(true, isExcep);
}

From source file:org.apache.servicecomb.demo.jaxrs.client.JaxrsClient.java

private static void testValidatorSayHiSuccess(RestTemplate template, String cseUrlPrefix) {
    ResponseEntity<String> responseEntity = template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT,
            null, String.class, "world");
    TestMgr.check(202, responseEntity.getStatusCode());
    TestMgr.check("world sayhi", responseEntity.getBody());
}

From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientImpl.java

@Override
public void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback)
        throws IOException {
    Assert.notNull(appName, "AppName must not be null");
    Assert.notNull(archive, "Archive must not be null");
    UUID appId = getAppId(appName);

    if (callback == null) {
        callback = UploadStatusCallback.NONE;
    }//from ww w  .j  a  v a  2  s. c  o  m
    CloudResources knownRemoteResources = getKnownRemoteResources(archive);
    callback.onCheckResources();
    callback.onMatchedFileNames(knownRemoteResources.getFilenames());
    UploadApplicationPayload payload = new UploadApplicationPayload(archive, knownRemoteResources);
    callback.onProcessMatchedResources(payload.getTotalUncompressedSize());
    HttpEntity<?> entity = generatePartialResourceRequest(payload, knownRemoteResources);
    ResponseEntity<Map<String, Object>> responseEntity = getRestTemplate().exchange(
            getUrl("/v2/apps/{guid}/bits?async=true"), HttpMethod.PUT, entity,
            new ParameterizedTypeReference<Map<String, Object>>() {
            }, appId);
    processAsyncJob(responseEntity.getBody(), callback);
}

From source file:org.cloudfoundry.identity.uaa.api.common.impl.UaaConnectionHelper.java

/**
 * Do an HTTP PUT//from ww  w.  j a  va2s . co  m
 *
 * @param uri the URI of the endpoint (relative to the base URL set in the constructor)
 * @param body the request body
 * @param responseType the object type to be returned
 * @param uriVariables any uri variables
 * @return the response body
 * @see #exchange(HttpMethod, Object, String, ParameterizedTypeReference, Object...)
 */
public <RequestType, ResponseType> ResponseType put(String uri, RequestType body,
        ParameterizedTypeReference<ResponseType> responseType, Object... uriVariables) {
    return exchange(HttpMethod.PUT, body, uri, responseType, uriVariables);
}

From source file:org.cloudfoundry.identity.uaa.api.common.impl.UaaConnectionHelper.java

/**
 * Do an HTTP PUT with SCIM features. SCIM requires PUT requests of a SCIM object have the version of the object set
 * as the <code>If-Match</code> request header.
 *
 * @param uri the URI of the endpoint (relative to the base URL set in the constructor)
 * @param body the request body// w w  w  . java 2  s.c o m
 * @param responseType the object type to be returned
 * @param uriVariables any uri variables
 * @return the response body
 * @see #exchange(HttpMethod, HttpHeaders, Object, String, ParameterizedTypeReference, Object...)
 */
public <RequestType extends ScimCore, ResponseType> ResponseType putScimObject(String uri, RequestType body,
        ParameterizedTypeReference<ResponseType> responseType, Object... uriVariables) {
    HttpHeaders headers = new HttpHeaders();
    headers.set("if-match", String.valueOf(body.getMeta().getVersion()));

    return exchange(HttpMethod.PUT, headers, body, uri, responseType, uriVariables);
}

From source file:org.cloudfoundry.identity.uaa.integration.feature.SamlLoginWithLocalIdpIT.java

public static SamlServiceProvider createOrUpdateSamlServiceProvider(String accessToken, String url,
        SamlServiceProvider provider) {/*from   ww w .j av  a 2  s .c om*/
    RestTemplate client = new RestTemplate();
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
    headers.add("Authorization", "bearer " + accessToken);
    headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
    headers.add(IdentityZoneSwitchingFilter.HEADER, provider.getIdentityZoneId());
    List<SamlServiceProvider> existing = getSamlServiceProviders(accessToken, url,
            provider.getIdentityZoneId());
    if (existing != null) {
        for (SamlServiceProvider p : existing) {
            if (p.getEntityId().equals(provider.getEntityId())
                    && p.getIdentityZoneId().equals(provider.getIdentityZoneId())) {
                provider.setId(p.getId());
                HttpEntity<SamlServiceProvider> putHeaders = new HttpEntity<SamlServiceProvider>(provider,
                        headers);
                ResponseEntity<String> providerPut = client.exchange(url + "/saml/service-providers/{id}",
                        HttpMethod.PUT, putHeaders, String.class, provider.getId());
                if (providerPut.getStatusCode() == HttpStatus.OK) {
                    return JsonUtils.readValue(providerPut.getBody(), SamlServiceProvider.class);
                }
            }
        }
    }

    HttpEntity<SamlServiceProvider> postHeaders = new HttpEntity<SamlServiceProvider>(provider, headers);
    ResponseEntity<String> providerPost = client.exchange(url + "/saml/service-providers/{id}", HttpMethod.POST,
            postHeaders, String.class, provider.getId());
    if (providerPost.getStatusCode() == HttpStatus.CREATED) {
        return JsonUtils.readValue(providerPost.getBody(), SamlServiceProvider.class);
    }
    throw new IllegalStateException(
            "Invalid result code returned, unable to create identity provider:" + providerPost.getStatusCode());
}

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  .  j a v  a2 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")));

}

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

private ScimGroup updateGroup(String id, String name, ScimGroupMember... members) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("If-Match", "*");
    ScimGroup g = new ScimGroup(null, name, IdentityZoneHolder.get().getId());
    List<ScimGroupMember> m = members != null ? Arrays.asList(members)
            : Collections.<ScimGroupMember>emptyList();
    g.setMembers(m);//from   w w w  . ja  v a2  s  .  co  m
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> r = client.exchange(serverRunning.getUrl(groupEndpoint + "/{id}"), HttpMethod.PUT,
            new HttpEntity<>(g, headers), Map.class, id);
    logger.warn(r.getBody());
    ScimGroup g1 = client.exchange(serverRunning.getUrl(groupEndpoint + "/{id}"), HttpMethod.PUT,
            new HttpEntity<>(g, headers), ScimGroup.class, id).getBody();
    assertEquals(name, g1.getDisplayName());
    assertEquals(m.size(), g1.getMembers().size());
    return g1;
}

From source file:org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils.java

public static ScimUser updateUser(String token, String url, ScimUser user) {
    RestTemplate template = new RestTemplate();
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("Accept", APPLICATION_JSON_VALUE);
    headers.add("Authorization", "bearer " + token);
    headers.add("Content-Type", APPLICATION_JSON_VALUE);
    headers.add("If-Match", String.valueOf(user.getVersion()));
    HttpEntity getHeaders = new HttpEntity(user, headers);
    ResponseEntity<ScimUser> userInfoGet = template.exchange(url + "/Users/" + user.getId(), HttpMethod.PUT,
            getHeaders, ScimUser.class);
    if (userInfoGet.getStatusCode() == HttpStatus.OK) {
        return userInfoGet.getBody();
    }/*from   w  ww .  j  ava  2s . com*/
    throw new RuntimeException("Invalid return code:" + userInfoGet.getStatusCode());
}

From source file:org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils.java

public static ScimGroup updateGroup(String token, String zoneId, String url, ScimGroup group) {
    RestTemplate template = new RestTemplate();
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("Accept", APPLICATION_JSON_VALUE);
    headers.add("Authorization", "bearer " + token);
    headers.add("If-Match", "*");
    headers.add("Content-Type", APPLICATION_JSON_VALUE);
    if (StringUtils.hasText(zoneId)) {
        headers.add(IdentityZoneSwitchingFilter.HEADER, zoneId);
    }//from w  w w  .  ja  v a 2 s. c o  m
    ResponseEntity<ScimGroup> updateGroup = template.exchange(url + "/Groups/{groupId}", HttpMethod.PUT,
            new HttpEntity(JsonUtils.writeValueAsBytes(group), headers), ScimGroup.class, group.getId());
    assertEquals(HttpStatus.OK, updateGroup.getStatusCode());
    return updateGroup.getBody();
}