List of usage examples for org.springframework.http HttpMethod PUT
HttpMethod PUT
To view the source code for org.springframework.http HttpMethod PUT.
Click Source Link
From source file:com.vmware.bdd.cli.rest.RestClient.java
/** * Update an object//from ww w .j a v a 2s . c o m * * @param entity * the updated content * @param path * the rest url * @param verb * the http method * @param prettyOutput * output callback */ public void update(Object entity, final String path, final HttpMethod verb, PrettyOutput... prettyOutput) { checkConnection(); try { if (verb == HttpMethod.PUT) { ResponseEntity<String> response = restUpdate(path, entity); if (!validateAuthorization(response)) { return; } processResponse(response, HttpMethod.PUT, 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
public TaskRead updateWithReturn(Object entity, final String path, final HttpMethod verb, PrettyOutput... prettyOutput) {/* ww w . j a v a2 s . c o m*/ checkConnection(); try { if (verb == HttpMethod.PUT) { ResponseEntity<String> response = restUpdate(path, entity); if (!validateAuthorization(response)) { return null; } return processResponse(response, HttpMethod.PUT, prettyOutput); } else { throw new Exception(Constants.HTTP_VERB_ERROR); } } catch (Exception e) { throw new CliRestException(CommandsUtils.getExceptionMessage(e)); } }
From source file:com.vmware.bdd.cli.rest.RestClient.java
private ResponseEntity<String> restUpdate(String path, Object entityName) { String targetUri = hostUri + Constants.HTTPS_CONNECTION_API + path; HttpHeaders headers = buildHeaders(); HttpEntity<Object> entity = new HttpEntity<Object>(entityName, headers); return client.exchange(targetUri, HttpMethod.PUT, entity, String.class); }
From source file:com.vsct.supervision.notification.repository.SeyrenRepositoryMappingTests.java
@Test public void testResponseErrorHandler_500() throws Exception { mockServer.expect(requestTo(seyrenUrl + SeyrenRepository.API_ALARMS + "/addAlarm")) .andExpect(method(HttpMethod.PUT)).andRespond(withServerError()); Alarm alarm = new Alarm(); alarm.setId("addAlarm"); try {//from w w w . j av a2 s . c o m seyrenRepository.updateAlarm(alarm); fail(); } catch (CerebroException e) { assertEquals(ErrorCode.SEYREN_ERROR, e.getErrorCode()); } }
From source file:com.wiley.gr.ace.authorservices.externalservices.service.impl.TaskServiceImpl.java
/** * Finish task.// w w w. j a va 2 s .c o m * * @param associationConfirmation the association confirmation * @return true, if successful * @throws Exception the exception */ @Override public final boolean finishTask(final AssociationConfirmation associationConfirmation) { boolean flag = false; final String url = "http://demo7930138.mockable.io/rest/bpm/wle/v1/task/" + associationConfirmation.getTaskId() + "55?action=" + associationConfirmation.isAssociationConfirmed() + "&parts=all"; final Service service = (Service) StubInvokerUtil.invokeStub(url, HttpMethod.PUT, Service.class); if (service != null && AuthorServicesConstants.BPM_CALL_SUCCESS_STATUS.equals(service.getStatus())) { flag = true; } return flag; }
From source file:org.alfresco.rest.framework.core.ResourceInspector.java
/** * Inspects the entity resource and returns meta data about it * /*from ww w. jav a 2 s .com*/ * @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/*w ww . j a v a2 s .c o 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 w w .java2s . com*/ * @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; }
From source file:org.alfresco.rest.framework.webscripts.ResourceWebScriptPut.java
public ResourceWebScriptPut() { super(); setHttpMethod(HttpMethod.PUT); setParamsExtractor(this); }
From source file:org.alfresco.rest.framework.webscripts.ResourceWebScriptPut.java
@Override public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req) { final String relationshipId = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_ID); final String entityId = req.getServiceMatch().getTemplateVars().get(ResourceLocator.ENTITY_ID); final RecognizedParams params = getRecognizedParams(req); final ResourceOperation operation = resourceMeta.getOperation(HttpMethod.PUT); switch (resourceMeta.getType()) { case ENTITY:/*w ww. ja v a 2s. c o m*/ if (StringUtils.isBlank(entityId)) { throw new UnsupportedResourceOperationException("PUT is executed against the instance URL"); } else { Object putEnt = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation)); return Params.valueOf(entityId, params, putEnt, req); } case RELATIONSHIP: if (StringUtils.isBlank(relationshipId)) { throw new UnsupportedResourceOperationException("PUT is executed against the instance URL"); } else { Object putRel = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation)); ResourceWebScriptHelper.setUniqueId(putRel, relationshipId); return Params.valueOf(entityId, params, putRel, req); } case PROPERTY: final String resourceName = req.getServiceMatch().getTemplateVars() .get(ResourceLocator.RELATIONSHIP_RESOURCE); final String propertyName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.PROPERTY); if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(resourceName)) { if (StringUtils.isNotBlank(propertyName)) { return Params.valueOf(entityId, relationshipId, null, getStream(req), propertyName, params, getContentInfo(req), req); } else { return Params.valueOf(entityId, null, null, getStream(req), resourceName, params, getContentInfo(req), req); } } //Fall through to unsupported. default: throw new UnsupportedResourceOperationException("PUT not supported for this request."); } }