Example usage for org.springframework.http HttpMethod DELETE

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

Introduction

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

Prototype

HttpMethod DELETE

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

Click Source Link

Usage

From source file:org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete.java

public ResourceWebScriptDelete() {
    super();
    setHttpMethod(HttpMethod.DELETE);
    setParamsExtractor(this);
}

From source file:org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete.java

@Override
public Void execute(final ResourceWithMetadata resource, final Params params, final WebScriptResponse res,
        boolean isReadOnly) {
    final ResourceOperation operation = resource.getMetaData().getOperation(HttpMethod.DELETE);
    final WithResponse callBack = new WithResponse(operation.getSuccessStatus(), DEFAULT_JSON_CONTENT,
            CACHE_NEVER);//from ww  w. j a  va  2  s.  co  m
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
        @Override
        public Void execute() throws Throwable {
            executeAction(resource, params, callBack); //ignore return result
            return null;
        }
    }, false, true);
    setResponse(res, callBack);
    return null;

}

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

private static void testExchange(RestTemplate template, String cseUrlPrefix) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", MediaType.APPLICATION_JSON);
    Person person = new Person();
    person.setName("world");
    HttpEntity<Person> requestEntity = new HttpEntity<>(person, headers);
    ResponseEntity<Person> resEntity = template.exchange(cseUrlPrefix + "/compute/sayhello", HttpMethod.POST,
            requestEntity, Person.class);
    TestMgr.check("hello world", resEntity.getBody());

    ResponseEntity<String> resEntity2 = template.exchange(cseUrlPrefix + "/compute/addstring?s=abc&s=def",
            HttpMethod.DELETE, null, String.class);
    TestMgr.check("abcdef", resEntity2.getBody());
}

From source file:org.apache.servicecomb.demo.springmvc.tests.SpringMvcIntegrationTestBase.java

@Test
public void ableToDeleteWithQueryString() throws Exception {
    ResponseEntity<String> responseEntity = restTemplate.exchange(codeFirstUrl + "addstring?s=a&s=b",
            HttpMethod.DELETE, null, String.class);

    assertThat(responseEntity.getBody(), is("ab"));
    ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
            .exchange(codeFirstUrl + "addstring?s=a&s=b", HttpMethod.DELETE, null, String.class);
    ResponseEntity<String> futureResponse = listenableFuture.get();
    assertThat(futureResponse.getBody(), is("ab"));
}

From source file:org.apache.zeppelin.livy.BaseLivyInterprereter.java

private String callRestAPI(String targetURL, String method, String jsonData) throws LivyException {
    targetURL = livyURL + targetURL;//from ww  w .j ava  2s.  c om
    LOGGER.debug("Call rest api in {}, method: {}, jsonData: {}", targetURL, method, jsonData);
    RestTemplate restTemplate = getRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    headers.add("X-Requested-By", "zeppelin");
    ResponseEntity<String> response = null;
    try {
        if (method.equals("POST")) {
            HttpEntity<String> entity = new HttpEntity<>(jsonData, headers);
            response = restTemplate.exchange(targetURL, HttpMethod.POST, entity, String.class);
        } else if (method.equals("GET")) {
            HttpEntity<String> entity = new HttpEntity<>(headers);
            response = restTemplate.exchange(targetURL, HttpMethod.GET, entity, String.class);
        } else if (method.equals("DELETE")) {
            HttpEntity<String> entity = new HttpEntity<>(headers);
            response = restTemplate.exchange(targetURL, HttpMethod.DELETE, entity, String.class);
        }
    } catch (HttpClientErrorException e) {
        response = new ResponseEntity(e.getResponseBodyAsString(), e.getStatusCode());
        LOGGER.error(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                e.getResponseBodyAsString()));
    }
    if (response == null) {
        throw new LivyException("No http response returned");
    }
    LOGGER.debug("Get response, StatusCode: {}, responseBody: {}", response.getStatusCode(),
            response.getBody());
    if (response.getStatusCode().value() == 200 || response.getStatusCode().value() == 201) {
        return response.getBody();
    } else if (response.getStatusCode().value() == 404) {
        if (response.getBody().matches("\"Session '\\d+' not found.\"")) {
            throw new SessionNotFoundException(response.getBody());
        } else {
            throw new APINotFoundException(
                    "No rest api found for " + targetURL + ", " + response.getStatusCode());
        }
    } else {
        String responseString = response.getBody();
        if (responseString.contains("CreateInteractiveRequest[\\\"master\\\"]")) {
            return responseString;
        }
        throw new LivyException(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                responseString));
    }
}

From source file:org.apache.zeppelin.livy.BaseLivyInterpreter.java

