}
private BatchRequestPart parseMultipart(final Scanner scanner, final String boundary, final boolean isChangeSet)
throws BatchException {
Map<String, String> mimeHeaders = new HashMap<String, String>();
BatchRequestPart multipart = null;
List<ODataRequest> requests = new ArrayList<ODataRequest>();
if (scanner.hasNext("--" + boundary + REG_EX_ZERO_OR_MORE_WHITESPACES)) {
scanner.next();
currentLineNumber++;
mimeHeaders = parseHeaders(scanner);
currentMimeHeaderContentId = mimeHeaders.get(BatchHelper.HTTP_CONTENT_ID.toLowerCase(Locale.ENGLISH));
String contentType = mimeHeaders.get(HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.ENGLISH));
if (contentType == null) {
throw new BatchException(BatchException.MISSING_CONTENT_TYPE);
}
if (isChangeSet) {
if (HttpContentType.APPLICATION_HTTP.equalsIgnoreCase(contentType)) {
validateEncoding(mimeHeaders.get(BatchHelper.HTTP_CONTENT_TRANSFER_ENCODING.toLowerCase(Locale.ENGLISH)));
parseNewLine(scanner);// mandatory
requests.add(parseRequest(scanner, isChangeSet));
multipart = new BatchRequestPartImpl(false, requests);
} else {
throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(HttpContentType.APPLICATION_HTTP));
}
} else {
if (HttpContentType.APPLICATION_HTTP.equalsIgnoreCase(contentType)) {
validateEncoding(mimeHeaders.get(BatchHelper.HTTP_CONTENT_TRANSFER_ENCODING.toLowerCase(Locale.ENGLISH)));
parseNewLine(scanner);// mandatory
requests.add(parseRequest(scanner, isChangeSet));
multipart = new BatchRequestPartImpl(false, requests);
} else if (contentType.matches(REG_EX_OPTIONAL_WHITESPACE + HttpContentType.MULTIPART_MIXED + ANY_CHARACTERS)) {
String changeSetBoundary = getBoundary(contentType);
if (boundary.equals(changeSetBoundary)) {
throw new BatchException(BatchException.INVALID_CHANGESET_BOUNDARY.addContent(currentLineNumber));
}
List<ODataRequest> changeSetRequests = new LinkedList<ODataRequest>();
parseNewLine(scanner);// mandatory
Pattern changeSetCloseDelimiter =
Pattern.compile("--" + changeSetBoundary + "--" + REG_EX_ZERO_OR_MORE_WHITESPACES);
while (!scanner.hasNext(changeSetCloseDelimiter)) {
BatchRequestPart part = parseMultipart(scanner, changeSetBoundary, true);
changeSetRequests.addAll(part.getRequests());
}
scanner.next(changeSetCloseDelimiter);
currentLineNumber++;
multipart = new BatchRequestPartImpl(true, changeSetRequests);
} else {