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.zalando.boot.etcd.EtcdClientTest.java

@Test
public void compareAndDeleteWithPrevValue() throws EtcdException {
    server.expect(//from  w  w  w .jav a  2  s .  com
            MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevValue=Hello%20etcd"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)).andRespond(
                    MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
                            MediaType.APPLICATION_JSON));

    EtcdResponse response = client.compareAndDelete("sample", "Hello etcd");
    Assert.assertNotNull("response", response);

    server.verify();
}

From source file:access.deploy.Deployer.java

/**
 * Deletes a deployment, as specified by its Id. This will remove the Deployment from GeoServer, delete the lease
 * and the deployment from the Database.
 * /*from w  w  w.  j  a  v  a  2 s  .  c om*/
 * @param deploymentId
 *            The Id of the deployment.
 * @throws GeoServerException
 * @throws InvalidInputException
 */
public void undeploy(String deploymentId) throws GeoServerException, InvalidInputException {
    // Get the Deployment from the Database to delete. If the Deployment had
    // a lease, then the lease is automatically removed when the deployment
    // is deleted.
    Deployment deployment = accessor.getDeployment(deploymentId);
    if (deployment == null) {
        throw new InvalidInputException("Deployment does not exist matching Id " + deploymentId);
    }
    // Delete the Deployment Layer from GeoServer
    authHeaders.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> request = new HttpEntity<>(authHeaders.get());
    String url = String.format("%s/rest/layers/%s", accessUtilities.getGeoServerBaseUrl(),
            deployment.getLayer());
    try {
        pzLogger.log(String.format("Deleting Deployment from Resource %s", url), Severity.INFORMATIONAL,
                new AuditElement(ACCESS, "undeployGeoServerLayer", deploymentId));
        restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
    } catch (HttpClientErrorException | HttpServerErrorException exception) {
        // Check the status code. If it's a 404, then the layer has likely
        // already been deleted by some other means.
        if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
            String warning = String.format(
                    "Attempted to undeploy GeoServer layer %s while deleting the Deployment Id %s, but the layer was already deleted from GeoServer. This layer may have been removed by some other means. If this was a Vector Source, then this message can be safely ignored.",
                    deployment.getLayer(), deploymentId);
            pzLogger.log(warning, Severity.WARNING);
        } else {
            // Some other exception occurred. Bubble it up.
            String error = String.format(
                    "Error deleting GeoServer Layer for Deployment %s via request %s: Code %s with Error %s",
                    deploymentId, url, exception.getStatusCode(), exception.getResponseBodyAsString());
            pzLogger.log(error, Severity.ERROR,
                    new AuditElement(ACCESS, "failedToDeleteGeoServerLayer", deploymentId));
            LOGGER.error(error, exception);
            throw new GeoServerException(error);
        }
    }

    // If this was a Raster dataset that contained its own unique data store, then delete that Coverage Store.
    url = String.format("%s/rest/workspaces/piazza/coveragestores/%s?purge=all&recurse=true",
            accessUtilities.getGeoServerBaseUrl(), deployment.getDataId());
    try {
        pzLogger.log(String.format("Deleting Coverage Store from Resource %s", url), Severity.INFORMATIONAL,
                new AuditElement(ACCESS, "deleteGeoServerCoverageStore", deployment.getDataId()));
        restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
    } catch (HttpClientErrorException | HttpServerErrorException exception) {
        // Check the status code. If it's a 404, then the layer has likely
        // already been deleted by some other means.
        if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
            String warning = String.format(
                    "Attempted to delete Coverage Store for GeoServer %s while deleting the Deployment Id %s, but the Coverage Store was already deleted from GeoServer. This Store may have been removed by some other means.",
                    deployment.getLayer(), deploymentId);
            pzLogger.log(warning, Severity.WARNING);
        } else {
            // Some other exception occurred. Bubble it up.
            String error = String.format(
                    "Error deleting GeoServer Coverage Store for Deployment %s via request %s: Code %s with Error: %s",
                    deploymentId, url, exception.getStatusCode(), exception.getResponseBodyAsString());
            pzLogger.log(error, Severity.ERROR,
                    new AuditElement(ACCESS, "failedToUndeployLayer", deploymentId));
            LOGGER.error(error, exception);
            throw new GeoServerException(error);
        }
    }

    pzLogger.log(String.format("Successfully deleted Deployment for %s", deploymentId), Severity.INFORMATIONAL);
    // Remove the Deployment from the Database
    accessor.deleteDeployment(deployment);
}

