diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ComplexCollectionProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ComplexCollectionProcessor.java index a4eaf0399..e861375e5 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ComplexCollectionProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ComplexCollectionProcessor.java @@ -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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ComplexProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ComplexProcessor.java index e50b29926..534946111 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ComplexProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ComplexProcessor.java @@ -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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountComplexCollectionProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountComplexCollectionProcessor.java new file mode 100644 index 000000000..4ccf31066 --- /dev/null +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountComplexCollectionProcessor.java @@ -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 text/plain 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; +} diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountEntityCollectionProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountEntityCollectionProcessor.java index 1f70b99f6..c2464dc81 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountEntityCollectionProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountEntityCollectionProcessor.java @@ -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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountPrimitiveCollectionProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountPrimitiveCollectionProcessor.java new file mode 100644 index 000000000..0f85f673f --- /dev/null +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CountPrimitiveCollectionProcessor.java @@ -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 text/plain 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; +} diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityCollectionProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityCollectionProcessor.java index 6a65eee4b..09d714340 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityCollectionProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityCollectionProcessor.java @@ -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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java index 585a7549f..2c9078c3e 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java @@ -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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java index 19d3ae691..b98d41a8b 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java @@ -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); } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MediaProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MediaEntityProcessor.java similarity index 59% rename from lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MediaProcessor.java rename to lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MediaEntityProcessor.java index fb8ce7d00..945c5af6a 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MediaProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MediaEntityProcessor.java @@ -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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java index 54e63d32a..211220a8c 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java @@ -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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveCollectionProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveCollectionProcessor.java index 7ceaf6170..330b2d4c8 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveCollectionProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveCollectionProcessor.java @@ -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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveProcessor.java index fbc692fcb..a7d4b6857 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveProcessor.java @@ -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 null, 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; } diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveValueProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveValueProcessor.java new file mode 100644 index 000000000..0770c2e34 --- /dev/null +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/PrimitiveValueProcessor.java @@ -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 null, 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; +} diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java index 3c8fba36b..c040ec37b 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java @@ -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; } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java index 51b328b0e..3f899decb 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java @@ -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); diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java index 700e3cf69..016b7b295 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java @@ -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); diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java index 09e9e8f08..5c0c88a75 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java @@ -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); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java index cad616da8..67ce094ae 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java @@ -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 diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java index 5cfce3120..4fcd381e3 100644 --- a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java +++ b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java @@ -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); - } }