Api Refactoring
Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
parent
bc46b5352e
commit
ad177ac11e
|
@ -18,14 +18,13 @@
|
|||
*/package org.apache.olingo.server.api.batch;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
|
||||
public interface BatchOperation {
|
||||
public List<BatchRequestPart> parseBatchRequest(InputStream in) throws BatchException;
|
||||
public List<BatchRequestPart> parseBatchRequest(ODataRequest request, boolean isStrict) throws BatchException;
|
||||
|
||||
public ODataResponse handleODataRequest(ODataRequest request, BatchRequestPart requestPart) throws BatchException;
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
|
|||
boolean continueOnError = shouldContinueOnError(request);
|
||||
|
||||
try {
|
||||
final List<BatchRequestPart> parts = operation.parseBatchRequest(request.getBody());
|
||||
final List<BatchRequestPart> parts = operation.parseBatchRequest(request, true);
|
||||
final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
|
||||
|
||||
for (BatchRequestPart part : parts) {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.apache.olingo.server.core.batch.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
|
@ -43,13 +42,13 @@ public class BatchOperationImpl implements BatchOperation {
|
|||
final boolean isStrict) {
|
||||
partHandler = new BatchPartHandler(oDataHandler, batchProcessor, this);
|
||||
writer = new BatchResponseWriter();
|
||||
parser = new BatchParser(getContentType(request), request.getRawBaseUri(),
|
||||
request.getRawServiceResolutionUri(), isStrict);
|
||||
parser = new BatchParser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BatchRequestPart> parseBatchRequest(InputStream in) throws BatchException {
|
||||
return parser.parseBatchRequest(in);
|
||||
public List<BatchRequestPart> parseBatchRequest(ODataRequest request, boolean isStrict) throws BatchException {
|
||||
return parser.parseBatchRequest(request.getBody(), getContentType(request), request.getRawBaseUri(),
|
||||
request.getRawServiceResolutionUri(), isStrict);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.apache.olingo.server.core.batch.handler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
||||
|
@ -126,10 +124,9 @@ public class BatchPartHandler {
|
|||
if (request.isChangeSet()) {
|
||||
return handleChangeSet(request);
|
||||
} else {
|
||||
final List<ODataResponse> responses = new ArrayList<ODataResponse>();
|
||||
responses.add(handleODataRequest(request.getRequests().get(0), request));
|
||||
final ODataResponse response = handleODataRequest(request.getRequests().get(0), request);
|
||||
|
||||
return new ODataResponsePart(responses, false);
|
||||
return new ODataResponsePart(response, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,21 +33,18 @@ import org.apache.olingo.server.core.batch.transformator.BatchRequestTransformat
|
|||
|
||||
public class BatchParser {
|
||||
|
||||
private final String contentTypeMime;
|
||||
private final String baseUri;
|
||||
private final String rawServiceResolutionUri;
|
||||
private final boolean isStrict;
|
||||
|
||||
public BatchParser(final String contentType, final String baseUri, final String serviceResolutionUri,
|
||||
final boolean isStrict) {
|
||||
contentTypeMime = contentType;
|
||||
this.baseUri = BatchParserCommon.removeEndingSlash(baseUri);
|
||||
this.isStrict = isStrict;
|
||||
this.rawServiceResolutionUri = serviceResolutionUri;
|
||||
}
|
||||
private String contentTypeMime;
|
||||
private String rawServiceResolutionUri;
|
||||
private boolean isStrict;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<BatchRequestPart> parseBatchRequest(final InputStream in) throws BatchException {
|
||||
public List<BatchRequestPart> parseBatchRequest(final InputStream in, final String contentType, final String baseUri,
|
||||
final String serviceResolutionUri, final boolean isStrict) throws BatchException {
|
||||
|
||||
contentTypeMime = contentType;
|
||||
this.isStrict = isStrict;
|
||||
this.rawServiceResolutionUri = serviceResolutionUri;
|
||||
|
||||
return (List<BatchRequestPart>) parse(in, new BatchRequestTransformator(baseUri, rawServiceResolutionUri));
|
||||
}
|
||||
|
||||
|
|
|
@ -196,8 +196,9 @@ public class BatchRequestParserTest {
|
|||
+ "--batch_1.2+34:2j)0?" + CRLF
|
||||
+ GET_REQUEST
|
||||
+ "--batch_1.2+34:2j)0?--";
|
||||
final BatchParser parser = new BatchParser(contentType, SERVICE_ROOT, "", true);
|
||||
final List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(StringUtil.toInputStream(batch));
|
||||
final BatchParser parser = new BatchParser();
|
||||
final List<BatchRequestPart> batchRequestParts =
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch), contentType, SERVICE_ROOT, "", true);
|
||||
|
||||
assertNotNull(batchRequestParts);
|
||||
assertFalse(batchRequestParts.isEmpty());
|
||||
|
@ -210,10 +211,10 @@ public class BatchRequestParserTest {
|
|||
+ "--batch_1740-bb84-2f7f" + CRLF
|
||||
+ GET_REQUEST
|
||||
+ "--batch_1740-bb84-2f7f--";
|
||||
final BatchParser parser = new BatchParser(invalidContentType, SERVICE_ROOT, "", true);
|
||||
final BatchParser parser = new BatchParser();
|
||||
|
||||
try {
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch));
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch), invalidContentType, SERVICE_ROOT, "", true);
|
||||
fail();
|
||||
} catch (BatchException e) {
|
||||
assertMessageKey(e, BatchException.MessageKeys.INVALID_CONTENT_TYPE);
|
||||
|
@ -227,8 +228,9 @@ public class BatchRequestParserTest {
|
|||
+ "--batch_14d1-b293-b99a" + CRLF
|
||||
+ GET_REQUEST
|
||||
+ "--batch_14d1-b293-b99a--";
|
||||
final BatchParser parser = new BatchParser(contentType, SERVICE_ROOT, "", true);
|
||||
final List<BatchRequestPart> parts = parser.parseBatchRequest(StringUtil.toInputStream(batch));
|
||||
final BatchParser parser = new BatchParser();
|
||||
final List<BatchRequestPart> parts =
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch), contentType, SERVICE_ROOT, "", true);
|
||||
|
||||
assertEquals(1, parts.size());
|
||||
}
|
||||
|
@ -240,10 +242,10 @@ public class BatchRequestParserTest {
|
|||
+ "--batch_1740-bb84-2f7f" + CRLF
|
||||
+ GET_REQUEST
|
||||
+ "--batch_1740-bb84-2f7f--";
|
||||
final BatchParser parser = new BatchParser(invalidContentType, SERVICE_ROOT, "", true);
|
||||
final BatchParser parser = new BatchParser();
|
||||
|
||||
try {
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch));
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch), invalidContentType, SERVICE_ROOT, "", true);
|
||||
fail();
|
||||
} catch (BatchException e) {
|
||||
assertMessageKey(e, BatchException.MessageKeys.INVALID_CONTENT_TYPE);
|
||||
|
@ -257,10 +259,10 @@ public class BatchRequestParserTest {
|
|||
+ "--batch_1740-bb:84-2f7f" + CRLF
|
||||
+ GET_REQUEST
|
||||
+ "--batch_1740-bb:84-2f7f--";
|
||||
final BatchParser parser = new BatchParser(invalidContentType, SERVICE_ROOT, "", true);
|
||||
final BatchParser parser = new BatchParser();
|
||||
|
||||
try {
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch));
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch), invalidContentType, SERVICE_ROOT, "", true);
|
||||
fail();
|
||||
} catch (BatchException e) {
|
||||
assertMessageKey(e, BatchException.MessageKeys.INVALID_BOUNDARY);
|
||||
|
@ -1272,8 +1274,9 @@ public class BatchRequestParserTest {
|
|||
}
|
||||
|
||||
private List<BatchRequestPart> parse(final InputStream in, final boolean isStrict) throws BatchException {
|
||||
final BatchParser parser = new BatchParser(CONTENT_TYPE, SERVICE_ROOT, "", isStrict);
|
||||
final List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
|
||||
final BatchParser parser = new BatchParser();
|
||||
final List<BatchRequestPart> batchRequestParts =
|
||||
parser.parseBatchRequest(in, CONTENT_TYPE, SERVICE_ROOT, "", isStrict);
|
||||
|
||||
assertNotNull(batchRequestParts);
|
||||
|
||||
|
@ -1295,10 +1298,10 @@ public class BatchRequestParserTest {
|
|||
|
||||
private void parseInvalidBatchBody(final String batch, final MessageKeys key, final boolean isStrict)
|
||||
throws UnsupportedEncodingException {
|
||||
final BatchParser parser = new BatchParser(CONTENT_TYPE, SERVICE_ROOT, "", isStrict);
|
||||
final BatchParser parser = new BatchParser();
|
||||
|
||||
try {
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch));
|
||||
parser.parseBatchRequest(StringUtil.toInputStream(batch), CONTENT_TYPE, SERVICE_ROOT, "", isStrict);
|
||||
fail("No exception thrown. Expect: " + key.toString());
|
||||
} catch (BatchException e) {
|
||||
assertMessageKey(e, key);
|
||||
|
|
|
@ -593,7 +593,7 @@ public class MockedBatchHandlerTest {
|
|||
@Override
|
||||
public void executeBatch(BatchOperation operation, ODataRequest request, ODataResponse response) {
|
||||
try {
|
||||
final List<BatchRequestPart> parts = operation.parseBatchRequest(request.getBody());
|
||||
final List<BatchRequestPart> parts = operation.parseBatchRequest(request, true);
|
||||
final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
|
||||
|
||||
for (BatchRequestPart part : parts) {
|
||||
|
|
Loading…
Reference in New Issue