[OLINGO-856] Created ODataHandler Interface

This commit is contained in:
mibo 2016-02-13 07:08:33 +01:00
parent 3c205f907e
commit e07abf0b0f
13 changed files with 114 additions and 54 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,63 @@
/*
* 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.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>
*
* <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);
/**
* 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

@ -22,17 +22,14 @@ 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.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>
@ -41,36 +38,16 @@ 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>
*/
void register(Processor processor);
/**
* Registers a service implementation for modifying the standard list of supported
* content types.
* @see CustomContentTypeSupport
*/
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
*/
void register(CustomETagSupport customConcurrencyControlSupport);
/**
* Registers the debug support handler.
* @param debugSupport
* @param debugSupport handler to register
*/
void register(DebugSupport debugSupport);
}

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

@ -27,6 +27,7 @@ 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;
@ -50,7 +51,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 +64,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;

View File

@ -55,14 +55,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
@ -76,7 +81,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;

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());
}
@ -738,7 +738,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);