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.sitewhere.rest.client.SiteWhereClient.java
public SiteWhereClient(String url, String username, String password, String tenantAuthToken, int connectTimeoutMs) { if (DEBUG_ENABLED) { enableDebugging();//from ww w. j a v a 2 s .c o m } this.client = new RestTemplate(); this.username = username; this.password = password; this.tenantAuthToken = tenantAuthToken; // Special handling for delete requests with request body passed. HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory() { @Override protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { if (HttpMethod.DELETE == httpMethod) { return new HttpEntityEnclosingDeleteRequest(uri); } return super.createHttpUriRequest(httpMethod, uri); } }; if (connectTimeoutMs > 0) { factory.setConnectTimeout(connectTimeoutMs); } client.setRequestFactory(factory); List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(); addMessageConverters(converters); client.setMessageConverters(converters); client.setErrorHandler(new SiteWhereErrorHandler()); this.baseUrl = url; }
From source file:com.sitewhere.rest.client.SiteWhereClient.java
@Override public DeviceSpecification deleteDeviceSpecification(String token, boolean deletePermanently) throws SiteWhereException { Map<String, String> vars = new HashMap<String, String>(); vars.put("token", token); vars.put("force", String.valueOf(deletePermanently)); return sendRest(getBaseUrl() + "specifications/{token}&force={force}", HttpMethod.DELETE, null, DeviceSpecification.class, vars); }
From source file:com.sitewhere.rest.client.SiteWhereClient.java
@Override public Device deleteDevice(String hardwareId, boolean force) throws SiteWhereException { Map<String, String> vars = new HashMap<String, String>(); vars.put("hardwareId", hardwareId); vars.put("force", String.valueOf(force)); String url = getBaseUrl() + "devices/{hardwareId}&force={force}"; return sendRest(url, HttpMethod.DELETE, null, Device.class, vars); }
From source file:com.sitewhere.rest.client.SiteWhereClient.java
@Override public DeviceGroup deleteDeviceGroup(String token) throws SiteWhereException { Map<String, String> vars = new HashMap<String, String>(); vars.put("token", token); return sendRest(getBaseUrl() + "devicegroups/{token}", HttpMethod.DELETE, null, DeviceGroup.class, vars); }
From source file:com.sitewhere.rest.client.SiteWhereClient.java
@Override public DeviceGroupElementSearchResults deleteDeviceGroupElements(String groupToken, List<DeviceGroupElementCreateRequest> elements) throws SiteWhereException { Map<String, String> vars = new HashMap<String, String>(); vars.put("token", groupToken); return sendRest(getBaseUrl() + "devicegroups/{token}/elements", HttpMethod.DELETE, elements, DeviceGroupElementSearchResults.class, vars); }
From source file:com.vmware.bdd.cli.rest.RestClient.java
/** * Delete an object by id/*from www .ja v a2 s .c o m*/ * * @param id * @param path * the rest url * @param verb * the http method * @param prettyOutput * utput callback */ public void deleteObject(final String id, final String path, final HttpMethod verb, PrettyOutput... prettyOutput) { checkConnection(); try { if (verb == HttpMethod.DELETE) { ResponseEntity<String> response = restDelete(path, id); if (!validateAuthorization(response)) { return; } processResponse(response, HttpMethod.DELETE, prettyOutput); } else { throw new Exception(Constants.HTTP_VERB_ERROR); } } catch (Exception e) { if (e instanceof CliRestException) { throw (CliRestException) e; } if (e instanceof BddException) { throw (BddException) e; } throw new CliRestException(CommandsUtils.getExceptionMessage(e)); } }
From source file:com.vmware.bdd.cli.rest.RestClient.java
private ResponseEntity<String> restDelete(String path, String id) { String targetUri = hostUri + Constants.HTTPS_CONNECTION_API + path + "/" + id; HttpHeaders headers = buildHeaders(); HttpEntity<String> entity = new HttpEntity<String>(headers); return client.exchange(targetUri, HttpMethod.DELETE, entity, String.class); }
From source file:org.alfresco.rest.framework.core.ResourceInspector.java
/** * Inspects the entity resource and returns meta data about it * //from w w w. j a v a 2s.co m * @param annot EntityResource * @param resource Class<?> */ private static List<ResourceMetadata> inspectEntity(EntityResource annot, Class<?> resource) { String urlPath = findEntityName(annot); logger.debug("Found EntityResource: " + urlPath); List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>(); Api api = inspectApi(resource); MetaHelper helper = new MetaHelper(resource); findOperation(EntityResourceAction.Create.class, HttpMethod.POST, helper); findOperation(EntityResourceAction.Read.class, HttpMethod.GET, helper); findOperation(EntityResourceAction.ReadById.class, HttpMethod.GET, helper); findOperation(EntityResourceAction.Update.class, HttpMethod.PUT, helper); findOperation(EntityResourceAction.Delete.class, HttpMethod.DELETE, helper); findOperation(EntityResourceAction.CreateWithResponse.class, HttpMethod.POST, helper); findOperation(EntityResourceAction.ReadWithResponse.class, HttpMethod.GET, helper); findOperation(EntityResourceAction.ReadByIdWithResponse.class, HttpMethod.GET, helper); findOperation(EntityResourceAction.UpdateWithResponse.class, HttpMethod.PUT, helper); findOperation(EntityResourceAction.DeleteWithResponse.class, HttpMethod.DELETE, helper); findOperation(MultiPartResourceAction.Create.class, HttpMethod.POST, helper); boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) { throw new IllegalArgumentException( "@WebApiNoAuth should not be on all (entity resource class) - only on individual methods: " + urlPath); } Set<Class<? extends ResourceAction>> apiNoAuth = helper.apiNoAuth; if (resource.isAnnotationPresent(WebApiDeleted.class)) { metainfo.add(new ResourceMetadata(ResourceDictionary.resourceKey(urlPath, null), RESOURCE_TYPE.ENTITY, null, api, ALL_ENTITY_RESOURCE_INTERFACES, apiNoAuth, null)); } else { if (!helper.apiDeleted.isEmpty() || !helper.operations.isEmpty()) { metainfo.add(new ResourceMetadata(ResourceDictionary.resourceKey(urlPath, null), RESOURCE_TYPE.ENTITY, helper.operations, api, helper.apiDeleted, apiNoAuth, null)); } } inspectAddressedProperties(api, resource, urlPath, metainfo); inspectOperations(api, resource, urlPath, metainfo); return metainfo; }
From source file:org.alfresco.rest.framework.core.ResourceInspector.java
/** * Inspects the entity resource and returns meta data about any addresssed/binary properties * @param api Api/*from w w w .j a va 2 s .co m*/ * @param entityPath String */ public static void inspectAddressedProperties(Api api, Class<?> resource, final String entityPath, List<ResourceMetadata> metainfo) { final Map<String, List<ResourceOperation>> operationGroupedByProperty = new HashMap<String, List<ResourceOperation>>(); MetaHelperAddressable helperForAddressProps = new MetaHelperAddressable(resource, entityPath, operationGroupedByProperty); findOperation(BinaryResourceAction.Read.class, HttpMethod.GET, helperForAddressProps); findOperation(BinaryResourceAction.Delete.class, HttpMethod.DELETE, helperForAddressProps); findOperation(BinaryResourceAction.Update.class, HttpMethod.PUT, helperForAddressProps); findOperation(BinaryResourceAction.ReadWithResponse.class, HttpMethod.GET, helperForAddressProps); findOperation(BinaryResourceAction.DeleteWithResponse.class, HttpMethod.DELETE, helperForAddressProps); findOperation(BinaryResourceAction.UpdateWithResponse.class, HttpMethod.PUT, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.Read.class, HttpMethod.GET, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.Delete.class, HttpMethod.DELETE, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.Update.class, HttpMethod.PUT, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.ReadWithResponse.class, HttpMethod.GET, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.DeleteWithResponse.class, HttpMethod.DELETE, helperForAddressProps); findOperation(RelationshipResourceBinaryAction.UpdateWithResponse.class, HttpMethod.PUT, helperForAddressProps); boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) { throw new IllegalArgumentException( "@WebApiNoAuth should not be on all (address properties) - only on individual methods: " + entityPath); } Set<Class<? extends ResourceAction>> apiNoAuth = helperForAddressProps.apiNoAuth; if (resource.isAnnotationPresent(WebApiDeleted.class)) { metainfo.add(new ResourceMetadata(ResourceDictionary.propertyResourceKey(entityPath, "FIX_ME"), RESOURCE_TYPE.PROPERTY, null, inspectApi(resource), ALL_PROPERTY_RESOURCE_INTERFACES, apiNoAuth, null)); } else { for (Entry<String, List<ResourceOperation>> groupedOps : operationGroupedByProperty.entrySet()) { metainfo.add(new ResourceMetadata(groupedOps.getKey(), RESOURCE_TYPE.PROPERTY, groupedOps.getValue(), api, null, apiNoAuth, null)); } } }
From source file:org.alfresco.rest.framework.core.ResourceInspector.java
/** * Inspects the relationship resource and returns meta data about it * //from w ww. j ava 2 s . c om * @param annot RelationshipResource * @param resource Class<?> */ private static List<ResourceMetadata> inspectRelationship(RelationshipResource annot, Class<?> resource) { Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot); String urlPath = String.valueOf(annotAttribs.get("name")); String entityPath = findEntityNameByAnnotationAttributes(annotAttribs); String relationshipKey = ResourceDictionary.resourceKey(entityPath, urlPath); Api api = inspectApi(resource); List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>(); MetaHelper helper = new MetaHelper(resource); findOperation(RelationshipResourceAction.Create.class, HttpMethod.POST, helper); findOperation(RelationshipResourceAction.Read.class, HttpMethod.GET, helper); findOperation(RelationshipResourceAction.ReadById.class, HttpMethod.GET, helper); findOperation(RelationshipResourceAction.Update.class, HttpMethod.PUT, helper); findOperation(RelationshipResourceAction.Delete.class, HttpMethod.DELETE, helper); findOperation(RelationshipResourceAction.CreateWithResponse.class, HttpMethod.POST, helper); findOperation(RelationshipResourceAction.ReadWithResponse.class, HttpMethod.GET, helper); findOperation(RelationshipResourceAction.ReadByIdWithResponse.class, HttpMethod.GET, helper); findOperation(RelationshipResourceAction.UpdateWithResponse.class, HttpMethod.PUT, helper); findOperation(RelationshipResourceAction.DeleteWithResponse.class, HttpMethod.DELETE, helper); findOperation(MultiPartRelationshipResourceAction.Create.class, HttpMethod.POST, helper); boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class); if (noAuth) { throw new IllegalArgumentException( "@WebApiNoAuth should not be on all (relationship resource class) - only on methods: " + urlPath); } Set<Class<? extends ResourceAction>> apiNoAuth = helper.apiNoAuth; if (resource.isAnnotationPresent(WebApiDeleted.class)) { metainfo.add(new ResourceMetadata(relationshipKey, RESOURCE_TYPE.RELATIONSHIP, null, inspectApi(resource), ALL_RELATIONSHIP_RESOURCE_INTERFACES, apiNoAuth, entityPath)); } else { metainfo.add(new ResourceMetadata(relationshipKey, RESOURCE_TYPE.RELATIONSHIP, helper.operations, inspectApi(resource), helper.apiDeleted, apiNoAuth, entityPath)); } inspectAddressedProperties(api, resource, relationshipKey, metainfo); inspectOperations(api, resource, relationshipKey, metainfo); return metainfo; }