From febf6ed5cfc24392627cb27f6c0962ab79089d4d Mon Sep 17 00:00:00 2001
From: mibo
Date: Mon, 15 Feb 2016 22:24:30 +0100
Subject: [PATCH] [OLINGO-856] Added OlingoExtension interface
---
.../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(-)
create mode 100644 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/ODataHandler.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataHandler.java
index d1ba14b03..8e46f6738 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;
/**
* Handles requests as OData requests.
@@ -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
+ * Registers additional extensions for handling OData requests.
+ * This method is used for registration of all possible extensions
+ * and provide the extensibility for further extensions and
+ * different ODataHandler implementations/extensions.
*/
- 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);
}
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 da26074b1..4c18e2e25 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);
}
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 000000000..92accba71
--- /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 {
+}
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 8a624272f..7fa7cd694 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.
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 873db1355..d758f0fe8 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;
/**
* 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
*/
-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.
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 4e6314852..b7e7c7af4 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;
/**
* Processors that supports custom content types can implement this interface.
@@ -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).
*/
-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 modifySupportedContentTypes(
+ List modifySupportedContentTypes(
List defaultContentTypes, RepresentationType type);
}
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 0b5a8d84f..3c2a903dd 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;
}
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 492e4d4ee..2bf73ab1e 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;
@@ -296,6 +297,11 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
handler.register(processor);
}
+ @Override
+ public void register(OlingoExtension extension) {
+ handler.register(extension);
+ }
+
@Override
public void register(final CustomContentTypeSupport customContentTypeSupport) {
handler.register(customContentTypeSupport);