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:com.appglu.impl.CrudTemplateTest.java
@Test public void deleteNotFound() { mockServer.expect(requestTo("http://localhost/appglu/v1/tables/user/2")) .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NOT_FOUND) .body(compactedJson("data/error_not_found")).headers(responseHeaders)); boolean success = crudOperations.delete("user", 2); Assert.assertFalse(success);//from ww w . j a v a 2 s .c o m mockServer.verify(); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testCreateResourceWithMalformedJSON() { try {//w ww .j a va 2 s. c o m String badResource = "{\"resource\": bad-resource-form\"}"; MultiValueMap<String, String> headers = new HttpHeaders(); headers.add("Content-type", "application/json"); headers.add(PolicyHelper.PREDIX_ZONE_ID, this.acsZone1Name); HttpEntity<String> httpEntity = new HttpEntity<String>(badResource, headers); this.acsAdminRestTemplate .put(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/bad-resource-form", httpEntity); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.BAD_REQUEST); return; } this.acsAdminRestTemplate.exchange( this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/bad-resource-form", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); Assert.fail("testCreateResourceWithMalformedJSON should have failed!"); }
From source file:com.orange.ngsi.client.NgsiRestClientTest.java
@Test public void testDeleteContextAttribute_JSON() throws Exception { String responseBody = json(jsonConverter, new StatusCode(CodeEnum.CODE_200)); mockServer.expect(requestTo(baseUrl + "/ngsi10/contextEntities/123/attributes/temp")) .andExpect(method(HttpMethod.DELETE)) .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON)); StatusCode response = ngsiRestClient.deleteContextAttribute(baseUrl, null, "123", "temp").get(); this.mockServer.verify(); assertEquals(CodeEnum.CODE_200.getLabel(), response.getCode()); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Delete the attribute of an entity/*from ww w . j a va 2 s . c o m*/ * @param entityId the entity ID * @param type optional entity type to avoid ambiguity when multiple entities have the same ID, null or zero-length for empty * @param attributeName the attribute name * @return */ public ListenableFuture<Attribute> deleteAttribute(String entityId, String type, String attributeName) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/entities/{entityId}/attrs/{attributeName}"); addParam(builder, "type", type); return adapt(request(HttpMethod.DELETE, builder.buildAndExpand(entityId, attributeName).toUriString(), null, Attribute.class)); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testCreateBatchResourcesWithMalformedJSON() { try {/*from ww w . j av a 2s. c o m*/ String badResource = "{\"resource\":{\"name\" : \"Site\", \"uriTemplate\" : " + "\"/secured-by-value/sites/{site_id}\"},{\"resource\": bad-resource-form\"}"; MultiValueMap<String, String> headers = new HttpHeaders(); headers.add("Content-type", "application/json"); headers.add(PolicyHelper.PREDIX_ZONE_ID, this.acsZone1Name); HttpEntity<String> httpEntity = new HttpEntity<String>(badResource, headers); this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH, httpEntity, BaseResource[].class); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.BAD_REQUEST); return; } this.acsAdminRestTemplate.exchange( this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/bad-resource-form", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); this.acsAdminRestTemplate.exchange(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/Site", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); Assert.fail("testCreateBatchResourcesWithMalformedJSON should have failed!"); }
From source file:gateway.controller.ServiceController.java
/** * De-registers a single service with Piazza. * /* www. j a v a 2 s . c o m*/ * @see http://pz-swagger.stage.geointservices.io/#!/Service/delete_service * * @param serviceId * The Id of the service to delete. * @param user * The user submitting the request * @return Service metadata, or an error. */ @RequestMapping(value = "/service/{serviceId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "Unregister a Service", notes = "Unregisters a Service by its Id.", tags = "Service") @ApiResponses(value = { @ApiResponse(code = 200, message = "Confirmation of 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> deleteService( @ApiParam(value = "The Id of the Service to unregister.", required = true) @PathVariable(value = "serviceId") String serviceId, @ApiParam(value = "Determines if the Service should be completely removed, or just disabled. If set to false, the Service will be entirely deleted.", hidden = true) @RequestParam(value = "softDelete", required = false) boolean softDelete, Principal user) { try { // Log the request logger.log(String.format("User %s has requested Service deletion of %s", gatewayUtil.getPrincipalName(user), serviceId), PiazzaLogger.INFO); // Proxy the request to the Service Controller instance String url = String.format("%s/%s/%s", SERVICECONTROLLER_URL, "service", serviceId); url = (softDelete) ? (String.format("%s?softDelete=%s", url, softDelete)) : (url); try { return new ResponseEntity<PiazzaResponse>( restTemplate.exchange(url, HttpMethod.DELETE, null, SuccessResponse.class).getBody(), HttpStatus.OK); } catch (HttpClientErrorException | HttpServerErrorException hee) { LOGGER.error("Error Deleting Service", hee); return new ResponseEntity<PiazzaResponse>( gatewayUtil.getErrorResponse(hee.getResponseBodyAsString()), hee.getStatusCode()); } } catch (Exception exception) { String error = String.format("Error Deleting Service %s Info for user %s: %s", serviceId, 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.ngsi.client.NgsiRestClient.java
/** * Delete a subscription// www .j av a 2 s . c om * @param url the URL of the broker * @param httpHeaders the HTTP header to use, or null for default * @param subscriptionID the ID of the subscription to delete * @return a future for an UnsubscribeContextResponse */ public ListenableFuture<UnsubscribeContextResponse> deleteContextSubscription(String url, HttpHeaders httpHeaders, String subscriptionID) { return request(HttpMethod.DELETE, url + subscriptionsPath + subscriptionID, httpHeaders, null, UnsubscribeContextResponse.class); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testDeleteAttibute_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/entities/room1/attrs/temperature?type=Room")) .andExpect(method(HttpMethod.DELETE)).andRespond(withNoContent()); ngsiClient.deleteAttribute("room1", "Room", "temperature").get(); }
From source file:com.ge.predix.acceptance.test.zone.admin.ZoneEnforcementStepsDefinitions.java
@When("^client_one does a DELETE on (.*?) with (.*?) in zone 1$") public void client_one_does_a_DELETE_on_api_with_identifier_in_test_zone_dev(final String api, final String identifier) throws Throwable { String encodedIdentifier = URLEncoder.encode(identifier, "UTF-8"); URI uri = URI.create(this.acsUrl + ACS_VERSION + "/" + api + "/" + encodedIdentifier); try {/*from www . j av a 2s. c o m*/ this.status = this.acsZone1Template .exchange(uri, HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class) .getStatusCode().value(); } catch (HttpClientErrorException e) { Assert.fail("Unable to DELETE identifier: " + identifier + " for api: " + api); } }