本文整理汇总了Java中org.apache.olingo.server.api.serializer.ODataSerializer类的典型用法代码示例。如果您正苦于以下问题:Java ODataSerializer类的具体用法?Java ODataSerializer怎么用?Java ODataSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataSerializer类属于org.apache.olingo.server.api.serializer包,在下文中一共展示了ODataSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readServiceDocument
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的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.serializer.ODataSerializer; //导入依赖的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: createSerializer
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
public ODataSerializer createSerializer(ContentType contentType) throws SerializerException {
ODataSerializer serializer = null;
if (contentType.isCompatible(ContentType.APPLICATION_JSON)) {
String metadata = contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA);
if (metadata == null
|| ContentType.VALUE_ODATA_METADATA_MINIMAL.equalsIgnoreCase(metadata)
|| ContentType.VALUE_ODATA_METADATA_NONE.equalsIgnoreCase(metadata)
|| ContentType.VALUE_ODATA_METADATA_FULL.equalsIgnoreCase(metadata)) {
serializer = new ElasticODataJsonSerializer(contentType);
}
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
serializer = new ElasticODataXmlSerializer();
}
if (serializer == null) {
throw new SerializerException(
"Unsupported format: " + contentType.toContentTypeString(),
SerializerException.MessageKeys.UNSUPPORTED_FORMAT,
contentType.toContentTypeString());
}
return serializer;
}
示例4: read
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的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());
}
示例5: serialize
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
protected SerializerResult serialize(ODataSerializer serializer,
InstanceData<EdmPrimitiveType, Property> data, ElasticEdmEntitySet entitySet,
UriInfo uriInfo) throws SerializerException {
List<UriResource> resourceParts = uriInfo.getUriResourceParts();
UriResourceProperty uriProperty = (UriResourceProperty) resourceParts
.get(resourceParts.size() - 1);
ElasticEdmProperty edmProperty = (ElasticEdmProperty) uriProperty.getProperty();
String propertyName = edmProperty.getName();
return serializer.primitive(serviceMetadata, data.getType(), data.getValue(),
PrimitiveSerializerOptions.with()
.contextURL(createContextUrl(entitySet, true, null, null, propertyName))
.scale(edmProperty.getScale()).nullable(edmProperty.isNullable())
.precision(edmProperty.getPrecision()).maxLength(edmProperty.getMaxLength())
.unicode(edmProperty.isUnicode()).build());
}
示例6: getContextUrl
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
private ODataSerializerOptions getContextUrl( final org.apache.olingo.commons.api.edm.EdmEntitySet entitySet,
final UriInfo uriInfo,
final ODataFormat format,
final ODataSerializer serializer,
final boolean isSingleEntity,
final String path) throws SerializerException {
ContextURL contextUrl = ContextURL.with().entitySetOrSingletonOrType(path)
.selectList(serializer.buildContextURLSelectList(entitySet, uriInfo.getExpandOption(), uriInfo.getSelectOption()))
.suffix(isSingleEntity ? Suffix.ENTITY : null)
.build();
return ODataSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null : contextUrl)
.count(uriInfo.getCountOption())
.expand(uriInfo.getExpandOption()).select(uriInfo.getSelectOption())
.build();
}
示例7: processError
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
public void processError(final ODataRequest request, final ODataResponse response,
final ODataServerError serverError,
final ContentType requestedContentType) {
try {
ODataSerializer serializer = odata.createSerializer(requestedContentType);
response.setContent(serializer.error(serverError).getContent());
response.setStatusCode(serverError.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
} catch (Exception e) {
// This should never happen but to be sure we have this catch here to prevent sending a stacktrace to a client.
String responseContent =
"{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred during error processing\"}}";
response.setContent(new ByteArrayInputStream(responseContent.getBytes(Charset.forName("utf-8"))));
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
}
}
示例8: createSerializer
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
public ODataSerializer createSerializer(final ContentType contentType) throws SerializerException {
ODataSerializer serializer = null;
if (contentType.isCompatible(ContentType.APPLICATION_JSON)) {
final String metadata = contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA);
if (metadata == null
|| ContentType.VALUE_ODATA_METADATA_MINIMAL.equalsIgnoreCase(metadata)
|| ContentType.VALUE_ODATA_METADATA_NONE.equalsIgnoreCase(metadata)
|| ContentType.VALUE_ODATA_METADATA_FULL.equalsIgnoreCase(metadata)) {
serializer = new ODataJsonSerializer(contentType, new Constantsv00());
}
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
serializer = new ODataXmlSerializer();
}
if (serializer == null) {
throw new SerializerException("Unsupported format: " + contentType.toContentTypeString(),
SerializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
} else {
return serializer;
}
}
示例9: handleServerError
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
void handleServerError(final ODataRequest request, final ODataResponse response,
final ODataServerError serverError) {
try {
ODataSerializer serializer = this.odata.createSerializer(this.contentType);
ErrorResponse errorResponse = new ErrorResponse(this.metadata, serializer, this.contentType, response);
handler.processError(serverError, errorResponse);
} catch (Exception e) {
// This should never happen but to be sure we have this catch here
// to prevent sending a stacktrace to a client.
String responseContent = "{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred during "
+ "error processing with message: " + e.getMessage() + "\"}}"; //$NON-NLS-1$ //$NON-NLS-2$
response.setContent(new ByteArrayInputStream(responseContent.getBytes()));
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE,
ContentType.APPLICATION_JSON.toContentTypeString());
}
}
示例10: readServiceDocument
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的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
if (isNotModified) {
response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
} else {
ODataSerializer serializer = odata.createSerializer(requestedContentType);
response.setContent(serializer.serviceDocument(serviceMetadata, request.getRawBaseUri()).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
}
示例11: readMetadata
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的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());
}
}
示例12: createEntity
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
public void createEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat,
ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(resourcePaths.size() - 1);
EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
EdmEntityType entityType = edmEntitySet.getEntityType();
InputStream requestInputStream = request.getBody();
ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat);
DeserializerResult result = deserializer.entity(requestInputStream, entityType);
Entity requestEntity = result.getEntity();
Entity createdEntity = createEntityData(edmEntitySet, requestEntity);
ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
EntitySerializerOptions options = EntitySerializerOptions.with().contextURL(contextUrl).build();
ODataSerializer serializer = this.odata.createSerializer(responseFormat);
SerializerResult serializedResponse = serializer.entity(serviceMetadata, entityType, createdEntity, options);
response.setContent(serializedResponse.getContent());
response.setStatusCode(HttpStatusCode.CREATED.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
示例13: readEntity
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
public void readEntity(
ODataRequest request,
ODataResponse response,
UriInfo uriInfo,
ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
// First path segment is Entity Set.
List<UriResource> resourceParts = uriInfo.getUriResourceParts();
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourceParts.get(0);
EdmEntitySet entitySet = uriResourceEntitySet.getEntitySet();
List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates();
// Retrieve entity from backend.
Entity entity = entityRepository.read(entitySet, keyPredicates);
// Serialize to response format.
ContextURL contextUrl = ContextURL.with()
.entitySet(entitySet)
.suffix(ContextURL.Suffix.ENTITY)
.build();
EntitySerializerOptions options = EntitySerializerOptions.with()
.contextURL(contextUrl)
.build();
ODataSerializer serializer = odata.createSerializer(responseFormat);
SerializerResult serializerResult = serializer.entity(
serviceMetadata, entitySet.getEntityType(), entity, options);
// Set response attributes.
response.setContent(serializerResult.getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
示例14: readEntityCollection
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
public void readEntityCollection(
ODataRequest request,
ODataResponse response,
UriInfo uriInfo,
ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
// First path segment is Entity Set.
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
EdmEntitySet entitySet = uriResourceEntitySet.getEntitySet();
// Retrieve entities from backend.
EntityCollection entityCollection = entityRepository.list(entitySet, uriInfo);
// Serialize to response format.
ContextURL contextUrl = ContextURL.with()
.entitySet(entitySet)
.build();
EntityCollectionSerializerOptions options = EntityCollectionSerializerOptions.with()
.id(request.getRawBaseUri() + "/" + entitySet.getName())
.contextURL(contextUrl)
.build();
ODataSerializer serializer = odata.createSerializer(responseFormat);
SerializerResult serializerResult = serializer.entityCollection(
serviceMetadata, entitySet.getEntityType(), entityCollection, options);
// Set response attributes.
response.setContent(serializerResult.getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
开发者ID:pukkaone,项目名称:odata-spring-boot-starter,代码行数:33,代码来源:ElasticsearchEntityCollectionProcessor.java
示例15: processError
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
public void processError(ODataRequest request, ODataResponse response, ODataServerError serverError,
ContentType responseFormat) {
try {
ODataSerializer serializer = odata.createSerializer(responseFormat);
response.setContent(serializer.error(serverError).getContent());
response.setStatusCode(serverError.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
switch (serverError.getStatusCode()) {
case 404:
break;
default:
//Only log severe errors, not 404 etc
if (serverError.getException() != null) {
log.error(request.getMethod() + ": " + request.getRawRequestUri() + " Error: "
+ serverError.getException().getMessage() + "\nCause: "
+ serverError.getException().getCause());
} else {
log.error(request.getMethod() + ": " + request.getRawRequestUri() + " Error: "
+ serverError.getException().getMessage());
}
}
} catch (Exception e) {
// This should never happen but to be sure we have this catch here to prevent sending a stacktrace to a client.
String responseContent = "{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred during error processing\"}}";
response.setContent(new ByteArrayInputStream(responseContent.getBytes(Charset.forName("utf-8"))));
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
}
}