From source file:gateway.controller.DeploymentController.java

/**
 * Deletes Deployment information for an active deployment.
 * /*ww w .  j a  va2 s . c o m*/
 * @see http://pz-swagger.stage.geointservices.io/#!/Deployment/ delete_deployment_deploymentId
 * 
 * @param deploymentId
 *            The Id of the deployment to delete.
 * @param user
 *            The user requesting the deployment information
 * @return OK confirmation if deleted, or an ErrorResponse if exceptions occur
 */
@RequestMapping(value = "/deployment/{deploymentId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Remove an active Deployment", notes = "If a user wishes to delete a Deployment before its lease time is up (and automatic deletion could take place) then this endpoint provides a way to do so manually.", tags = "Deployment")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Confirmation that the deployment has been deleted.", response = SuccessResponse.class),
        @ApiResponse(code = 401, message = "Unauthorized", response = ErrorResponse.class),
        @ApiResponse(code = 404, message = "Not Found", response = ErrorResponse.class),
        @ApiResponse(code = 500, message = "Internal Error", response = ErrorResponse.class) })
public ResponseEntity<PiazzaResponse> deleteDeployment(
        @ApiParam(value = "Id of the Deployment to Delete.", required = true) @PathVariable(value = "deploymentId") String deploymentId,
        Principal user) {
    try {
        // Log the request
        logger.log(String.format("User %s requested Deletion for Deployment %s",
                gatewayUtil.getPrincipalName(user), deploymentId), PiazzaLogger.INFO);
        // Broker the request to Pz-Access
        try {
            return new ResponseEntity<PiazzaResponse>(
                    restTemplate.exchange(String.format("%s/%s/%s", ACCESS_URL, "deployment", deploymentId),
                            HttpMethod.DELETE, null, SuccessResponse.class).getBody(),
                    HttpStatus.OK);
        } catch (HttpClientErrorException | HttpServerErrorException hee) {
            LOGGER.error("Error Deleting Deployment.", hee);
            return new ResponseEntity<PiazzaResponse>(
                    gatewayUtil.getErrorResponse(hee.getResponseBodyAsString()), hee.getStatusCode());
        }
    } catch (Exception exception) {
        String error = String.format("Error Deleting Deployment by Id %s by user %s: %s", deploymentId,
                gatewayUtil.getPrincipalName(user), exception.getMessage());
        LOGGER.error(error, exception);
        logger.log(error, PiazzaLogger.ERROR);
        return new ResponseEntity<PiazzaResponse>(new ErrorResponse(error, "Gateway"),
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.cbioportal.session_service.SessionServiceTest.java

@Test
public void deleteSession() throws Exception {
    // first add data
    String data = "\"portal-session\":{\"arg1\":\"first argument\"}";
    ResponseEntity<String> response = addData("msk_portal", "main_session", data);

    // get id//from w w  w . j av  a 2s  .  c o m
    List<String> ids = parseIds(response.getBody());
    assertThat(ids.size(), equalTo(1));
    String id = ids.get(0);

    // get record from database
    response = template.getForEntity(base.toString() + "msk_portal/main_session/" + id, String.class);
    assertThat(expectedResponse(response.getBody(), "msk_portal", "main_session", data), equalTo(true));

    // delete
    response = template.exchange(base.toString() + "msk_portal/main_session/" + id, HttpMethod.DELETE, null,
            String.class);
    assertThat(response.getBody(), equalTo(null));
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));

    // confirm record is gone
    response = template.getForEntity(base.toString() + "msk_portal/main_session/" + id, String.class);
    assertThat(response.getBody(),
            containsString("org.cbioportal.session_service.service.exception.SessionNotFoundException"));
    assertThat(response.getStatusCode(), equalTo(HttpStatus.NOT_FOUND));
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Atomically deletes a key-value pair in etcd.
 * //from  w w  w.  jav a2 s.  c o m
 * @param key
 *            the key
 * @param prevIndex
 *            the modified index of the key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndDelete(final String key, int prevIndex) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("prevIndex", prevIndex);

    return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Atomically deletes a key-value pair in etcd.
 * /*from w  w w.  ja v a2  s  .  c om*/
 * @param key
 *            the key
 * @param prevValue
 *            the previous value of the key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndDelete(final String key, String prevValue) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("prevValue", prevValue);

    return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class);
}

