List of usage examples for org.springframework.http HttpMethod DELETE
HttpMethod DELETE
To view the source code for org.springframework.http HttpMethod DELETE.
Click Source Link
From source file:gateway.controller.DeploymentController.java
/** * Deletes a Deployment Group. This will delete the Group in the Mongo DB holdings, and also in the GIS Server * instance. Unrecoverable once deleted. * //from w w w .j av a2 s . c o m * @param deploymentGroupId * The Id of the group to delete. * @param user * The user requesting deletion. * @return OK if deleted, Error if not. */ @RequestMapping(value = "/deployment/group/{deploymentGroupId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "Delete a DeploymentGroup.", notes = "Deletes a DeploymentGroup from the Piazza metadata, and the GIS server.", tags = "Deployment") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful deletion of DeploymentGroup.", 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> deleteDeploymentGroup( @PathVariable(value = "deploymentGroupId") String deploymentGroupId, Principal user) { try { // Log the request logger.log(String.format("User %s requested delete of DeploymentGroup %s", gatewayUtil.getPrincipalName(user), deploymentGroupId), PiazzaLogger.INFO); // Broker to access String url = String.format("%s/deployment/group/%s", ACCESS_URL, deploymentGroupId); try { return new ResponseEntity<PiazzaResponse>( restTemplate.exchange(url, HttpMethod.DELETE, null, PiazzaResponse.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 DeploymentGroup %s : %s - exception: %s", deploymentGroupId, 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:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testDeleteRegistration_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/registrations/abcdef")).andExpect(method(HttpMethod.DELETE)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)).andRespond(withNoContent()); ngsiClient.deleteRegistration("abcdef").get(); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Delete the subscription by subscription ID * @param subscriptionId the subscription ID * @return//from w w w .j a va 2 s . co m */ public ListenableFuture<Void> deleteSubscription(String subscriptionId) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/subscriptions/{subscriptionId}"); return adapt( request(HttpMethod.DELETE, builder.buildAndExpand(subscriptionId).toUriString(), null, Void.class)); }
From source file:com.orange.ngsi.client.NgsiRestClientTest.java
@Test public void testDeleteContextSubscription_JSON() throws Exception { String responseBody = json(jsonConverter, createUnsubscribeContextSubscriptionResponseTemperature()); mockServer.expect(requestTo(baseUrl + "/ngsi10/contextSubscriptions/12345678")) .andExpect(method(HttpMethod.DELETE)) .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON)); UnsubscribeContextResponse response = ngsiRestClient.deleteContextSubscription(baseUrl, null, "12345678") .get();// w w w.j a va 2s. c o m this.mockServer.verify(); assertNotNull(response); assertEquals(CodeEnum.CODE_200.getLabel(), response.getStatusCode().getCode()); assertEquals("12345678", response.getSubscriptionId()); }
From source file:gateway.controller.DataController.java
/** * Deletes the Data Resource from Piazza. * // w w w. j a v a 2 s .com * @param dataId * The Id of the data item to delete * @param user * The user submitting the request * @return 200 OK if deleted, error response if not. */ @RequestMapping(value = "/data/{dataId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "Delete Loaded Data", notes = "Deletes an entry to Data that has been previously loaded into Piazza. If the file was hosted by Piazza, then that file will also be deleted.", tags = "Data") @ApiResponses(value = { @ApiResponse(code = 200, message = "Message indicating confirmation of delete", 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> deleteData( @ApiParam(value = "Id of the Data item to Delete.", required = true) @PathVariable(value = "dataId") String dataId, Principal user) { try { // Log the request logger.log(String.format("User %s requested Delete of Data Id %s.", gatewayUtil.getPrincipalName(user), dataId), PiazzaLogger.INFO); // Proxy the request to Pz-ingest try { return new ResponseEntity<PiazzaResponse>( restTemplate.exchange(String.format("%s/%s/%s", INGEST_URL, "data", dataId), HttpMethod.DELETE, null, SuccessResponse.class).getBody(), HttpStatus.OK); } catch (HttpClientErrorException | HttpServerErrorException hee) { LOGGER.error("Error Deleting Data Id " + dataId, hee); return new ResponseEntity<PiazzaResponse>( gatewayUtil.getErrorResponse(hee.getResponseBodyAsString()), hee.getStatusCode()); } } catch (Exception exception) { String error = String.format("Error Deleting Data for item %s by user %s: %s", dataId, 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:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl.java
private void deletePage(final String pageId, final String title) { final SwaggerConfluenceConfig swaggerConfluenceConfig = SWAGGER_CONFLUENCE_CONFIG.get(); final HttpHeaders httpHeaders = buildHttpHeaders(swaggerConfluenceConfig.getAuthentication()); final HttpEntity<String> requestEntity = new HttpEntity<>(httpHeaders); final String path = String.format("/content/%s", pageId); final URI targetUrl = UriComponentsBuilder.fromUriString(swaggerConfluenceConfig.getConfluenceRestApiUrl()) .path(path).queryParam(EXPAND, "page").build().toUri(); final ResponseEntity<String> responseEntity; try {/*from w w w . ja v a 2 s.c o m*/ responseEntity = restTemplate.exchange(targetUrl, HttpMethod.DELETE, requestEntity, String.class); } catch (final HttpClientErrorException e) { throw new ConfluenceAPIException(String.format("Failed to Clean Page -> %s : %s", pageId, title), e); } if (responseEntity.getStatusCode() == HttpStatus.NO_CONTENT) { LOG.info("Cleaned Path Page -> {} : {}", pageId, title); } else { throw new ConfluenceAPIException(String.format("Failed to Clean Page -> %s : %s", pageId, title)); } }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testPutGetDeleteResource() throws Exception { try {//from w w w . j a va2 s . c om this.privilegeHelper.putResource(this.acsAdminRestTemplate, SANRAMON, this.acsUrl, this.zone1Headers, this.privilegeHelper.getDefaultAttribute()); } catch (Exception e) { Assert.fail("Unable to create resource. " + e.getMessage()); } URI resourceUri = URI.create(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + URLEncoder.encode(SANRAMON.getResourceIdentifier(), "UTF-8")); try { this.acsAdminRestTemplate.exchange(resourceUri, HttpMethod.GET, new HttpEntity<>(this.zone1Headers), BaseResource.class); } catch (HttpClientErrorException e) { Assert.fail("Unable to get resource."); } try { this.acsAdminRestTemplate.exchange(resourceUri, HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); } catch (HttpClientErrorException e) { Assert.fail("Unable to delete resource."); } // properly delete try { this.acsAdminRestTemplate.exchange(resourceUri, HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); this.acsAdminRestTemplate.exchange(resourceUri, HttpMethod.GET, new HttpEntity<>(this.zone1Headers), BaseResource.class); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.NOT_FOUND); } }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testDeleteSubscription_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/subscriptions/abcdef")).andExpect(method(HttpMethod.DELETE)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)).andRespond(withNoContent()); ngsiClient.deleteSubscription("abcdef"); }
From source file:com.netflix.genie.web.controllers.JobRestController.java
/** * Kill job based on given job ID./*w ww . ja va2s .com*/ * * @param id id for job to kill * @param forwardedFrom The host this request was forwarded from if present * @param request the servlet request * @param response the servlet response * @throws GenieException For any error * @throws IOException on redirect error * @throws ServletException when trying to handle the request */ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.ACCEPTED) public void killJob(@PathVariable("id") final String id, @RequestHeader(name = JobConstants.GENIE_FORWARDED_FROM_HEADER, required = false) final String forwardedFrom, final HttpServletRequest request, final HttpServletResponse response) throws GenieException, IOException, ServletException { log.info("[killJob] Called for job id: {}. Forwarded from: {}", id, forwardedFrom); // If forwarded from is null this request hasn't been forwarded at all. Check we're on the right node if (this.jobsProperties.getForwarding().isEnabled() && forwardedFrom == null) { final String jobHostname = this.jobSearchService.getJobHost(id); if (!this.hostName.equals(jobHostname)) { log.info("Job {} is not on this node. Forwarding kill request to {}", id, jobHostname); final String forwardUrl = buildForwardURL(request, jobHostname); try { //Need to forward job restTemplate.execute(forwardUrl, HttpMethod.DELETE, forwardRequest -> copyRequestHeaders(request, forwardRequest), (final ClientHttpResponse forwardResponse) -> { response.setStatus(HttpStatus.ACCEPTED.value()); copyResponseHeaders(response, forwardResponse); return null; }); } catch (HttpStatusCodeException e) { log.error("Failed killing job on {}. Error: {}", forwardUrl, e.getMessage()); response.sendError(e.getStatusCode().value(), e.getStatusText()); } catch (Exception e) { log.error("Failed killing job on {}. Error: {}", forwardUrl, e.getMessage()); response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); } // No need to do anything on this node return; } } log.info("Job {} is on this node. Attempting to kill.", id); // Job is on this node so try to kill it this.jobCoordinatorService.killJob(id); response.setStatus(HttpStatus.ACCEPTED.value()); }