[OLINGO-856] Merge branch 'OLINGO-856_ODataHandlerInAPI'

This commit is contained in:
mibo 2016-03-04 21:24:10 +01:00
commit 59699da030
17 changed files with 172 additions and 64 deletions

View File

@ -97,6 +97,13 @@ public abstract class OData {
*/
public abstract ODataHttpHandler createHandler(ServiceMetadata serviceMetadata);
/**
* Creates a new ODataHandler for handling OData requests.
*
* @param serviceMetadata - metadata object required to handle an OData request
*/
public abstract ODataHandler createBasicHandler(ServiceMetadata serviceMetadata);
/**
* Creates a metadata object for this service.
*

View File

@ -0,0 +1,56 @@
/*
* 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;
import org.apache.olingo.server.api.processor.Processor;
/**
* <p>Handles requests as OData requests.</p>
*
* <p>This includes URI parsing, content negotiation, dispatching the request
* to a specific custom processor implementation for handling data and
* creating the serialized content for the response object.</p>
*/
public interface ODataHandler {
/**
* <p>Processes an OData request.</p>
* <p>This includes URI parsing, content negotiation, dispatching the request
* to a specific custom processor implementation for handling data and
* creating the serialized content for the response object.</p>
* @param request the OData request
* @return OData response
*/
ODataResponse process(final ODataRequest request);
/**
* <p>Registers additional custom processor implementations for handling OData requests.</p>
* <p>If request processing requires a processor that is not registered then a
* "not implemented" exception will happen.</p>
*/
void register(Processor processor);
/**
* <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(OlingoExtension extension);
}

View File

@ -23,16 +23,15 @@ 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.processor.Processor;
import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
/**
* Handles HTTP requests as OData requests.
*/
public interface ODataHttpHandler {
public interface ODataHttpHandler extends ODataHandler {
/**
* <p>Processes an OData request.</p>
* <p>Processes a HttpServletRequest as an OData request.</p>
* <p>This includes URI parsing, content negotiation, dispatching the request
* to a specific custom processor implementation for handling data and
* creating the serialized content for the response object.</p>
@ -42,11 +41,17 @@ public interface ODataHttpHandler {
void process(HttpServletRequest request, HttpServletResponse response);
/**
* <p>Registers additional custom processor implementations for handling OData requests.</p>
* <p>If request processing requires a processor that is not registered then a
* "not implemented" exception will happen.</p>
* Sets the split parameter which is used for service resolution.
* @param split the number of path segments reserved for service resolution; default is 0
*/
void register(Processor processor);
void setSplit(int split);
/**
* Registers the debug support handler.
* @param debugSupport handler to register
*/
void register(DebugSupport debugSupport);
/**
* Registers a service implementation for modifying the standard list of supported
@ -55,22 +60,9 @@ public interface ODataHttpHandler {
*/
void register(CustomContentTypeSupport customContentTypeSupport);
/**
* Sets the split parameter which is used for service resolution.
* @param split the number of path segments reserved for service resolution; default is 0
*/
void setSplit(int split);
/**
* Registers support for concurrency control for certain entity sets.
* @param customETagSupport
* @param customETagSupport handler to register
*/
void register(CustomETagSupport customConcurrencyControlSupport);
/**
* Registers the debug support handler.
* @param debugSupport
*/
void register(DebugSupport debugSupport);
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

@ -39,7 +39,7 @@ public class OData4Impl extends ODataImpl {
}
@Override
public ODataHttpHandler createHandler(final ServiceMetadata edm) {
return new OData4HttpHandler(this, edm);
public ODataHttpHandler createHandler(final ServiceMetadata serviceMetadata) {
return new OData4HttpHandler(this, serviceMetadata);
}
}

View File

@ -75,9 +75,9 @@ public class ODataDispatcher {
private static final String NOT_IMPLEMENTED_MESSAGE = "not implemented";
private final UriInfo uriInfo;
private final ODataHandler handler;
private final ODataHandlerImpl handler;
public ODataDispatcher(final UriInfo uriInfo, final ODataHandler handler) {
public ODataDispatcher(final UriInfo uriInfo, final ODataHandlerImpl handler) {
this.uriInfo = uriInfo;
this.handler = handler;
}

View File

@ -22,15 +22,18 @@ 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;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataHandler;
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;
@ -50,7 +53,7 @@ import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
import org.apache.olingo.server.core.uri.validator.UriValidationException;
import org.apache.olingo.server.core.uri.validator.UriValidator;
public class ODataHandler {
public class ODataHandlerImpl implements ODataHandler {
private final OData odata;
private final ServiceMetadata serviceMetadata;
@ -63,8 +66,8 @@ public class ODataHandler {
private UriInfo uriInfo;
private Exception lastThrownException;
public ODataHandler(final OData server, final ServiceMetadata serviceMetadata, final ServerCoreDebugger debugger) {
odata = server;
public ODataHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata, final ServerCoreDebugger debugger) {
this.odata = odata;
this.serviceMetadata = serviceMetadata;
this.debugger = debugger;
@ -206,18 +209,22 @@ public class 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

@ -45,6 +45,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;
@ -57,14 +58,19 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
public static final int COPY_BUFFER_SIZE = 8192;
private final ODataHandler handler;
private final ODataHandlerImpl handler;
private final ServerCoreDebugger debugger;
private int split = 0;
public ODataHttpHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata) {
debugger = new ServerCoreDebugger(odata);
handler = new ODataHandler(odata, serviceMetadata, debugger);
handler = new ODataHandlerImpl(odata, serviceMetadata, debugger);
}
@Override
public ODataResponse process(ODataRequest request) {
return handler.process(request);
}
@Override
@ -78,7 +84,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
try {
fillODataRequest(odRequest, request, split);
odResponse = handler.process(odRequest);
odResponse = process(odRequest);
// ALL future methods after process must not throw exceptions!
} catch (Exception e) {
exception = e;
@ -306,6 +312,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);

View File

@ -27,6 +27,7 @@ import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataHandler;
import org.apache.olingo.server.api.ODataHttpHandler;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.debug.DebugResponseHelper;
@ -42,6 +43,7 @@ import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriHelper;
import org.apache.olingo.server.core.debug.DebugResponseHelperImpl;
import org.apache.olingo.server.core.debug.ServerCoreDebugger;
import org.apache.olingo.server.core.deserializer.FixedFormatDeserializerImpl;
import org.apache.olingo.server.core.deserializer.json.ODataJsonDeserializer;
import org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer;
@ -84,8 +86,13 @@ public class ODataImpl extends OData {
}
@Override
public ODataHttpHandler createHandler(final ServiceMetadata edm) {
return new ODataHttpHandlerImpl(this, edm);
public ODataHttpHandler createHandler(final ServiceMetadata serviceMetadata) {
return new ODataHttpHandlerImpl(this, serviceMetadata);
}
@Override
public ODataHandler createBasicHandler(ServiceMetadata serviceMetadata) {
return new ODataHandlerImpl(this, serviceMetadata, new ServerCoreDebugger(this));
}
@Override

View File

@ -27,7 +27,7 @@ import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerExceptio
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
import org.apache.olingo.server.api.processor.BatchProcessor;
import org.apache.olingo.server.core.ODataHandler;
import org.apache.olingo.server.core.ODataHandlerImpl;
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
public class BatchFacadeImpl implements BatchFacade {
@ -39,8 +39,8 @@ public class BatchFacadeImpl implements BatchFacade {
* @param batchProcessor batch processor
* @param isStrict mode switch (currently not used)
*/
public BatchFacadeImpl(final ODataHandler oDataHandler, final BatchProcessor batchProcessor,
final boolean isStrict) {
public BatchFacadeImpl(final ODataHandlerImpl oDataHandler, final BatchProcessor batchProcessor,
final boolean isStrict) {
partHandler = new BatchPartHandler(oDataHandler, batchProcessor, this);
}

View File

@ -29,14 +29,14 @@ import org.apache.olingo.server.api.batch.BatchFacade;
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
import org.apache.olingo.server.api.processor.BatchProcessor;
import org.apache.olingo.server.core.ODataHandler;
import org.apache.olingo.server.core.ODataHandlerImpl;
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
public class BatchHandler {
private final BatchProcessor batchProcessor;
private final ODataHandler oDataHandler;
private final ODataHandlerImpl oDataHandler;
public BatchHandler(final ODataHandler oDataHandler, final BatchProcessor batchProcessor) {
public BatchHandler(final ODataHandlerImpl oDataHandler, final BatchProcessor batchProcessor) {
this.batchProcessor = batchProcessor;
this.oDataHandler = oDataHandler;

View File

@ -28,17 +28,17 @@ import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerExceptio
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
import org.apache.olingo.server.api.processor.BatchProcessor;
import org.apache.olingo.server.core.ODataHandler;
import org.apache.olingo.server.core.ODataHandlerImpl;
import org.apache.olingo.server.core.batchhandler.referenceRewriting.BatchReferenceRewriter;
public class BatchPartHandler {
private final ODataHandler oDataHandler;
private final ODataHandlerImpl oDataHandler;
private final BatchProcessor batchProcessor;
private final BatchFacade batchFacade;
private final BatchReferenceRewriter rewriter;
public BatchPartHandler(final ODataHandler oDataHandler, final BatchProcessor processor,
final BatchFacade batchFacade) {
public BatchPartHandler(final ODataHandlerImpl oDataHandler, final BatchProcessor processor,
final BatchFacade batchFacade) {
this.oDataHandler = oDataHandler;
batchProcessor = processor;
this.batchFacade = batchFacade;

View File

@ -52,7 +52,7 @@ import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
import org.apache.olingo.server.api.processor.BatchProcessor;
import org.apache.olingo.server.api.serializer.BatchSerializerException;
import org.apache.olingo.server.core.ODataHandler;
import org.apache.olingo.server.core.ODataHandlerImpl;
import org.apache.olingo.server.core.deserializer.batch.BatchLineReader;
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
import org.junit.Before;
@ -67,7 +67,7 @@ public class MockedBatchHandlerTest {
private static final String BATCH_REQUEST_URI = "http://localhost:8080/odata/$batch";
private static final String BASE_URI = "http://localhost:8080/odata";
private static final String CRLF = "\r\n";
private ODataHandler oDataHandler;
private ODataHandlerImpl oDataHandler;
private BatchHandler batchHandler;
private int entityCounter = 1;
@ -77,7 +77,7 @@ public class MockedBatchHandlerTest {
batchProcessor.init(OData.newInstance(), null);
entityCounter = 1;
oDataHandler = mock(ODataHandler.class);
oDataHandler = mock(ODataHandlerImpl.class);
batchHandler = new BatchHandler(oDataHandler, batchProcessor);
}

View File

@ -81,7 +81,7 @@ import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
public class ODataHandlerTest {
public class ODataHandlerImplTest {
private static final String BASE_URI = "http://localhost/odata";
@ -234,7 +234,7 @@ public class ODataHandlerTest {
request.setRawODataPath("EdmException");
final ODataResponse response =
new ODataHandler(odata, serviceMetadata, new ServerCoreDebugger(odata)).process(request);
new ODataHandlerImpl(odata, serviceMetadata, new ServerCoreDebugger(odata)).process(request);
assertNotNull(response);
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
}
@ -784,7 +784,7 @@ public class ODataHandlerTest {
final ServiceMetadata metadata = odata.createServiceMetadata(
new EdmTechProvider(), Collections.<EdmxReference> emptyList());
ODataHandler handler = new ODataHandler(odata, metadata, new ServerCoreDebugger(odata));
ODataHandlerImpl handler = new ODataHandlerImpl(odata, metadata, new ServerCoreDebugger(odata));
if (processor != null) {
handler.register(processor);