private String callRestAPI(String targetURL, String method, String jsonData) throws LivyException {
    targetURL = livyURL + targetURL;//from  w w  w .  jav a2  s  .c o m
    LOGGER.debug("Call rest api in {}, method: {}, jsonData: {}", targetURL, method, jsonData);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE);
    headers.add("X-Requested-By", "zeppelin");
    for (Map.Entry<String, String> entry : customHeaders.entrySet()) {
        headers.add(entry.getKey(), entry.getValue());
    }
    ResponseEntity<String> response = null;
    try {
        if (method.equals("POST")) {
            HttpEntity<String> entity = new HttpEntity<>(jsonData, headers);
            response = restTemplate.exchange(targetURL, HttpMethod.POST, entity, String.class);
        } else if (method.equals("GET")) {
            HttpEntity<String> entity = new HttpEntity<>(headers);
            response = restTemplate.exchange(targetURL, HttpMethod.GET, entity, String.class);
        } else if (method.equals("DELETE")) {
            HttpEntity<String> entity = new HttpEntity<>(headers);
            response = restTemplate.exchange(targetURL, HttpMethod.DELETE, entity, String.class);
        }
    } catch (HttpClientErrorException e) {
        response = new ResponseEntity(e.getResponseBodyAsString(), e.getStatusCode());
        LOGGER.error(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                e.getResponseBodyAsString()));
    } catch (RestClientException e) {
        // Exception happens when kerberos is enabled.
        if (e.getCause() instanceof HttpClientErrorException) {
            HttpClientErrorException cause = (HttpClientErrorException) e.getCause();
            if (cause.getResponseBodyAsString().matches(SESSION_NOT_FOUND_PATTERN)) {
                throw new SessionNotFoundException(cause.getResponseBodyAsString());
            }
            throw new LivyException(cause.getResponseBodyAsString() + "\n"
                    + ExceptionUtils.getFullStackTrace(ExceptionUtils.getRootCause(e)));
        }
        if (e instanceof HttpServerErrorException) {
            HttpServerErrorException errorException = (HttpServerErrorException) e;
            String errorResponse = errorException.getResponseBodyAsString();
            if (errorResponse.contains("Session is in state dead")) {
                throw new SessionDeadException();
            }
            throw new LivyException(errorResponse, e);
        }
        throw new LivyException(e);
    }
    if (response == null) {
        throw new LivyException("No http response returned");
    }
    LOGGER.debug("Get response, StatusCode: {}, responseBody: {}", response.getStatusCode(),
            response.getBody());
    if (response.getStatusCode().value() == 200 || response.getStatusCode().value() == 201) {
        return response.getBody();
    } else if (response.getStatusCode().value() == 404) {
        if (response.getBody().matches(SESSION_NOT_FOUND_PATTERN)) {
            throw new SessionNotFoundException(response.getBody());
        } else {
            throw new APINotFoundException(
                    "No rest api found for " + targetURL + ", " + response.getStatusCode());
        }
    } else {
        String responseString = response.getBody();
        if (responseString.contains("CreateInteractiveRequest[\\\"master\\\"]")) {
            return responseString;
        }
        throw new LivyException(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                responseString));
    }
}

From source file:org.apache.zeppelin.livy.LivyHelper.java

protected String executeHTTP(String targetURL, String method, String jsonData, String paragraphId)
        throws Exception {
    LOGGER.debug("Call rest api in {}, method: {}, jsonData: {}", targetURL, method, jsonData);
    RestTemplate restTemplate = getRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    headers.add("X-Requested-By", "zeppelin");
    ResponseEntity<String> response = null;
    try {// w ww  . j  a va 2s .  c  o m
        if (method.equals("POST")) {
            HttpEntity<String> entity = new HttpEntity<>(jsonData, headers);

            response = restTemplate.exchange(targetURL, HttpMethod.POST, entity, String.class);
            paragraphHttpMap.put(paragraphId, response);
        } else if (method.equals("GET")) {
            HttpEntity<String> entity = new HttpEntity<>(headers);
            response = restTemplate.exchange(targetURL, HttpMethod.GET, entity, String.class);
            paragraphHttpMap.put(paragraphId, response);
        } else if (method.equals("DELETE")) {
            HttpEntity<String> entity = new HttpEntity<>(headers);
            response = restTemplate.exchange(targetURL, HttpMethod.DELETE, entity, String.class);
        }
    } catch (HttpClientErrorException e) {
        response = new ResponseEntity(e.getResponseBodyAsString(), e.getStatusCode());
        LOGGER.error(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                e.getResponseBodyAsString()));
    }
    if (response == null) {
        return null;
    }

    if (response.getStatusCode().value() == 200 || response.getStatusCode().value() == 201
            || response.getStatusCode().value() == 404) {
        return response.getBody();
    } else {
        String responseString = response.getBody();
        if (responseString.contains("CreateInteractiveRequest[\\\"master\\\"]")) {
            return responseString;
        }
        LOGGER.error(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                responseString));
        throw new Exception(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(),
                responseString));
    }
}

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  www  .  j  a  v a  2s . c om
    }
    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.identity.uaa.api.common.impl.UaaConnectionHelper.java

/**
 * Do an HTTP DELETE//  w  w  w  .ja va 2 s .com
 * 
 * @param uri the URI of the endpoint (relative to the base URL set in the constructor)
 * @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 <ResponseType> ResponseType delete(String uri, ParameterizedTypeReference<ResponseType> responseType,
        Object... uriVariables) {
    return exchange(HttpMethod.DELETE, null, uri, responseType, uriVariables);
}

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

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