Example usage for org.springframework.http HttpEntity EMPTY

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

Introduction

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

Prototype

HttpEntity EMPTY

To view the source code for org.springframework.http HttpEntity EMPTY.

Click Source Link

Document

The empty HttpEntity , with no body or headers.

Usage

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

private void processAsyncJob(Map<String, Object> jobResource, UploadStatusCallback callback) {
    CloudJob job = resourceMapper.mapResource(jobResource, CloudJob.class);
    do {/* w w w.j  a  v a 2s.  com*/
        boolean unsubscribe = callback.onProgress(job.getStatus().toString());
        if (unsubscribe) {
            return;
        }
        if (job.getStatus() == CloudJob.Status.FAILED) {
            return;
        }

        try {
            Thread.sleep(JOB_POLLING_PERIOD);
        } catch (InterruptedException ex) {
            return;
        }

        ResponseEntity<Map<String, Object>> jobProgressEntity = getRestTemplate().exchange(
                getUrl(job.getMeta().getUrl()), HttpMethod.GET, HttpEntity.EMPTY,
                new ParameterizedTypeReference<Map<String, Object>>() {
                });
        job = resourceMapper.mapResource(jobProgressEntity.getBody(), CloudJob.class);
    } while (job.getStatus() != CloudJob.Status.FINISHED);
}

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

private void doDeleteService(CloudService cloudService) {
    List<UUID> appIds = getAppsBoundToService(cloudService);
    if (appIds.size() > 0) {
        for (UUID appId : appIds) {
            doUnbindService(appId, cloudService.getMeta().getGuid());
        }/*from   w  w w  .j av a2s. com*/
    }
    ResponseEntity<Map<String, Object>> response = getRestTemplate().exchange(
            getUrl("/v2/service_instances/{guid}?async=true"), HttpMethod.DELETE, HttpEntity.EMPTY,
            new ParameterizedTypeReference<Map<String, Object>>() {
            }, cloudService.getMeta().getGuid());
    waitForAsyncJobCompletion(response.getBody());
}

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

private void waitForAsyncJobCompletion(Map<String, Object> jobResponse) {
    long timeout = System.currentTimeMillis() + JOB_TIMEOUT;
    while (System.currentTimeMillis() < timeout) {
        CloudJob job = resourceMapper.mapResource(jobResponse, CloudJob.class);

        if (job.getStatus() == CloudJob.Status.FINISHED) {
            return;
        }//  w  w  w  .  j a v a2 s  .c o  m

        if (job.getStatus() == CloudJob.Status.FAILED) {
            throw new CloudOperationException(job.getErrorDetails().getDescription());
        }

        try {
            Thread.sleep(JOB_POLLING_PERIOD);
        } catch (InterruptedException e) {
            return;
        }

        jobResponse = getRestTemplate().exchange(getUrl(job.getMeta().getUrl()), HttpMethod.GET,
                HttpEntity.EMPTY, new ParameterizedTypeReference<Map<String, Object>>() {
                }).getBody();
    }
}

From source file:org.jgrades.rest.client.lic.LicenceManagerServiceClient.java

@Override
public List<Licence> getAll() {
    String serviceUrl = backendBaseUrl + "/licence";
    ResponseEntity<List<Licence>> response = restTemplate.exchange(serviceUrl, HttpMethod.GET, HttpEntity.EMPTY,
            new ParameterizedTypeReference<List<Licence>>() {
            });/*  w  w w .j a  v a2  s.c  om*/
    return response.getBody();
}

From source file:org.jgrades.rest.client.lic.LicenceManagerServiceClient.java

@Override
public Licence get(Long uid) {
    String serviceUrl = backendBaseUrl + "/licence/" + uid;
    ResponseEntity<Licence> response = restTemplate.exchange(serviceUrl, HttpMethod.GET, HttpEntity.EMPTY,
            Licence.class);
    return response.getBody();
}

From source file:org.jgrades.rest.client.lic.LicenceManagerServiceClient.java

@Override
public void uninstall(Long uid) {
    String serviceUrl = backendBaseUrl + "/licence/" + uid;
    restTemplate.exchange(serviceUrl, HttpMethod.DELETE, HttpEntity.EMPTY, Void.class);
}

From source file:org.jgrades.rest.client.StatefullRestTemplate.java

private Object insertCookieToHeaderIfApplicable(Object requestBody) {
    HttpEntity<?> httpEntity;//w  w  w . ja  v a 2s.co m

    if (requestBody instanceof HttpEntity) {
        httpEntity = (HttpEntity<?>) requestBody;
    } else if (requestBody != null) {
        httpEntity = new HttpEntity<Object>(requestBody);
    } else {
        httpEntity = HttpEntity.EMPTY;
    }

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.putAll(httpEntity.getHeaders());

    httpHeaders.set("Accept", MediaType.APPLICATION_JSON_VALUE);
    if (httpHeaders.getContentType() == null) {
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    }

    if (StringUtils.isNotEmpty(cookie)) {
        httpHeaders.add("Cookie", cookie);
    }

    return new HttpEntity<>(httpEntity.getBody(), httpHeaders);
}

From source file:org.springframework.social.gitlab.api.core.impl.GitlabTemplate.java

@Override
public <T> PagedList<T> getForPage(URI url, Class<T> responseType) {

    ParameterizedTypeReference<List<T>> listType = createTypeReference(responseType);
    ResponseEntity<List<T>> response = restOperations().exchange(url, HttpMethod.GET, HttpEntity.EMPTY,
            listType);/*ww w. j av a2s . c  o  m*/
    Paging paging = linkHeaderParser.buildPaging(response.getHeaders().getFirst("Link"));

    return new PagedList<>(response.getBody(), paging);
}

From source file:org.springframework.social.gitlab.api.core.impl.GitlabTemplate.java

@Override
public <T> List<T> getForList(URI url, final Class<T> responseType) {
    ParameterizedTypeReference<List<T>> listType = createTypeReference(responseType);
    ResponseEntity<List<T>> response = restOperations().exchange(url, HttpMethod.GET, HttpEntity.EMPTY,
            listType);/*  w  w  w  .j a  v  a  2 s . c  om*/

    return response.getBody();
}

From source file:org.springframework.vault.authentication.AuthenticationStepsExecutor.java

private static HttpEntity<?> getEntity(HttpEntity<?> entity, @Nullable Object state) {

    if (entity == null) {
        return state == null ? HttpEntity.EMPTY : new HttpEntity<>(state);
    }/*from w w  w  .j  av  a  2s .c o m*/

    if (entity.getBody() == null && state != null) {
        return new HttpEntity<>(state, entity.getHeaders());
    }

    return entity;
}