if (result.groupCount() == 2) {
method = result.group(1);
uri = result.group(2).trim();
} else {
currentLineNumber++;
throw new BatchException(BatchException.INVALID_REQUEST_LINE.addContent(scanner.next()).addContent(
currentLineNumber));
}
PathInfo pathInfo = parseRequestUri(uri);
Map<String, String> queryParameters = parseQueryParameters(uri);
if (isChangeSet) {
if (!HTTP_CHANGESET_METHODS.contains(method)) {
throw new BatchException(BatchException.INVALID_CHANGESET_METHOD.addContent(currentLineNumber));
}
} else if (!HTTP_BATCH_METHODS.contains(method)) {
throw new BatchException(BatchException.INVALID_QUERY_OPERATION_METHOD.addContent(currentLineNumber));
}
ODataHttpMethod httpMethod = ODataHttpMethod.valueOf(method);
Map<String, List<String>> headers = parseRequestHeaders(scanner, boundary);
if (currentMimeHeaderContentId != null) {
List<String> headerList = new ArrayList<String>();
headerList.add(currentMimeHeaderContentId);
headers.put(BatchHelper.MIME_HEADER_CONTENT_ID.toLowerCase(Locale.ENGLISH), headerList);
}
String contentType = getContentTypeHeader(headers);
List<String> acceptHeaders = getAcceptHeader(headers);
List<Locale> acceptLanguages = getAcceptLanguageHeader(headers);
InputStream body = new ByteArrayInputStream(new byte[0]);
if (isChangeSet) {
body = parseBody(scanner);
}
ODataRequestBuilder requestBuilder = ODataRequest.method(httpMethod)
.queryParameters(queryParameters)
.requestHeaders(headers)
.pathInfo(pathInfo)
.acceptableLanguages(acceptLanguages)
.body(body)
.acceptHeaders(acceptHeaders);
if (contentType != null) {
requestBuilder = requestBuilder.contentType(contentType);
}
return requestBuilder.build();
} else {
currentLineNumber++;
throw new BatchException(BatchException.INVALID_REQUEST_LINE.addContent(scanner.next()).addContent(
currentLineNumber));
}
}