本文整理汇总了Java中org.apache.olingo.server.api.ODataLibraryException类的典型用法代码示例。如果您正苦于以下问题:Java ODataLibraryException类的具体用法?Java ODataLibraryException怎么用?Java ODataLibraryException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataLibraryException类属于org.apache.olingo.server.api包,在下文中一共展示了ODataLibraryException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readServiceDocument
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void readServiceDocument(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, ODataLibraryException {
boolean isNotModified = false;
ServiceMetadataETagSupport eTagSupport = serviceMetadata.getServiceMetadataETagSupport();
if (eTagSupport != null && eTagSupport.getServiceDocumentETag() != null) {
// Set application etag at response
response.setHeader(HttpHeader.ETAG, eTagSupport.getServiceDocumentETag());
// Check if service document has been modified
ETagHelper eTagHelper = odata.createETagHelper();
isNotModified = eTagHelper.checkReadPreconditions(eTagSupport.getServiceDocumentETag(),
request.getHeaders(HttpHeader.IF_MATCH), request.getHeaders(HttpHeader.IF_NONE_MATCH));
}
// Send the correct response req.getRequestURL().toString().replace(req.getServletPath(), "")
if (isNotModified) {
response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
} else {
ODataSerializer serializer = odata.createSerializer(requestedContentType);
//Provide serviceRoot with rawBaseUri as Excel PowerQuery does not like relative URIs
response.setContent(serializer.serviceDocument(serviceMetadata, request.getRawBaseUri()).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
}
示例2: readMetadata
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void readMetadata(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, ODataLibraryException {
boolean isNotModified = false;
ServiceMetadataETagSupport eTagSupport = serviceMetadata.getServiceMetadataETagSupport();
if (eTagSupport != null && eTagSupport.getMetadataETag() != null) {
// Set application etag at response
response.setHeader(HttpHeader.ETAG, eTagSupport.getMetadataETag());
// Check if metadata document has been modified
ETagHelper eTagHelper = odata.createETagHelper();
isNotModified = eTagHelper.checkReadPreconditions(eTagSupport.getMetadataETag(),
request.getHeaders(HttpHeader.IF_MATCH), request.getHeaders(HttpHeader.IF_NONE_MATCH));
}
// Send the correct response
if (isNotModified) {
response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
} else {
ODataSerializer serializer = odata.createSerializer(requestedContentType);
response.setContent(serializer.metadataDocument(serviceMetadata).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
}
示例3: createReference
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void createReference(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat) throws ODataApplicationException, ODataLibraryException {
// 2. create the data in backend
// 2.1. retrieve the payload from the POST request for the entity to create and deserialize it
InputStream requestInputStream = request.getBody();
ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat);
DeserializerResult result = deserializer.entityReferences(requestInputStream);
List<URI> requestEntityReferences = result.getEntityReferences();
// 2.2 do the creation in backend,
try {
SparqlBaseCommand.writeEntityReference(rdfEdmProvider, uriInfo, requestEntityReferences);
} catch (EdmException | OData2SparqlException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.NO_CONTENT.getStatusCode(),
Locale.ENGLISH);
}
// 3. serialize the response
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
示例4: updateReference
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void updateReference(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat) throws ODataApplicationException, ODataLibraryException {
// 1. Retrieve the entity type from the URI
// EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
// EdmEntityType edmEntityType = edmEntitySet.getEntityType();
// 2. create the data in backend
// 2.1. retrieve the payload from the POST request for the entity to create and deserialize it
InputStream requestInputStream = request.getBody();
ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat);
DeserializerResult result = deserializer.entityReferences(requestInputStream);
List<URI> requestEntityReferences = result.getEntityReferences();
// 2.2 do the creation in backend,
try {
SparqlBaseCommand.updateEntityReference(rdfEdmProvider, uriInfo, requestEntityReferences);
} catch (EdmException | OData2SparqlException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.NO_CONTENT.getStatusCode(),
Locale.ENGLISH);
}
// 3. serialize the response
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
示例5: deleteReference
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void deleteReference(ODataRequest request, ODataResponse response, UriInfo uriInfo)
throws ODataApplicationException, ODataLibraryException {
// 1. Retrieve the entity type from the URI
// EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
// EdmEntityType edmEntityType = edmEntitySet.getEntityType();
try {
SparqlBaseCommand.deleteEntityReference(rdfEdmProvider, uriInfo);
} catch (EdmException | OData2SparqlException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.NO_CONTENT.getStatusCode(),
Locale.ENGLISH);
}
// 3. serialize the response
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
示例6: read
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
/**
* Method is a template to provide behavior for all read processors.
*/
@Override
public void read(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
this.request = request;
ESRequest searchRequest = createRequest(uriInfo);
ElasticEdmEntitySet entitySet = searchRequest.getEntitySet();
SearchResponse searchResponse = searchRequest.execute();
InstanceData<T, V> data = parseResponse(searchResponse, entitySet);
ODataSerializer serializer = odata.createSerializer(responseFormat);
SerializerResult serializerResult = serialize(serializer, data, entitySet, uriInfo);
response.setContent(serializerResult.getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
示例7: getContextUrl
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
private static ContextURL getContextUrl(final EdmEntitySet entitySet,
final EdmEntityType entityType,
final boolean isSingleEntity)
throws ODataLibraryException
{
ContextURL.Builder builder = ContextURL.with();
builder = (entitySet == null)
? isSingleEntity
? builder.type(entityType)
: builder.asCollection().type(entityType)
: builder.entitySet(entitySet);
builder = builder.suffix((isSingleEntity && (entitySet != null))
? ContextURL.Suffix.ENTITY
: null);
return builder.build();
}
示例8: countEntityCollection
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void countEntityCollection(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo) throws ODataApplicationException, ODataLibraryException {
validateOptions(uriInfo.asUriInfoResource());
getEdmEntitySet(uriInfo); // including checks
final EntityCollection entitySetInitial = readEntityCollection(uriInfo);
EntityCollection entitySet = new EntityCollection();
entitySet.getEntities().addAll(entitySetInitial.getEntities());
FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, uriInfo, serviceMetadata.getEdm());
int count = entitySet.getEntities().size();
for (SystemQueryOption systemQueryOption : uriInfo.getSystemQueryOptions()) {
if (systemQueryOption.getName().contains(DELTATOKEN)) {
count = count + getDeltaCount(uriInfo);
break;
}
}
response.setContent(odata.createFixedFormatSerializer().count(count));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.TEXT_PLAIN.toContentTypeString());
}
示例9: createReference
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void createReference(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat) throws ODataApplicationException, ODataLibraryException {
final ODataDeserializer deserializer = odata.createDeserializer(requestFormat);
final DeserializerResult references = deserializer.entityReferences(request.getBody());
if (references.getEntityReferences().size() != 1) {
throw new ODataApplicationException("A post request to a collection navigation property must "
+ "contain a single entity reference", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
}
final Entity entity = readEntity(uriInfo, true);
final UriResourceNavigation navigationProperty = getLastNavigation(uriInfo);
ensureNavigationPropertyNotNull(navigationProperty);
dataProvider.createReference(entity, navigationProperty.getProperty(), references.getEntityReferences().get(0),
request.getRawBaseUri());
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
示例10: serializeEntityCollection
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
private SerializerResult serializeEntityCollection(final ODataRequest request, final EntityCollection
entityCollection, final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType,
final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
final CountOption countOption, String id, final boolean isContNav) throws ODataLibraryException {
return odata.createSerializer(requestedFormat, request.getHeaders(HttpHeader.ODATA_VERSION))
.entityCollection(
serviceMetadata,
edmEntityType,
entityCollection,
EntityCollectionSerializerOptions.with()
.contextURL(isODataMetadataNone(requestedFormat) ? null :
getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, false, expand, select, isContNav))
.count(countOption)
.expand(expand).select(select)
.id(id)
.build());
}
示例11: serializeEntity
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
private SerializerResult serializeEntity(final ODataRequest request, final Entity entity,
final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType,
final ContentType requestedFormat,
final ExpandOption expand, final SelectOption select, final boolean isContNav)
throws ODataLibraryException {
ContextURL contextUrl = isODataMetadataNone(requestedFormat) ? null :
getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, true, expand, null,isContNav);
return odata.createSerializer(requestedFormat, request.getHeaders(HttpHeader.ODATA_VERSION)).entity(
serviceMetadata,
edmEntityType,
entity,
EntitySerializerOptions.with()
.contextURL(contextUrl)
.expand(expand).select(select)
.build());
}
示例12: deleteMediaEntity
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void deleteMediaEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo)
throws ODataApplicationException, ODataLibraryException {
/*
* In this tutorial, the content of the media entity is stored in a special property.
* So no additional steps to delete the content of the media entity are necessary.
*
* A real service may store the content on the file system. So we have to take care to
* delete external files too.
*
* DELETE request to /Advertisements(ID) will be dispatched to the deleteEntity(...) method
* DELETE request to /Advertisements(ID)/$value will be dispatched to the deleteMediaEntity(...) method
*
* So it is a good idea handle deletes in a central place.
*/
deleteEntity(request, response, uriInfo);
}
示例13: readMediaEntity
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void readMediaEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, ODataLibraryException {
final UriResource firstResoucePart = uriInfo.getUriResourceParts().get(0);
if(firstResoucePart instanceof UriResourceEntitySet) {
final EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
final UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) firstResoucePart;
final Entity entity = storage.readEntityData(edmEntitySet, uriResourceEntitySet.getKeyPredicates());
if(entity == null) {
throw new ODataApplicationException("Entity not found", HttpStatusCode.NOT_FOUND.getStatusCode(),
Locale.ENGLISH);
}
final byte[] mediaContent = storage.readMedia(entity);
final InputStream responseContent = odata.createFixedFormatSerializer().binary(mediaContent);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setContent(responseContent);
response.setHeader(HttpHeader.CONTENT_TYPE, entity.getMediaContentType());
} else {
throw new ODataApplicationException("Not implemented", HttpStatusCode.BAD_REQUEST.getStatusCode(),
Locale.ENGLISH);
}
}
示例14: fillODataRequest
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
private ODataRequest fillODataRequest(final ODataRequest odRequest, final HttpServletRequest httpRequest,
final int split) throws ODataLibraryException {
final int requestHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "fillODataRequest");
try {
odRequest.setBody(httpRequest.getInputStream());
odRequest.setProtocol(httpRequest.getProtocol());
odRequest.setMethod(extractMethod(httpRequest));
int innerHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "copyHeaders");
copyHeaders(odRequest, httpRequest);
debugger.stopRuntimeMeasurement(innerHandle);
innerHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "fillUriInformation");
fillUriInformation(odRequest, httpRequest, split);
debugger.stopRuntimeMeasurement(innerHandle);
return odRequest;
} catch (final IOException e) {
throw new DeserializerException("An I/O exception occurred.", e,
DeserializerException.MessageKeys.IO_EXCEPTION);
} finally {
debugger.stopRuntimeMeasurement(requestHandle);
}
}
示例15: deleteEntity
import org.apache.olingo.server.api.ODataLibraryException; //导入依赖的package包/类
@Override
public void deleteEntity(DataRequest request, String eTag, EntityResponse response)
throws ODataLibraryException, ODataApplicationException {
EdmEntitySet edmEntitySet = request.getEntitySet();
Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), request.getKeyPredicates());
if (entity == null) {
response.writeNotFound(true);
return;
}
String key = edmEntitySet.getEntityType().getKeyPredicateNames().get(0);
boolean removed = this.dataModel.deleteEntity(edmEntitySet.getName(), eTag, key, entity
.getProperty(key).getValue());
if (removed) {
response.writeDeletedEntityOrReference();
} else {
response.writeNotFound(true);
}
}