From source file:org.cbioportal.session_service.SessionServiceTest.java

@Test
public void deleteSessionInvalidId() throws Exception {
    ResponseEntity<String> response = template.exchange(base.toString() + "msk_portal/main_session/id",
            HttpMethod.DELETE, null, String.class);
    assertThat(response.getBody(),/*from w  ww  .  j  a  v  a 2  s  . c  o  m*/
            containsString("org.cbioportal.session_service.service.exception.SessionNotFoundException"));
    assertThat(response.getStatusCode(), equalTo(HttpStatus.NOT_FOUND));
}

From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java

@Test(dataProvider = "subjectProvider")
public void testPutGetDeleteSubject(final BaseSubject subject) throws UnsupportedEncodingException {
    ResponseEntity<BaseSubject> responseEntity = null;
    try {/*from  w w w. j ava2 s. c o  m*/
        this.privilegeHelper.putSubject(this.acsAdminRestTemplate, subject, this.acsUrl, this.zone1Headers,
                this.privilegeHelper.getDefaultAttribute());
    } catch (HttpClientErrorException e) {
        Assert.fail("Unable to create subject.");
    }
    String encodedSubjectIdentifier = URLEncoder.encode(subject.getSubjectIdentifier(), "UTF-8");
    URI uri = URI.create(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + encodedSubjectIdentifier);
    try {
        responseEntity = this.acsAdminRestTemplate.exchange(uri, HttpMethod.GET,
                new HttpEntity<>(this.zone1Headers), BaseSubject.class);
        Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);
    } catch (HttpClientErrorException e) {
        Assert.fail("Unable to get subject.");
    }
    try {
        this.acsAdminRestTemplate.exchange(uri, HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers),
                ResponseEntity.class);
        responseEntity = this.acsAdminRestTemplate.exchange(uri, HttpMethod.GET,
                new HttpEntity<>(this.zone1Headers), BaseSubject.class);
        Assert.fail("Subject " + subject.getSubjectIdentifier() + " was not properly deleted");
    } catch (HttpClientErrorException e) {
        Assert.assertEquals(e.getStatusCode(), HttpStatus.NOT_FOUND, "Subject was not deleted.");
    }

}

From source file:org.zalando.boot.etcd.EtcdClientTest.java

@Test
public void deleteDir() throws EtcdException {
    server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?dir=true"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)).andRespond(
                    MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
                            MediaType.APPLICATION_JSON));

    EtcdResponse response = client.deleteDir("sample");
    Assert.assertNotNull("response", response);

    server.verify();//w ww.j av a 2  s.  c  om
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Delete the registration by registration ID
 * @param registrationId the registration ID
 * @return/*from  ww w. ja v  a2s .c  om*/
 */
public ListenableFuture<Void> deleteRegistration(String registrationId) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
    builder.path("v2/registrations/{registrationId}");
    return adapt(
            request(HttpMethod.DELETE, builder.buildAndExpand(registrationId).toUriString(), null, Void.class));
}