mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-06 16:49:09 +00:00
[OLINGO-482] Merge branch 'OLINGO-482-ReFactor-Processor-Interfaces'
This commit is contained in:
commit
0a5081271b
@ -29,8 +29,8 @@ import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
|
||||
public interface BatchProcessor extends Processor {
|
||||
// TODO:Check exception signature
|
||||
void executeBatch(BatchFacade facade, ODataRequest request, ODataResponse response)
|
||||
void processBatch(BatchFacade facade, ODataRequest request, ODataResponse response)
|
||||
throws SerializerException, BatchException;
|
||||
|
||||
ODataResponsePart executeChangeSet(BatchFacade facade, List<ODataRequest> requests);
|
||||
ODataResponsePart processChangeSet(BatchFacade facade, List<ODataRequest> requests);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.apache.olingo.server.api.processor;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
@ -36,11 +35,9 @@ public interface CountComplexCollectionProcessor extends Processor {
|
||||
* @param request OData request object containing raw HTTP information.
|
||||
* @param response OData response object for collecting response data
|
||||
* @param uriInfo information of a parsed OData URI
|
||||
* @param responseFormat requested content type after content negotiation
|
||||
* @throws ODataApplicationException if the service implementation encounters a failure
|
||||
* @throws SerializerException if serialization failed
|
||||
*/
|
||||
void countComplexCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
|
||||
ContentType responseFormat)
|
||||
void countComplexCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo)
|
||||
throws ODataApplicationException, SerializerException;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.apache.olingo.server.api.processor;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
@ -36,10 +35,9 @@ public interface CountEntityCollectionProcessor extends Processor {
|
||||
* @param request OData request object containing raw HTTP information.
|
||||
* @param response OData response object for collecting response data
|
||||
* @param uriInfo information of a parsed OData URI
|
||||
* @param responseFormat requested content type after content negotiation
|
||||
* @throws ODataApplicationException if the service implementation encounters a failure
|
||||
* @throws SerializerException if serialization failed
|
||||
*/
|
||||
void countEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
|
||||
void countEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo)
|
||||
throws ODataApplicationException, SerializerException;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ import org.apache.olingo.server.api.uri.UriInfo;
|
||||
* <p>This implementation is registered in the ODataHandler by default.
|
||||
* The default can be replaced by re-registering a custom implementation.</p>
|
||||
*/
|
||||
public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProcessor, ExceptionProcessor {
|
||||
public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProcessor, ErrorProcessor {
|
||||
private OData odata;
|
||||
private ServiceMetadata serviceMetadata;
|
||||
|
||||
@ -71,8 +71,8 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processException(ODataRequest request, ODataResponse response, ODataServerError serverError,
|
||||
ContentType requestedContentType) {
|
||||
public void processError(ODataRequest request, ODataResponse response, ODataServerError serverError,
|
||||
ContentType requestedContentType) {
|
||||
try {
|
||||
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
|
||||
response.setContent(serializer.error(serverError));
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.processor;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
|
||||
/**
|
||||
* Processor interface for handling a single instance of an Delta Response.
|
||||
*/
|
||||
public interface DeltaProcessor extends Processor {
|
||||
|
||||
/**
|
||||
* Reads delta information from persistence and put it as serialized content and
|
||||
* with according status into the response.
|
||||
* @param request OData request object containing raw HTTP information
|
||||
* @param response OData response object for collecting response data
|
||||
* @param uriInfo information of a parsed OData URI
|
||||
* @param responseFormat requested content type after content negotiation
|
||||
* @throws ODataApplicationException if the service implementation encounters a failure
|
||||
* @throws SerializerException if serialization failed
|
||||
*/
|
||||
void readDelta(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
|
||||
throws ODataApplicationException, SerializerException;
|
||||
}
|
@ -24,17 +24,17 @@ import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.ODataServerError;
|
||||
|
||||
/**
|
||||
* Processor which is called if any exception occurs inside the library or another processor.
|
||||
* Processor which is called if any error/exception occurs inside the library or another processor.
|
||||
*/
|
||||
public interface ExceptionProcessor extends Processor {
|
||||
public interface ErrorProcessor extends Processor {
|
||||
|
||||
/**
|
||||
* Processes an exception. MUST NOT throw an exception!
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
* Processes an error/exception. MUST NOT throw an exception!
|
||||
* @param request OData request object containing raw HTTP information
|
||||
* @param response OData response object for collecting response data
|
||||
* @param serverError the server error
|
||||
* @param responseFormat the requested format for the error message
|
||||
* @param responseFormat requested content type after content negotiation
|
||||
*/
|
||||
public void processException(ODataRequest request, ODataResponse response, ODataServerError serverError,
|
||||
ContentType responseFormat);
|
||||
public void processError(ODataRequest request, ODataResponse response, ODataServerError serverError,
|
||||
ContentType responseFormat);
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.processor;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
|
||||
/**
|
||||
* Processor interface for handling a collection an Entity References.
|
||||
*/
|
||||
public interface ReferenceCollectionProcessor extends Processor {
|
||||
|
||||
/**
|
||||
* Reads entity references from persistence and put them as serialized content and with
|
||||
* according status into the response.
|
||||
* @param request OData request object containing raw HTTP information
|
||||
* @param response OData response object for collecting response data
|
||||
* @param uriInfo information of a parsed OData URI
|
||||
* @param responseFormat requested content type after content negotiation
|
||||
* @throws ODataApplicationException if the service implementation encounters a failure
|
||||
* @throws SerializerException if serialization failed
|
||||
*/
|
||||
void readReferenceCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
|
||||
ContentType responseFormat)
|
||||
throws ODataApplicationException, SerializerException;
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.processor;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
|
||||
/**
|
||||
* Processor interface for handling a single instance of an Entity Reference.
|
||||
*/
|
||||
public interface ReferenceProcessor extends Processor {
|
||||
|
||||
/**
|
||||
* Reads entity reference from persistence and put it as serialized content and status into the response.
|
||||
* @param request OData request object containing raw HTTP information
|
||||
* @param response OData response object for collecting response data
|
||||
* @param uriInfo information of a parsed OData URI
|
||||
* @param responseFormat requested content type after content negotiation
|
||||
* @throws ODataApplicationException if the service implementation encounters a failure
|
||||
* @throws SerializerException if serialization failed
|
||||
*/
|
||||
void readReference(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
|
||||
throws ODataApplicationException, SerializerException;
|
||||
|
||||
/**
|
||||
* Creates entity reference data in the persistence and puts content, status, and Location into the response.
|
||||
* @param request OData request object containing raw HTTP information
|
||||
* @param response OData response object for collecting response data
|
||||
* @param uriInfo information of a parsed OData URI
|
||||
* @param requestFormat content type of body sent with request
|
||||
* @param responseFormat requested content type after content negotiation
|
||||
* @throws ODataApplicationException if the service implementation encounters a failure
|
||||
* @throws DeserializerException if deserialization failed
|
||||
* @throws SerializerException if serialization failed
|
||||
*/
|
||||
void createReference(ODataRequest request, ODataResponse response, UriInfo uriInfo,
|
||||
ContentType requestFormat, ContentType responseFormat)
|
||||
throws ODataApplicationException, DeserializerException, SerializerException;
|
||||
|
||||
/**
|
||||
* Update entity media reference in the persistence and puts content, status, and Location into the response.
|
||||
* @param request OData request object containing raw HTTP information
|
||||
* @param response OData response object for collecting response data
|
||||
* @param uriInfo information of a parsed OData URI
|
||||
* @param requestFormat content type of body sent with request
|
||||
* @param responseFormat requested content type after content negotiation
|
||||
* @throws ODataApplicationException if the service implementation encounters a failure
|
||||
* @throws DeserializerException if deserialization failed
|
||||
* @throws SerializerException if serialization failed
|
||||
*/
|
||||
void updateReference(ODataRequest request, ODataResponse response, UriInfo uriInfo,
|
||||
ContentType requestFormat, ContentType responseFormat)
|
||||
throws ODataApplicationException, DeserializerException, SerializerException;
|
||||
|
||||
|
||||
/**
|
||||
* Deletes entity (related to reference) from persistence and puts the status into the response.
|
||||
* @param request OData request object containing raw HTTP information
|
||||
* @param response OData response object for collecting response data
|
||||
* @param uriInfo information of a parsed OData URI
|
||||
* @throws ODataApplicationException if the service implementation encounters a failure
|
||||
*/
|
||||
void deleteReference(ODataRequest request, ODataResponse response, UriInfo uriInfo) throws ODataApplicationException;
|
||||
}
|
@ -45,7 +45,7 @@ import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
|
||||
import org.apache.olingo.server.api.processor.DefaultProcessor;
|
||||
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
|
||||
import org.apache.olingo.server.api.processor.EntityProcessor;
|
||||
import org.apache.olingo.server.api.processor.ExceptionProcessor;
|
||||
import org.apache.olingo.server.api.processor.ErrorProcessor;
|
||||
import org.apache.olingo.server.api.processor.MediaEntityProcessor;
|
||||
import org.apache.olingo.server.api.processor.MetadataProcessor;
|
||||
import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
|
||||
@ -183,9 +183,9 @@ public class ODataHandler {
|
||||
}
|
||||
|
||||
public void handleException(ODataRequest request, ODataResponse response, ODataServerError serverError) {
|
||||
ExceptionProcessor exceptionProcessor;
|
||||
ErrorProcessor exceptionProcessor;
|
||||
try {
|
||||
exceptionProcessor = selectProcessor(ExceptionProcessor.class);
|
||||
exceptionProcessor = selectProcessor(ErrorProcessor.class);
|
||||
} catch (ODataHandlerException e) {
|
||||
// This cannot happen since there is always an ExceptionProcessor registered.
|
||||
exceptionProcessor = new DefaultProcessor();
|
||||
@ -198,7 +198,7 @@ public class ODataHandler {
|
||||
} catch (final ContentNegotiatorException e) {
|
||||
requestedContentType = ODataFormat.JSON.getContentType(ODataServiceVersion.V40);
|
||||
}
|
||||
exceptionProcessor.processException(request, response, serverError, requestedContentType);
|
||||
exceptionProcessor.processError(request, response, serverError, requestedContentType);
|
||||
}
|
||||
|
||||
private void handleResourceDispatching(final ODataRequest request, final ODataResponse response)
|
||||
@ -255,7 +255,7 @@ public class ODataHandler {
|
||||
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
|
||||
if (resource instanceof UriResourceEntitySet || resource instanceof UriResourceNavigation) {
|
||||
selectProcessor(CountEntityCollectionProcessor.class)
|
||||
.countEntityCollection(request, response, uriInfo, ContentType.TEXT_PLAIN);
|
||||
.countEntityCollection(request, response, uriInfo);
|
||||
} else {
|
||||
throw new ODataHandlerException(
|
||||
"Count of collections of primitive-type or complex-type instances is not implemented.",
|
||||
|
@ -46,7 +46,7 @@ public class BatchHandler {
|
||||
validateRequest(request);
|
||||
|
||||
final BatchFacade operation = new BatchFascadeImpl(oDataHandler, request, batchProcessor, isStrict);
|
||||
batchProcessor.executeBatch(operation, request, response);
|
||||
batchProcessor.processBatch(operation, request, response);
|
||||
}
|
||||
|
||||
private void validateRequest(final ODataRequest request) throws BatchDeserializerException {
|
||||
|
@ -81,7 +81,7 @@ public class BatchPartHandler {
|
||||
}
|
||||
|
||||
private ODataResponsePart handleChangeSet(BatchRequestPart request) {
|
||||
return batchProcessor.executeChangeSet(batchFascade, request.getRequests());
|
||||
return batchProcessor.processChangeSet(batchFascade, request.getRequests());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -580,7 +580,7 @@ public class MockedBatchHandlerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataResponsePart executeChangeSet(BatchFacade fascade, List<ODataRequest> requests) {
|
||||
public ODataResponsePart processChangeSet(BatchFacade fascade, List<ODataRequest> requests) {
|
||||
List<ODataResponse> responses = new ArrayList<ODataResponse>();
|
||||
|
||||
for (ODataRequest request : requests) {
|
||||
@ -595,7 +595,7 @@ public class MockedBatchHandlerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeBatch(BatchFacade fascade, ODataRequest request, ODataResponse response)
|
||||
public void processBatch(BatchFacade fascade, ODataRequest request, ODataResponse response)
|
||||
throws BatchException, SerializerException {
|
||||
final String boundary = getBoundary(request.getHeader(HttpHeader.CONTENT_TYPE));
|
||||
final BatchOptions options = BatchOptions.with().isStrict(true).rawBaseUri(BASE_URI).build();
|
||||
|
@ -49,7 +49,7 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeBatch(BatchFacade fascade, ODataRequest request, ODataResponse response)
|
||||
public void processBatch(BatchFacade fascade, ODataRequest request, ODataResponse response)
|
||||
throws SerializerException, BatchException {
|
||||
|
||||
// TODO refactor isContinueOnError
|
||||
@ -132,7 +132,7 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataResponsePart executeChangeSet(BatchFacade fascade, List<ODataRequest> requests) {
|
||||
public ODataResponsePart processChangeSet(BatchFacade fascade, List<ODataRequest> requests) {
|
||||
List<ODataResponse> responses = new ArrayList<ODataResponse>();
|
||||
|
||||
for (ODataRequest request : requests) {
|
||||
|
@ -28,6 +28,7 @@ import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.http.HttpContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
@ -89,8 +90,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void countEntityCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
|
||||
final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
|
||||
public void countEntityCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo)
|
||||
throws ODataApplicationException, SerializerException {
|
||||
validateOptions(uriInfo.asUriInfoResource());
|
||||
blockNavigation(uriInfo);
|
||||
|
||||
@ -103,7 +104,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
||||
} else {
|
||||
response.setContent(odata.createFixedFormatSerializer().count(entitySet.getCount()));
|
||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
|
||||
response.setHeader(HttpHeader.CONTENT_TYPE, HttpContentType.TEXT_PLAIN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ public class ODataHandlerTest {
|
||||
dispatch(HttpMethod.GET, "ESAllPrim/$count", processor);
|
||||
|
||||
verify(processor).countEntityCollection(
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), eq(ContentType.TEXT_PLAIN));
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, "ESAllPrim/$count", processor);
|
||||
}
|
||||
@ -246,7 +246,7 @@ public class ODataHandlerTest {
|
||||
dispatch(HttpMethod.GET, "ESAllPrim(0)/NavPropertyETTwoPrimMany/$count", processor);
|
||||
|
||||
verify(processor).countEntityCollection(
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), eq(ContentType.TEXT_PLAIN));
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user