[OLINGO-472] BatchFascade refactoring to support boundary extraction
Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
parent
55c4d69d8d
commit
65ad2f48d5
|
@ -55,4 +55,13 @@ public interface BatchFacade {
|
||||||
* @throws BatchDeserializerException
|
* @throws BatchDeserializerException
|
||||||
*/
|
*/
|
||||||
public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchDeserializerException;
|
public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchDeserializerException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the boundary of a multipart/mixed header.
|
||||||
|
* See RFC 2046#5.1
|
||||||
|
*
|
||||||
|
* @param contentType Content Type
|
||||||
|
* @return Boundary
|
||||||
|
*/
|
||||||
|
public String extractBoundaryFromContentType(String contentType) throws BatchDeserializerException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,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.deserializer.batch.ODataResponsePart;
|
||||||
import org.apache.olingo.server.api.processor.BatchProcessor;
|
import org.apache.olingo.server.api.processor.BatchProcessor;
|
||||||
import org.apache.olingo.server.core.ODataHandler;
|
import org.apache.olingo.server.core.ODataHandler;
|
||||||
|
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
|
||||||
|
|
||||||
public class BatchFascadeImpl implements BatchFacade {
|
public class BatchFascadeImpl implements BatchFacade {
|
||||||
private final BatchPartHandler partHandler;
|
private final BatchPartHandler partHandler;
|
||||||
|
@ -44,4 +45,9 @@ public class BatchFascadeImpl implements BatchFacade {
|
||||||
public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchDeserializerException {
|
public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchDeserializerException {
|
||||||
return partHandler.handleBatchRequest(request);
|
return partHandler.handleBatchRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String extractBoundaryFromContentType(String contentType) throws BatchDeserializerException {
|
||||||
|
return BatchParserCommon.getBoundary(contentType, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.apache.olingo.server.tecsvc.processor;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
|
@ -39,7 +38,6 @@ import org.apache.olingo.server.api.processor.BatchProcessor;
|
||||||
import org.apache.olingo.server.tecsvc.data.DataProvider;
|
import org.apache.olingo.server.tecsvc.data.DataProvider;
|
||||||
|
|
||||||
public class TechnicalBatchProcessor extends TechnicalProcessor implements BatchProcessor {
|
public class TechnicalBatchProcessor extends TechnicalProcessor implements BatchProcessor {
|
||||||
// TODO remove
|
|
||||||
private static final String PREFERENCE_CONTINUE_ON_ERROR = "odata.continue-on-error";
|
private static final String PREFERENCE_CONTINUE_ON_ERROR = "odata.continue-on-error";
|
||||||
|
|
||||||
public TechnicalBatchProcessor(DataProvider dataProvider) {
|
public TechnicalBatchProcessor(DataProvider dataProvider) {
|
||||||
|
@ -49,10 +47,9 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
|
||||||
@Override
|
@Override
|
||||||
public void processBatch(BatchFacade fascade, ODataRequest request, ODataResponse response)
|
public void processBatch(BatchFacade fascade, ODataRequest request, ODataResponse response)
|
||||||
throws BatchSerializerException, BatchDeserializerException {
|
throws BatchSerializerException, BatchDeserializerException {
|
||||||
// TODO refactor isContinueOnError
|
|
||||||
boolean continueOnError = isContinueOnError(request);
|
boolean continueOnError = isContinueOnError(request);
|
||||||
|
|
||||||
final String boundary = getBoundary(request.getHeader(HttpHeader.CONTENT_TYPE));
|
final String boundary = fascade.extractBoundaryFromContentType(request.getHeader(HttpHeader.CONTENT_TYPE));
|
||||||
final BatchOptions options = BatchOptions.with()
|
final BatchOptions options = BatchOptions.with()
|
||||||
.rawBaseUri(request.getRawBaseUri())
|
.rawBaseUri(request.getRawBaseUri())
|
||||||
.rawServiceResolutionUri(request.getRawServiceResolutionUri()).build();
|
.rawServiceResolutionUri(request.getRawServiceResolutionUri()).build();
|
||||||
|
@ -82,7 +79,6 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
|
||||||
response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
|
response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO refactor isContinueOnError
|
|
||||||
private boolean isContinueOnError(ODataRequest request) {
|
private boolean isContinueOnError(ODataRequest request) {
|
||||||
final List<String> preferValues = request.getHeaders(HttpHeader.PREFER);
|
final List<String> preferValues = request.getHeaders(HttpHeader.PREFER);
|
||||||
|
|
||||||
|
@ -94,38 +90,6 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO refactor getBoundary
|
|
||||||
private String getBoundary(String contentType) {
|
|
||||||
if (contentType == null) {
|
|
||||||
throw new IllegalArgumentException("Content mustn`t be null.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contentType.toLowerCase(Locale.ENGLISH).startsWith("multipart/mixed")) {
|
|
||||||
final String[] parameter = contentType.split(";");
|
|
||||||
|
|
||||||
for (final String pair : parameter) {
|
|
||||||
final String[] attrValue = pair.split("=");
|
|
||||||
if (attrValue.length == 2 && "boundary".equals(attrValue[0].trim().toLowerCase(Locale.ENGLISH))) {
|
|
||||||
if (attrValue[1].matches("([a-zA-Z0-9_\\-\\.'\\+]{1,70})|\"([a-zA-Z0-9_\\-\\.'\\+\\s\\" +
|
|
||||||
"(\\),/:=\\?]{1,69}[a-zA-Z0-9_\\-\\.'\\+\\(\\),/:=\\?])\"")) {
|
|
||||||
|
|
||||||
String boundary = attrValue[1].trim();
|
|
||||||
if (boundary.matches("\".*\"")) {
|
|
||||||
boundary = boundary.replace("\"", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return boundary;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Invalid boundary");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Content type is not multipart mixed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue