本文整理汇总了Java中org.apache.olingo.server.api.serializer.ODataSerializer类的典型用法代码示例。如果您正苦于以下问题:Java ODataSerializer类的具体用法?Java ODataSerializer怎么用?Java ODataSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataSerializer类属于org.apache.olingo.server.api.serializer包,在下文中一共展示了ODataSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:26,代码来源:SparqlDefaultProcessor.java
示例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());
}
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:25,代码来源:SparqlDefaultProcessor.java
示例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;
}
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:24,代码来源:ElasticOData.java
示例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());
}
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:19,代码来源:AbstractESReadProcessor.java
示例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());
}
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:17,代码来源:PrimitiveProcessorImpl.java
示例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();
}
开发者ID:kenweezy,项目名称:teiid,代码行数:17,代码来源:TeiidProcessor.java
示例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());
}
}
开发者ID:apache,项目名称:olingo-odata4,代码行数:19,代码来源:DefaultProcessor.java
示例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;
}
}
开发者ID:apache,项目名称:olingo-odata4,代码行数:25,代码来源:ODataImpl.java
示例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());
}
}
开发者ID:apache,项目名称:olingo-odata4,代码行数:18,代码来源:ErrorHandler.java
示例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());
}
}
开发者ID:jbaliuka,项目名称:sql-analytic,代码行数:25,代码来源:SQLServiceDocumentProcessor.java
示例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());
}
}
开发者ID:jbaliuka,项目名称:sql-analytic,代码行数:25,代码来源:SQLServiceDocumentProcessor.java
示例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());
}
开发者ID:jbaliuka,项目名称:sql-analytic,代码行数:23,代码来源:SQLEntityProcessor.java
示例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());
}
开发者ID:pukkaone,项目名称:odata-spring-boot-starter,代码行数:34,代码来源:ElasticsearchEntityProcessor.java
示例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());
}
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:32,代码来源:SparqlDefaultProcessor.java
示例16: 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());
}
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:28,代码来源:SparqlErrorProcessor.java
示例17: writeProperty
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
private void writeProperty(ODataRequest request, ODataResponse response, ContentType responseFormat,
EdmEntitySet edmEntitySet, String edmPropertyName, EdmPrimitiveType edmPropertyType, Property property)
throws SerializerException, ODataApplicationException {
Object value = property.getValue();
if (value != null) {
// 3.1. configure the serializer
ODataSerializer serializer = odata.createSerializer(responseFormat);
ContextURL contextUrl = null;
try {
//Need absolute URI for PowewrQuery and Linqpad (and probably other MS based OData clients)
contextUrl = ContextURL.with().entitySet(edmEntitySet).navOrPropertyPath(edmPropertyName)
.serviceRoot(new URI(request.getRawBaseUri() + "/")).build();
} catch (URISyntaxException e) {
throw new ODataApplicationException("Inavlid RawBaseURI " + request.getRawBaseUri(),
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
}
PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextUrl).build();
// 3.2. serialize
SerializerResult serializerResult = serializer.primitive(serviceMetadata, edmPropertyType, property,
options);
InputStream propertyStream = serializerResult.getContent();
//4. configure the response object
response.setContent(propertyStream);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
} else {
// in case there's no value for the property, we can skip the serialization
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:34,代码来源:SparqlPrimitiveValueProcessor.java
示例18: 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 {
// 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.entity(requestInputStream, edmEntityType);
Entity requestEntity = result.getEntity();
// 2.2 do the creation in backend, which returns the newly created entity
Entity createdEntity = null;
try {
createdEntity = SparqlBaseCommand.writeEntity(rdfEdmProvider, uriInfo, requestEntity);
if (createdEntity == null)
throw new OData2SparqlException("Entity not created");
} catch (EdmException | OData2SparqlException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.NO_CONTENT.getStatusCode(),
Locale.ENGLISH);
}
// 3. serialize the response (we have to return the created entity)
ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
// expand and select currently not supported
EntitySerializerOptions options = EntitySerializerOptions.with().contextURL(contextUrl).build();
ODataSerializer serializer = this.odata.createSerializer(responseFormat);
SerializerResult serializedResponse = serializer.entity(serviceMetadata, edmEntityType, createdEntity, options);
//4. configure the response object
response.setContent(serializedResponse.getContent());
response.setStatusCode(HttpStatusCode.CREATED.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:39,代码来源:SparqlEntityProcessor.java
示例19: serialize
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
protected SerializerResult serialize(ODataSerializer serializer,
InstanceData<EdmEntityType, AbstractEntityCollection> data,
ElasticEdmEntitySet entitySet, UriInfo uriInfo) throws SerializerException {
String id = request.getRawBaseUri() + "/" + entitySet.getEntityType();
ExpandOption expand = uriInfo.getExpandOption();
SelectOption select = uriInfo.getSelectOption();
CountOption count = uriInfo.getCountOption();
return serializer.entityCollection(serviceMetadata, data.getType(), data.getValue(),
EntityCollectionSerializerOptions.with()
.contextURL(createContextUrl(entitySet, false, expand, select, null)).id(id)
.count(count).select(select).expand(expand).build());
}
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:14,代码来源:AbstractESCollectionProcessor.java
示例20: serialize
import org.apache.olingo.server.api.serializer.ODataSerializer; //导入依赖的package包/类
@Override
protected SerializerResult serialize(ODataSerializer serializer,
InstanceData<EdmEntityType, Entity> data, ElasticEdmEntitySet entitySet,
UriInfo uriInfo) throws SerializerException {
ExpandOption expand = uriInfo.getExpandOption();
SelectOption select = uriInfo.getSelectOption();
return serializer.entity(serviceMetadata, data.getType(), data.getValue(),
EntitySerializerOptions.with()
.contextURL(createContextUrl(entitySet, true, expand, select, null))
.select(select).expand(expand).build());
}
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:12,代码来源:EntityProcessorImpl.java
注:本文中的org.apache.olingo.server.api.serializer.ODataSerializer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论