[OLINGO-856] Added OlingoExtension interface

This commit is contained in:
mibo 2016-02-15 22:24:30 +01:00
parent e07abf0b0f
commit febf6ed5cf
8 changed files with 74 additions and 26 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 {
}

View File

@ -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.

View File

@ -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.

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);