[OLINGO-482] Refactor Processor Interfaces

This commit is contained in:
Michael Bolz 2014-12-09 15:11:32 +01:00
parent 5f18ea2e09
commit aee1ebe372
19 changed files with 335 additions and 130 deletions

View File

@ -37,10 +37,10 @@ public interface ComplexCollectionProcessor extends Processor {
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readComplexCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readComplexCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -36,10 +36,10 @@ public interface ComplexProcessor extends Processor {
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readComplex(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readComplex(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling counting a collection of complex properties, e.g. an EdmComplexType.
*/
public interface CountComplexCollectionProcessor extends Processor {
/**
* Counts complex properties from persistence and puts serialized content and status into the response.
* Response content type is <code>text/plain</code> by default.
* @param request OData request object containing raw HTTP information.
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void countComplexCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -26,7 +26,7 @@ import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling counting a collection of entities, e.g., an Entity Set.
* Processor interface for handling counting a collection of entities, e.g. an Entity Set.
*/
public interface CountEntityCollectionProcessor extends Processor {
@ -36,10 +36,10 @@ public interface CountEntityCollectionProcessor extends Processor {
* @param request OData request object containing raw HTTP information.
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void countEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void countEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling counting a collection of primitive properties, e.g. an collection of EdmString.
*/
public interface CountPrimitiveCollectionProcessor extends Processor {
/**
* Counts primitive properties from persistence and puts serialized content and status into the response.
* Response content type is <code>text/plain</code> by default.
* @param request OData request object containing raw HTTP information.
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void countPrimitiveCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -35,10 +35,10 @@ public interface EntityCollectionProcessor extends Processor {
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -22,6 +22,7 @@ import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
@ -35,10 +36,34 @@ public interface EntityProcessor extends Processor {
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
/**
* Creates entity media data in the persistence and puts content, status, and Location into the response.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param requestFormat content type of body sent with request
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws DeserializerException if deserialization failed
* @throws SerializerException if serialization failed
*/
void createEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException;
/**
* Deletes entity media data from persistence and puts the status into the response.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @throws ODataApplicationException if the service implementation encounters a failure
*/
void deleteEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo) throws ODataApplicationException;
}

View File

@ -33,8 +33,8 @@ public interface ExceptionProcessor extends Processor {
* @param request the request
* @param response the response
* @param serverError the server error
* @param format the requested format for the error message
* @param responseFormat the requested format for the error message
*/
public void processException(ODataRequest request, ODataResponse response, ODataServerError serverError,
ContentType format);
ContentType responseFormat);
}

View File

@ -29,52 +29,32 @@ import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling Entity Media.
*/
public interface MediaProcessor extends Processor {
public interface MediaEntityProcessor extends EntityProcessor {
/**
* Reads entity media data from persistence and puts content and status into the response.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readMedia(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readMediaEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
/**
* Creates entity media data in the persistence and puts content, status, and Location into the response.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws DeserializerException if deserialization failed
* @throws SerializerException if serialization failed
*/
void createMedia(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, DeserializerException, SerializerException;
/**
* Updates entity media data in the persistence and puts content and status into the response.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param requestFormat content type of body sent with request
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws DeserializerException if deserialization failed
* @throws SerializerException if serialization failed
*/
void updateMedia(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void updateMediaEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException;
/**
* Deletes entity media data from persistence and puts the status into the response.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @throws ODataApplicationException if the service implementation encounters a failure
*/
void deleteMedia(ODataRequest request, ODataResponse response, UriInfo uriInfo) throws ODataApplicationException;
}

View File

@ -35,10 +35,10 @@ public interface MetadataProcessor extends Processor {
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readMetadata(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readMetadata(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -37,10 +37,11 @@ public interface PrimitiveCollectionProcessor extends Processor {
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readPrimitiveCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readPrimitiveCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -37,24 +37,10 @@ public interface PrimitiveProcessor extends Processor {
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readPrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException;
/**
* Reads raw value of a primitive-type instance, e.g., of a primitive property of an entity.
* If the value is <code>null</code>, the service responds with 204 No Content.
* If it is not available, for example due to permissions, the service responds with 404 Not Found.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readPrimitiveAsValue(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readPrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
* Processor interface for handling an instance of a primitive type, e.g., a primitive property of an entity.
*/
public interface PrimitiveValueProcessor extends PrimitiveProcessor {
/**
* Reads raw value of a primitive-type instance, e.g., of a primitive property of an entity.
* If the value is <code>null</code>, the service responds with 204 No Content.
* If it is not available, for example due to permissions, the service responds with 404 Not Found.
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param responseFormat requested content type after content negotiation
* @throws org.apache.olingo.server.api.ODataApplicationException if the service implementation encounters a failure
* @throws org.apache.olingo.server.api.serializer.SerializerException if serialization failed
*/
void readPrimitiveValue(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -35,10 +35,10 @@ public interface ServiceDocumentProcessor extends Processor {
* @param request OData request object containing raw HTTP information
* @param response OData response object for collecting response data
* @param uriInfo information of a parsed OData URI
* @param format requested content type after content negotiation
* @param responseFormat requested content type after content negotiation
* @throws ODataApplicationException if the service implementation encounters a failure
* @throws SerializerException if serialization failed
*/
void readServiceDocument(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
void readServiceDocument(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
throws ODataApplicationException, SerializerException;
}

View File

@ -46,10 +46,11 @@ import org.apache.olingo.server.api.processor.DefaultProcessor;
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
import org.apache.olingo.server.api.processor.ExceptionProcessor;
import org.apache.olingo.server.api.processor.MediaProcessor;
import org.apache.olingo.server.api.processor.MediaEntityProcessor;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
import org.apache.olingo.server.api.processor.PrimitiveProcessor;
import org.apache.olingo.server.api.processor.PrimitiveValueProcessor;
import org.apache.olingo.server.api.processor.Processor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
@ -219,10 +220,12 @@ public class ODataHandler {
.readEntityCollection(request, response, uriInfo, requestedContentType);
} else if (method.equals(HttpMethod.POST)) {
if (isMedia(lastPathSegment)) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(MediaProcessor.class)
.createMedia(request, response, uriInfo, requestedContentType);
final ContentType requestFormat =
ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
selectProcessor(MediaEntityProcessor.class)
.createEntity(request, response, uriInfo, requestFormat, responseFormat);
} else {
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
@ -240,8 +243,8 @@ public class ODataHandler {
.readEntity(request, response, uriInfo, requestedContentType);
} else if (method.equals(HttpMethod.DELETE)) {
if (isMedia(lastPathSegment)) {
selectProcessor(MediaProcessor.class)
.deleteMedia(request, response, uriInfo);
selectProcessor(MediaEntityProcessor.class)
.deleteEntity(request, response, uriInfo);
} else {
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
@ -321,8 +324,8 @@ public class ODataHandler {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, representationType);
selectProcessor(PrimitiveProcessor.class)
.readPrimitiveAsValue(request, response, uriInfo, requestedContentType);
selectProcessor(PrimitiveValueProcessor.class)
.readPrimitiveValue(request, response, uriInfo, requestedContentType);
} else {
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
@ -331,16 +334,18 @@ public class ODataHandler {
if (method.equals(HttpMethod.GET)) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.MEDIA);
selectProcessor(MediaProcessor.class)
.readMedia(request, response, uriInfo, requestedContentType);
selectProcessor(MediaEntityProcessor.class)
.readMediaEntity(request, response, uriInfo, requestedContentType);
} else if (method.equals(HttpMethod.PUT)) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(MediaProcessor.class)
.updateMedia(request, response, uriInfo, requestedContentType);
final ContentType requestFormat =
ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(MediaEntityProcessor.class)
.updateMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
} else if (method.equals(HttpMethod.DELETE)) {
selectProcessor(MediaProcessor.class)
.deleteMedia(request, response, uriInfo);
selectProcessor(MediaEntityProcessor.class)
.deleteEntity(request, response, uriInfo);
} else {
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);

View File

@ -37,7 +37,7 @@ import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
import org.apache.olingo.server.api.processor.MediaProcessor;
import org.apache.olingo.server.api.processor.MediaEntityProcessor;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
@ -54,7 +54,7 @@ import org.apache.olingo.server.tecsvc.data.DataProvider;
* Technical Processor for entity-related functionality.
*/
public class TechnicalEntityProcessor extends TechnicalProcessor
implements EntityCollectionProcessor, CountEntityCollectionProcessor, EntityProcessor, MediaProcessor {
implements EntityCollectionProcessor, CountEntityCollectionProcessor, EntityProcessor, MediaEntityProcessor {
public TechnicalEntityProcessor(final DataProvider dataProvider) {
super(dataProvider);
@ -136,8 +136,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
}
@Override
public void readMedia(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
public void readMediaEntity(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType responseFormat) throws ODataApplicationException, SerializerException {
blockNavigation(uriInfo);
final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) uriInfo.getUriResourceParts().get(0);
final Entity entity = dataProvider.read(resourceEntitySet.getEntitySet(), resourceEntitySet.getKeyPredicates());
@ -152,8 +152,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
}
@Override
public void createMedia(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType)
public void createEntity(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockNavigation(uriInfo);
final String contentType = request.getHeader(HttpHeader.CONTENT_TYPE);
@ -166,8 +166,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
}
@Override
public void updateMedia(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType)
public void updateMediaEntity(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
blockNavigation(uriInfo);
final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) uriInfo.getUriResourceParts().get(0);
@ -183,7 +183,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
}
dataProvider.setMedia(entity, odata.createFixedFormatDeserializer().binary(request.getBody()), contentType);
final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
final ODataFormat format = ODataFormat.fromContentType(responseFormat);
ODataSerializer serializer = odata.createSerializer(format);
response.setContent(serializer.entity(edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
@ -191,11 +191,11 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
getContextUrl(serializer, edmEntitySet, true, null, null))
.build()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
@Override
public void deleteMedia(final ODataRequest request, ODataResponse response, final UriInfo uriInfo)
public void deleteEntity(final ODataRequest request, ODataResponse response, final UriInfo uriInfo)
throws ODataApplicationException {
blockNavigation(uriInfo);
final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) uriInfo.getUriResourceParts().get(0);

View File

@ -43,6 +43,7 @@ import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ComplexProcessor;
import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
import org.apache.olingo.server.api.processor.PrimitiveProcessor;
import org.apache.olingo.server.api.processor.PrimitiveValueProcessor;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
import org.apache.olingo.server.api.serializer.ODataSerializer;
@ -64,7 +65,8 @@ import org.apache.olingo.server.tecsvc.data.DataProvider;
* Technical Processor which provides functionality related to primitive and complex types and collections thereof.
*/
public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
implements PrimitiveProcessor, PrimitiveCollectionProcessor, ComplexProcessor, ComplexCollectionProcessor {
implements PrimitiveProcessor, PrimitiveValueProcessor, PrimitiveCollectionProcessor,
ComplexProcessor, ComplexCollectionProcessor {
public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider) {
super(dataProvider);
@ -200,7 +202,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
}
@Override
public void readPrimitiveAsValue(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
public void readPrimitiveValue(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException {
final UriInfoResource resource = uriInfo.asUriInfoResource();
validateOptions(resource);

View File

@ -53,10 +53,11 @@ import org.apache.olingo.server.api.processor.ComplexProcessor;
import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
import org.apache.olingo.server.api.processor.MediaProcessor;
import org.apache.olingo.server.api.processor.MediaEntityProcessor;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
import org.apache.olingo.server.api.processor.PrimitiveProcessor;
import org.apache.olingo.server.api.processor.PrimitiveValueProcessor;
import org.apache.olingo.server.api.processor.Processor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
import org.apache.olingo.server.api.uri.UriInfo;
@ -259,45 +260,45 @@ public class ODataHandlerTest {
@Test
public void dispatchMedia() throws Exception {
final MediaProcessor processor = mock(MediaProcessor.class);
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
dispatch(HttpMethod.GET, "ESMedia(1)/$value", processor);
verify(processor).readMedia(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
verify(processor).readMediaEntity(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
}
@Test
public void dispatchMediaCreate() throws Exception {
final MediaProcessor processor = mock(MediaProcessor.class);
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
dispatch(HttpMethod.POST, "ESMedia", processor);
verify(processor).createMedia(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
verify(processor).createEntity(any(ODataRequest.class), any(ODataResponse.class),
any(UriInfo.class), any(ContentType.class), any(ContentType.class));
}
@Test
public void dispatchMediaPut() throws Exception {
final MediaProcessor processor = mock(MediaProcessor.class);
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
dispatch(HttpMethod.PUT, "ESMedia(1)/$value", processor);
verify(processor).updateMedia(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
verify(processor).updateMediaEntity(any(ODataRequest.class), any(ODataResponse.class),
any(UriInfo.class), any(ContentType.class), any(ContentType.class));
}
@Test
public void dispatchMediaDelete() throws Exception {
final MediaProcessor processor = mock(MediaProcessor.class);
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
dispatch(HttpMethod.DELETE, "ESMedia(1)/$value", processor);
verify(processor).deleteMedia(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
verify(processor).deleteEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
}
@Test
public void dispatchMediaDeleteIndirect() throws Exception {
final MediaProcessor processor = mock(MediaProcessor.class);
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
dispatch(HttpMethod.DELETE, "ESMedia(1)", processor);
verify(processor).deleteMedia(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
verify(processor).deleteEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
}
@Test
@ -311,11 +312,11 @@ public class ODataHandlerTest {
@Test
public void dispatchPrimitivePropertyValue() throws Exception {
final PrimitiveProcessor processor = mock(PrimitiveProcessor.class);
final PrimitiveValueProcessor processor = mock(PrimitiveValueProcessor.class);
dispatch(HttpMethod.GET, "ESAllPrim(0)/PropertyInt16/$value", processor);
verify(processor).readPrimitiveAsValue(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
verify(processor).readPrimitiveValue(any(ODataRequest.class), any(ODataResponse.class),
any(UriInfo.class), any(ContentType.class));
}
@Test

View File

@ -18,7 +18,9 @@
*/
package org.apache.olingo.server.sample.processor;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;
@ -33,6 +35,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpContentType;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.server.api.OData;
@ -40,10 +43,13 @@ import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.processor.ComplexProcessor;
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
import org.apache.olingo.server.api.processor.MediaEntityProcessor;
import org.apache.olingo.server.api.processor.PrimitiveProcessor;
import org.apache.olingo.server.api.processor.PrimitiveValueProcessor;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
@ -65,8 +71,8 @@ import org.apache.olingo.server.sample.data.DataProvider.DataProviderException;
* This is a very simple example which should give you a rough guideline on how to implement such an processor.
* See the JavaDoc of the server.api interfaces for more information.
*/
public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor,
PrimitiveProcessor, ComplexProcessor {
public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor, MediaEntityProcessor,
PrimitiveProcessor, PrimitiveValueProcessor, ComplexProcessor {
private OData odata;
private DataProvider dataProvider;
@ -150,6 +156,86 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
}
}
@Override
public void createEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void deleteEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo)
throws ODataApplicationException {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void readPrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException {
readProperty(response, uriInfo, format, false);
}
@Override
public void readComplex(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException {
readProperty(response, uriInfo, format, true);
}
@Override
public void readPrimitiveValue(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException {
// First we have to figure out which entity set the requested entity is in
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource());
// Next we fetch the requested entity from the database
final Entity entity;
try {
entity = readEntityInternal(uriInfo.asUriInfoResource(), edmEntitySet);
} catch (DataProviderException e) {
throw new ODataApplicationException(e.getMessage(), 500, Locale.ENGLISH);
}
if (entity == null) {
// If no entity was found for the given key we throw an exception.
throw new ODataApplicationException("No entity found for this key", HttpStatusCode.NOT_FOUND
.getStatusCode(), Locale.ENGLISH);
} else {
// Next we get the property value from the entity and pass the value to serialization
UriResourceProperty uriProperty = (UriResourceProperty) uriInfo
.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 1);
EdmProperty edmProperty = uriProperty.getProperty();
Property property = entity.getProperty(edmProperty.getName());
if (property == null) {
throw new ODataApplicationException("No property found", HttpStatusCode.NOT_FOUND
.getStatusCode(), Locale.ENGLISH);
} else {
if (property.getValue() == null) {
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
} else {
String value = String.valueOf(property.getValue());
ByteArrayInputStream serializerContent = new ByteArrayInputStream(
value.getBytes(Charset.forName("UTF-8")));
response.setContent(serializerContent);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, HttpContentType.TEXT_PLAIN);
}
}
}
}
@Override
public void readMediaEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType responseFormat)
throws ODataApplicationException, SerializerException {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void updateMediaEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
throw new UnsupportedOperationException("Not yet implemented");
}
private void readProperty(ODataResponse response, UriInfo uriInfo, ContentType contentType,
boolean complex) throws ODataApplicationException, SerializerException {
// To read a property we have to first get the entity out of the entity set
@ -172,7 +258,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
EdmProperty edmProperty = uriProperty.getProperty();
Property property = entity.getProperty(edmProperty.getName());
if (property == null) {
throw new ODataApplicationException("No porperty found", HttpStatusCode.NOT_FOUND
throw new ODataApplicationException("No property found", HttpStatusCode.NOT_FOUND
.getStatusCode(), Locale.ENGLISH);
} else {
if (property.getValue() == null) {
@ -231,23 +317,4 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
.navOrPropertyPath(navOrPropertyPath)
.build();
}
@Override
public void readPrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException {
readProperty(response, uriInfo, format, false);
}
@Override
public void readComplex(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException {
readProperty(response, uriInfo, format, true);
}
@Override
public void readPrimitiveAsValue(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException {
throw new ODataApplicationException("Not implemented for this sample",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
}
}