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.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info,
        InstanceStatus overriddenStatus) {
    String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status=" + info.getStatus().toString()
            + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString()
            + (overriddenStatus != null ? "&overriddenstatus=" + overriddenStatus.name() : "");

    ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null,
            InstanceInfo.class);

    EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(
            response.getStatusCodeValue(), InstanceInfo.class).headers(headersOf(response));

    if (response.hasBody())
        eurekaResponseBuilder.entity(response.getBody());

    return eurekaResponseBuilder.build();
}

From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

@Override
public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus,
        InstanceInfo info) {//from w  w w. j a  va2s  . c  o  m
    String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status=" + newStatus.name()
            + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString();

    ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null, Void.class);

    return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
}

From source file:org.springframework.cloud.vault.util.PrepareVault.java

/**
 * Initialize Vault and unseal the vault.
 *
 * @return the root token./*from   ww  w.ja v  a  2s .c  om*/
 */
public VaultToken initializeVault() {

    Assert.notNull(vaultProperties, "VaultProperties must not be null");

    Map<String, String> parameters = parameters(vaultProperties);

    int createKeys = 2;
    int requiredKeys = 2;

    InitializeVault initializeVault = InitializeVault.of(createKeys, requiredKeys);

    ResponseEntity<VaultInitialized> initResponse = restTemplate.exchange(INITIALIZE_URL_TEMPLATE,
            HttpMethod.PUT, new HttpEntity<>(initializeVault), VaultInitialized.class, parameters);

    if (!initResponse.getStatusCode().is2xxSuccessful()) {
        throw new IllegalStateException("Cannot initialize vault: " + initResponse.toString());
    }
    VaultInitialized initialized = initResponse.getBody();

    for (int i = 0; i < requiredKeys; i++) {

        UnsealKey unsealKey = UnsealKey.of(initialized.getKeys().get(i));
        ResponseEntity<UnsealProgress> unsealResponse = restTemplate.exchange(UNSEAL_URL_TEMPLATE,
                HttpMethod.PUT, new HttpEntity<>(unsealKey), UnsealProgress.class, parameters);

        UnsealProgress unsealProgress = unsealResponse.getBody();
        if (!unsealProgress.isSealed()) {
            break;
        }
    }

    return VaultToken.of(initialized.getRootToken());
}

From source file:org.springframework.cloud.vault.util.PrepareVault.java

/**
 * Write key-value data to a path in Vault.
 *
 * @param httpMethod//from   w  w  w.  ja va  2 s.c  om
 * @param path
 * @param data
 */
public void write(HttpMethod httpMethod, String path, Map<String, ?> data) {

    Assert.notNull(httpMethod, "HttpMethod must not be null");
    Assert.hasText(path, "Path must not be empty");
    Assert.notNull(data, "Data must not be null");

    HttpHeaders headers = authenticatedHeaders();

    Map<String, String> parameters = parameters(vaultProperties);
    parameters.put("path", path);

    ResponseEntity<String> exchange = restTemplate.exchange(WRITE_URL_TEMPLATE, HttpMethod.PUT,
            new HttpEntity<Object>(data, headers), String.class, parameters);

    if (!exchange.getStatusCode().is2xxSuccessful()) {
        throw new IllegalStateException(String.format("Cannot write to %s: %s", path, exchange.getBody()));
    }
}

From source file:org.springframework.data.document.couchdb.core.CouchTemplate.java

public void save(String id, Object document) {
    Assert.notNull(document, "document must not be null for save");
    HttpEntity<?> httpEntity = createHttpEntity(document);
    try {//from w w  w .jav  a 2s .  c  o  m
        ResponseEntity<Map> response = restOperations.exchange(defaultDocumentUrl, HttpMethod.PUT, httpEntity,
                Map.class, id);
        //TODO update the document revision id on the object from the returned value
        //TODO better exception translation
    } catch (RestClientException e) {
        throw new UncategorizedCouchDataAccessException(e);
    }

}

From source file:org.springframework.data.document.couchdb.core.CouchTemplate.java

public void save(URI uri, Object document) {
    Assert.notNull(document, "document must not be null for save");
    Assert.notNull(uri, "URI must not be null for save");
    HttpEntity<?> httpEntity = createHttpEntity(document);
    try {/*  w  w  w .  j a  v a 2  s .c o m*/
        ResponseEntity<Map> response = restOperations.exchange(uri, HttpMethod.PUT, httpEntity, Map.class);
        //TODO update the document revision id on the object from the returned value
        //TODO better exception translation
    } catch (RestClientException e) {
        throw new UncategorizedCouchDataAccessException(e);
    }

}

From source file:org.springframework.data.keyvalue.riak.client.RiakRestClient.java

@Override
public void setBucketProperties(String bucket, RiakBucketProperty<?>... bucketProperties) throws RiakException {
    Assert.notNull(bucket, "The bucket cannot be null");
    Assert.notNull(bucketProperties, "At least one bucket property must be set");
    executeRiak(HttpMethod.PUT,
            Collections.singletonMap(RiakConstants.PROPS, new RiakBucketProperties(bucketProperties)), null,
            byte[].class, bucket);

}

From source file:org.springframework.data.keyvalue.riak.client.RiakRestClient.java

@Override
public void storeKeyValue(String bucket, String key, Object value, RiakPutParameter... params)
        throws RiakException {
    executeRiak(HttpMethod.PUT, value, params, byte[].class, bucket, key);
}

From source file:org.springframework.social.box.api.impl.BoxOperations.java

protected <T, E extends Enum<E>> T boxOperation(HttpMethod httpMethod, String operation, List<E> fields,
        String body, Class<T> domainClass) {
    URIBuilder uriBuilder = URIBuilder.fromUri(BOX_API_URL + operation);
    appendFieldsParameter(fields, uriBuilder);

    switch (httpMethod) {
    case GET://  w  w w . j  a va  2s. c  o m
        return restTemplate.getForObject(uriBuilder.build(), domainClass);
    case POST:
        return restTemplate.postForObject(uriBuilder.build(), body, domainClass);
    case PUT:
        return restTemplate
                .exchange(uriBuilder.build(), HttpMethod.PUT, new HttpEntity<String>(body), domainClass)
                .getBody();
    case DELETE:
        restTemplate.delete(uriBuilder.build());
        return null;
    default:
        throw new UnsupportedOperationException("This http method is not supported by spring-social-box");
    }
}

From source file:org.springframework.social.box.api.impl.FileTemplate.java

@Override
public BoxFile updateFile(String fileId, String newName, String newDescription, List<String> newTags,
        List<BoxFileFields> fields) {
    try {//from  w ww .  j ava  2  s. co  m
        return boxOperation(HttpMethod.PUT, FILE_OPERATION + fileId, fields,
                mapper.writeValueAsString(new BoxFileUpdate(newName, newDescription, newTags)), BoxFile.class);
    } catch (JsonProcessingException e) {
        throw new UncategorizedApiException(BOX_PROVIDER_NAME, "spring-social-box internal error", e);
    }
}