mimeHeaders = parseMimeHeaders(scanner);
currentContentId = mimeHeaders.get(BatchHelper.HTTP_CONTENT_ID.toLowerCase(Locale.ENGLISH));
final 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
BatchSingleResponseImpl response = parseResponse(scanner, isChangeSet);
responses.add(response);
} 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
BatchSingleResponseImpl response = parseResponse(scanner, isChangeSet);
responses.add(response);
} 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));
}
parseNewLine(scanner);// mandatory
Pattern changeSetCloseDelimiter =
Pattern.compile("--" + changeSetBoundary + "--" + REG_EX_ZERO_OR_MORE_WHITESPACES);
while (!scanner.hasNext(changeSetCloseDelimiter)) {
responses.addAll(parseMultipart(scanner, changeSetBoundary, true));
}
scanner.next(changeSetCloseDelimiter);
currentLineNumber++;
parseOptionalEmptyLine(scanner);
} else {
throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(HttpContentType.MULTIPART_MIXED
+ " or " + HttpContentType.APPLICATION_HTTP));
}
}
} else if (scanner.hasNext(boundary + REG_EX_ZERO_OR_MORE_WHITESPACES)) {
currentLineNumber++;
throw new BatchException(BatchException.INVALID_BOUNDARY_DELIMITER.addContent(currentLineNumber));
} else if (scanner.hasNext(REG_EX_ANY_BOUNDARY_STRING)) {
currentLineNumber++;
throw new BatchException(BatchException.NO_MATCH_WITH_BOUNDARY_STRING.addContent(boundary).addContent(
currentLineNumber));
} else {
currentLineNumber++;
throw new BatchException(BatchException.MISSING_BOUNDARY_DELIMITER.addContent(currentLineNumber));
}
return responses;
}