Repository: olingo-odata4 Updated Branches: refs/heads/OLINGO-856_ODataHandlerInAPI e07abf0b0 -> febf6ed5c
[OLINGO-856] Added OlingoExtension interface Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/febf6ed5 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/febf6ed5 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/febf6ed5 Branch: refs/heads/OLINGO-856_ODataHandlerInAPI Commit: febf6ed5cfc24392627cb27f6c0962ab79089d4d Parents: e07abf0 Author: mibo <[email protected]> Authored: Mon Feb 15 22:24:30 2016 +0100 Committer: mibo <[email protected]> Committed: Mon Feb 15 22:24:30 2016 +0100 ---------------------------------------------------------------------- .../apache/olingo/server/api/ODataHandler.java | 17 ++++--------- .../olingo/server/api/ODataHttpHandler.java | 15 ++++++++++++ .../olingo/server/api/OlingoExtension.java | 25 ++++++++++++++++++++ .../olingo/server/api/debug/DebugSupport.java | 11 +++++---- .../server/api/etag/CustomETagSupport.java | 3 ++- .../serializer/CustomContentTypeSupport.java | 5 ++-- .../olingo/server/core/ODataHandlerImpl.java | 18 +++++++++----- .../server/core/ODataHttpHandlerImpl.java | 6 +++++ 8 files changed, 74 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/febf6ed5/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHandler.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHandler.java index d1ba14b..8e46f67 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHandler.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHandler.java @@ -18,9 +18,7 @@ */ package org.apache.olingo.server.api; -import org.apache.olingo.server.api.etag.CustomETagSupport; import org.apache.olingo.server.api.processor.Processor; -import org.apache.olingo.server.api.serializer.CustomContentTypeSupport; /** * <p>Handles requests as OData requests.</p> @@ -49,15 +47,10 @@ public interface ODataHandler { void register(Processor processor); /** - * Registers a service implementation for modifying the standard list of supported - * content types. - * @see CustomContentTypeSupport + * <p>Registers additional extensions for handling OData requests.</p> + * <p>This method is used for registration of all possible extensions + * and provide the extensibility for further extensions and + * different ODataHandler implementations/extensions.</p> */ - void register(CustomContentTypeSupport customContentTypeSupport); - - /** - * Registers support for concurrency control for certain entity sets. - * @param customETagSupport handler to register - */ - void register(CustomETagSupport customETagSupport); + void register(OlingoExtension extension); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/febf6ed5/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHttpHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHttpHandler.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHttpHandler.java index da26074..4c18e2e 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHttpHandler.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHttpHandler.java @@ -22,6 +22,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.olingo.server.api.debug.DebugSupport; +import org.apache.olingo.server.api.etag.CustomETagSupport; +import org.apache.olingo.server.api.serializer.CustomContentTypeSupport; /** * Handles HTTP requests as OData requests. @@ -50,4 +52,17 @@ public interface ODataHttpHandler extends ODataHandler { * @param debugSupport handler to register */ void register(DebugSupport debugSupport); + + /** + * Registers a service implementation for modifying the standard list of supported + * content types. + * @see CustomContentTypeSupport + */ + void register(CustomContentTypeSupport customContentTypeSupport); + + /** + * Registers support for concurrency control for certain entity sets. + * @param customETagSupport handler to register + */ + void register(CustomETagSupport customETagSupport); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/febf6ed5/lib/server-api/src/main/java/org/apache/olingo/server/api/OlingoExtension.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/OlingoExtension.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/OlingoExtension.java new file mode 100644 index 0000000..92accba --- /dev/null +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/OlingoExtension.java @@ -0,0 +1,25 @@ +/* + * 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; + +/** + * Marker interface for all possible Olingo extensions. + */ +public interface OlingoExtension { +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/febf6ed5/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java index 8a62427..7fa7cd6 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/debug/DebugSupport.java @@ -20,16 +20,17 @@ package org.apache.olingo.server.api.debug; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ODataResponse; +import org.apache.olingo.server.api.OlingoExtension; /** * Register this interface to add debug support to your service. */ -public interface DebugSupport { +public interface DebugSupport extends OlingoExtension { - public static final String ODATA_DEBUG_QUERY_PARAMETER = "odata-debug"; - public static final String ODATA_DEBUG_JSON = "json"; - public static final String ODATA_DEBUG_HTML = "html"; - public static final String ODATA_DEBUG_DOWNLOAD = "download"; + String ODATA_DEBUG_QUERY_PARAMETER = "odata-debug"; + String ODATA_DEBUG_JSON = "json"; + String ODATA_DEBUG_HTML = "html"; + String ODATA_DEBUG_DOWNLOAD = "download"; /** * Initializes the debug support implementation. http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/febf6ed5/lib/server-api/src/main/java/org/apache/olingo/server/api/etag/CustomETagSupport.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/etag/CustomETagSupport.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/etag/CustomETagSupport.java index 873db13..d758f0f 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/etag/CustomETagSupport.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/etag/CustomETagSupport.java @@ -19,6 +19,7 @@ package org.apache.olingo.server.api.etag; import org.apache.olingo.commons.api.edm.EdmBindingTarget; +import org.apache.olingo.server.api.OlingoExtension; /** * <p>Processors that would like to support etags for certain entity sets can implement this @@ -27,7 +28,7 @@ import org.apache.olingo.commons.api.edm.EdmBindingTarget; * require an if-match/if-none-match or an if-modified-since/if-unmodified-since header. Otherwise the request will * result in a "Precondition Required" response</p> */ -public interface CustomETagSupport { +public interface CustomETagSupport extends OlingoExtension { /** * This method will be called for update requests which target an entity or a property of an entity. http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/febf6ed5/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/CustomContentTypeSupport.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/CustomContentTypeSupport.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/CustomContentTypeSupport.java index 4e63148..b7e7c7a 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/CustomContentTypeSupport.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/CustomContentTypeSupport.java @@ -21,6 +21,7 @@ package org.apache.olingo.server.api.serializer; import java.util.List; import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.server.api.OlingoExtension; /** * <p>Processors that supports custom content types can implement this interface.</p> @@ -33,7 +34,7 @@ import org.apache.olingo.commons.api.format.ContentType; * 406 (Not Acceptable); sending content of an unsupported type results in an * HTTP error 415 (Unsupported Media Type).</p> */ -public interface CustomContentTypeSupport { +public interface CustomContentTypeSupport extends OlingoExtension { /** * Returns a list of supported content types. @@ -41,6 +42,6 @@ public interface CustomContentTypeSupport { * @param type the current type of representation * @return modified list of supported content types */ - public List<ContentType> modifySupportedContentTypes( + List<ContentType> modifySupportedContentTypes( List<ContentType> defaultContentTypes, RepresentationType type); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/febf6ed5/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java index 0b5a8d8..3c2a903 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java @@ -22,6 +22,7 @@ import java.util.LinkedList; import java.util.List; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.ex.ODataRuntimeException; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpMethod; @@ -32,6 +33,7 @@ import org.apache.olingo.server.api.ODataLibraryException; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ODataResponse; import org.apache.olingo.server.api.ODataServerError; +import org.apache.olingo.server.api.OlingoExtension; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.deserializer.DeserializerException; import org.apache.olingo.server.api.etag.CustomETagSupport; @@ -207,18 +209,22 @@ public class ODataHandlerImpl implements ODataHandler { processors.add(0, processor); } - public void register(final CustomContentTypeSupport customContentTypeSupport) { - this.customContentTypeSupport = customContentTypeSupport; + @Override + public void register(OlingoExtension extension) { + if(extension instanceof CustomContentTypeSupport) { + this.customContentTypeSupport = (CustomContentTypeSupport) extension; + } else if(extension instanceof CustomETagSupport) { + this.customETagSupport = (CustomETagSupport) extension; + } else { + throw new ODataRuntimeException("Got not supported exception with class name " + + extension.getClass().getSimpleName()); + } } public CustomContentTypeSupport getCustomContentTypeSupport() { return customContentTypeSupport; } - public void register(final CustomETagSupport customETagSupport) { - this.customETagSupport = customETagSupport; - } - public CustomETagSupport getCustomETagSupport() { return customETagSupport; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/febf6ed5/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java index 492e4d4..2bf73ab 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java @@ -43,6 +43,7 @@ import org.apache.olingo.server.api.ODataLibraryException; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ODataResponse; import org.apache.olingo.server.api.ODataServerError; +import org.apache.olingo.server.api.OlingoExtension; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.debug.DebugSupport; import org.apache.olingo.server.api.deserializer.DeserializerException; @@ -297,6 +298,11 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler { } @Override + public void register(OlingoExtension extension) { + handler.register(extension); + } + + @Override public void register(final CustomContentTypeSupport customContentTypeSupport) { handler.register(customContentTypeSupport); }
