@Override public void visit(EntityResponse response) throws ODataApplicationException, SerializerException { if (details.entity == null) { /*Sometimes there can be navigation entity might be null, therefore according to the ODATA spec we should send NoContent Header */ if (details.eTagMatched) { response.writeNoContent(true); } else { response.writeNotFound(true); } } else { if (details.eTagMatched) { response.writeReadEntity(details.entityType, details.entity); } else { response.getODataResponse().setStatusCode(HttpStatusCode.PRECONDITION_FAILED.getStatusCode()); } } } });
locationHeader = buildLocation(this.baseURL, entity, entitySet.getName(), entitySet.getEntityType()); } catch (EdmPrimitiveTypeException e) { throw new SerializerException(e.getMessage(), e, SerializerException.MessageKeys.WRONG_PRIMITIVE_VALUE); writeNoContent(false); writeHeader(HttpHeader.LOCATION, locationHeader); writeHeader("Preference-Applied", "return=minimal"); //$NON-NLS-1$ //$NON-NLS-2$ writeHeader("OData-EntityId", entity.getId().toASCIIString()); //$NON-NLS-1$ close(); return; writeCreated(false); writeHeader(HttpHeader.LOCATION, locationHeader); if (this.returnRepresentation != ReturnRepresentation.NONE) { writeHeader("Preference-Applied", "return=representation"); //$NON-NLS-1$ //$NON-NLS-2$ writeHeader(HttpHeader.CONTENT_TYPE, this.responseContentType.toContentTypeString()); close();
public void visit(EntityResponse response) throws ODataLibraryException, ODataApplicationException { EntityCollection entitySet = (EntityCollection)queryResponse; if (entitySet.getEntities().isEmpty()) { if (visitor.hasNavigation()) { response.writeNoContent(true); } else { response.writeNotFound(true); } } else { response.writeReadEntity(visitor.getContext().getEdmEntityType(), entitySet.getEntities().get(0)); } }
public void writeReadEntity(EdmEntityType entityType, Entity entity) throws SerializerException { assert (!isClosed()); if (entity == null) { writeNotFound(true); return; } if (ContentTypeHelper.isODataMetadataFull(this.responseContentType)) { EdmAction action = this.metadata.getEdm().getBoundActionWithBindingType( entityType.getFullQualifiedName(), false); if (action != null) { entity.getOperations().add(buildOperation(action, entity.getId().toASCIIString())); } List<EdmFunction> functions = this.metadata.getEdm() .getBoundFunctionsWithBindingType(entityType.getFullQualifiedName(),false); for (EdmFunction function:functions) { entity.getOperations().add(buildOperation(function, entity.getId().toASCIIString())); } } // write the entity to response this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options).getContent()); writeOK(responseContentType); close(); }
if (EMPTY_E_TAG.equals(eTag)) { updateEntity(entityType, changes, keys, merge); response.writeUpdatedEntity(); } else { Entity entity = getEntity(request.getEntitySet().getEntityType(), keys, baseUrl); if (entity == null) { response.writeNotFound(true); if (log.isDebugEnabled()) { StringBuilder message = new StringBuilder(); boolean result = updateEntityWithETagMatched(entityType, changes, entity, merge); if (result) { response.writeUpdatedEntity(); } else { response.writeNotModified(); response.writeError( new ODataServerError().setStatusCode(HttpStatusCode.PRECONDITION_FAILED.getStatusCode()) .setMessage("E-Tag checksum didn't match.")); response.writeNotModified(); log.error("Error occurred while updating entity. :" + e.getMessage(), e); } finally { finalizeTransactionalConnection(); } catch (DataServiceFault e) { response.writeNotModified(); log.error("Error occurred while updating entity. :" + e.getMessage(), e);
Entity entity = getEntity(request.getEntitySet().getEntityType(), keys, baseUrl); if (entity == null) { response.writeNotFound(true); if (log.isDebugEnabled()) { StringBuilder message = new StringBuilder(); entity = getETagMatchedEntity(eTag, getIfMatch(request), entity); if (entity == null) { response.writeError( new ODataServerError().setStatusCode(HttpStatusCode.PRECONDITION_FAILED.getStatusCode()) .setMessage("E-Tag checksum didn't match.")); response.writeDeletedEntityOrReference(); } else { if (!EMPTY_E_TAG.equals(eTag)) { response.writeNotModified(); } else { response.writeNotFound(true); response.writeNotModified(); log.error("Error occurred while deleting entity. :" + e.getMessage(), e); } finally { finalizeTransactionalConnection(); } catch (DataServiceFault e) { response.writeNotModified(); log.error("Error occurred while deleting entity. :" + e.getMessage(), e);
@Override public void visit(EntityResponse response) throws ODataLibraryException, ODataApplicationException { selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getResponseContentType()); }
String location = EntityResponse.buildLocation(request.getODataRequest().getRawBaseUri(), entity, request.getEntitySet().getName(), entity.setId(new URI(location)); response.writeCreatedEntity(request.getEntitySet(), entity); response.writeNotModified();
public void writeUpdatedEntity() { // spec says just success response; so either 200 or 204. 200 typically has // payload writeNoContent(true); }
@Override public void createEntity(DataRequest request, Entity entity, EntityResponse response) throws ODataApplicationException { EdmEntitySet edmEntitySet = request.getEntitySet(); String baseURL = request.getODataRequest().getRawBaseUri(); try { Entity created = createEntityInTable(edmEntitySet.getEntityType(), entity); entity.setId(new URI(ODataUtils.buildLocation(baseURL, created, edmEntitySet.getName(), edmEntitySet.getEntityType()))); response.writeCreatedEntity(edmEntitySet, created); } catch (ODataServiceFault | SerializerException | URISyntaxException | EdmPrimitiveTypeException e) { response.writeNotModified(); String error = "Error occurred while creating entity. :" + e.getMessage(); throw new ODataApplicationException(error, 500, Locale.ENGLISH); } }
response.writeUpdatedEntity(); response.writeNotModified();
@Override public void deleteEntity(DataRequest request, String entityETag, EntityResponse response) throws ODataLibraryException, ODataApplicationException { // TODO: need to match entityETag. checkETag(entityETag); UpdateResponse updateResponse = null; try { ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata); visitor.visit(request.getUriInfo()); Delete delete = visitor.delete(); updateResponse = getClient().executeUpdate(delete, visitor.getParameters()); } catch (SQLException e) { throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e); } if (updateResponse != null && updateResponse.getUpdateCount() > 0) { response.writeDeletedEntityOrReference(); } else { //since DELETE is idempotent same response as otherwise success operation. response.writeDeletedEntityOrReference(); } }
@Override public void upsertEntity(DataRequest request, Entity entity, boolean merge, String entityETag, EntityResponse response) throws ODataLibraryException, ODataApplicationException { EdmEntitySet edmEntitySet = request.getEntitySet(); String baseUrl = request.getODataRequest().getRawBaseUri(); Entity currentEntity; try { currentEntity = getEntity(edmEntitySet.getEntityType(), request.getKeyPredicates(), baseUrl); if (currentEntity == null) { createEntity(request, entity, response); } else { updateEntity(request, entity, merge, entityETag, response); } } catch (ODataServiceFault e) { response.writeNotModified(); log.error("Error occurred while upserting entity. :" + e.getMessage(), e); } }
String id = EntityResponse.buildLocation(baseURL, entity, entityType.getName(), entityType); entity.setId(new URI(id));
public void writeReadEntity(EdmEntityType entityType, Entity entity) throws SerializerException { assert (!isClosed()); if (entity == null) { writeNotFound(true); return; } if (ContentTypeHelper.isODataMetadataFull(this.responseContentType)) { EdmAction action = this.metadata.getEdm().getBoundActionWithBindingType( entityType.getFullQualifiedName(), false); if (action != null) { entity.getOperations().add(buildOperation(action, entity.getId().toASCIIString())); } List<EdmFunction> functions = this.metadata.getEdm() .getBoundFunctionsWithBindingType(entityType.getFullQualifiedName(),false); for (EdmFunction function:functions) { entity.getOperations().add(buildOperation(function, entity.getId().toASCIIString())); } } // write the entity to response this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options).getContent()); writeOK(responseContentType); close(); }
@Override public void visit(EntityResponse response) throws ODataLibraryException, ODataApplicationException { selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getResponseContentType()); }
public void writeUpdatedEntity() { // spec says just success response; so either 200 or 204. 200 typically has // payload writeNoContent(true); }
locationHeader = buildLocation(this.baseURL, entity, entitySet.getName(), entitySet.getEntityType()); } catch (EdmPrimitiveTypeException e) { throw new SerializerException(e.getMessage(), e, SerializerException.MessageKeys.WRONG_PRIMITIVE_VALUE); writeNoContent(false); writeHeader(HttpHeader.LOCATION, locationHeader); writeHeader("Preference-Applied", "return=minimal"); //$NON-NLS-1$ //$NON-NLS-2$ writeHeader("OData-EntityId", entity.getId().toASCIIString()); //$NON-NLS-1$ close(); return; writeCreated(false); writeHeader(HttpHeader.LOCATION, locationHeader); if (this.returnRepresentation != ReturnRepresentation.NONE) { writeHeader("Preference-Applied", "return=representation"); //$NON-NLS-1$ //$NON-NLS-2$ writeHeader(HttpHeader.CONTENT_TYPE, this.responseContentType.toContentTypeString()); close();
@Override public void visit(EntityResponse response) throws ODataLibraryException, ODataApplicationException { selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(), response.getODataResponse(), request.getUriInfo(), request.getResponseContentType()); }
public void writeDeletedEntityOrReference() { writeNoContent(true); }