@Test public void testMultipleAccepLanguagetHeaderSameValue() throws BatchException { String[] messageRaw = new String[] { "Accept-Language:en-US,en;q=0.7,en-UK;q=0.9" + CRLF, "Accept-Language:en-US,en;q=0.7" + CRLF, "content-type: Application/http" + CRLF, "content-transfer-encoding: Binary" + CRLF }; List<Line> message = toLineList(messageRaw); final Header header = BatchParserCommon.consumeHeaders(message); assertNotNull(header); final List<String> acceptLanguageHeader = header.getHeaders(HttpHeaders.ACCEPT_LANGUAGE); assertNotNull(acceptLanguageHeader); assertEquals(3, acceptLanguageHeader.size()); }
public static Header consumeHeaders(final List<Line> remainingMessage) throws BatchException { final int headerLineNumber = !remainingMessage.isEmpty() ? remainingMessage.get(0).getLineNumber() : 0; final Header headers = new Header(headerLineNumber); final Iterator<Line> iter = remainingMessage.iterator(); final AcceptParser acceptParser = new AcceptParser(); Line currentLine; int acceptLineNumber = 0; int acceptLanguageLineNumber = 0; boolean isHeader = true; while (iter.hasNext() && isHeader) { currentLine = iter.next(); final Matcher headerMatcher = PATTERN_HEADER_LINE.matcher(currentLine.toString()); if (headerMatcher.matches() && headerMatcher.groupCount() == 2) { iter.remove(); String headerName = headerMatcher.group(1).trim(); String headerValue = headerMatcher.group(2).trim(); if (HttpHeaders.ACCEPT.equalsIgnoreCase(headerName)) { acceptParser.addAcceptHeaderValue(headerValue); acceptLineNumber = currentLine.getLineNumber(); } else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(headerName)) { acceptParser.addAcceptLanguageHeaderValue(headerValue); acceptLanguageLineNumber = currentLine.getLineNumber(); } else { headers.addHeader(headerName, Header.splitValuesByComma(headerValue), currentLine.getLineNumber()); } } else { isHeader = false; } } headers.addHeader(HttpHeaders.ACCEPT, acceptParser.parseAcceptHeaders(), acceptLineNumber); headers.addHeader(HttpHeaders.ACCEPT_LANGUAGE, acceptParser.parseAcceptableLanguages(), acceptLanguageLineNumber); return headers; }
BatchParserCommon { public static Header consumeHeaders(final List<Line> remainingMessage) throws BatchException { final int headerLineNumber = !remainingMessage.isEmpty() ? remainingMessage.get(0).getLineNumber() : 0; final Header headers = new Header(headerLineNumber); final Iterator<Line> iter = remainingMessage.iterator(); final AcceptParser acceptParser = new AcceptParser(); Line currentLine; int acceptLineNumber = 0; int acceptLanguageLineNumber = 0; boolean isHeader = true; while (iter.hasNext() && isHeader) { currentLine = iter.next(); final Matcher headerMatcher = PATTERN_HEADER_LINE.matcher(currentLine.toString()); if (headerMatcher.matches() && headerMatcher.groupCount() == 2) { iter.remove(); String headerName = headerMatcher.group(1).trim(); String headerValue = headerMatcher.group(2).trim(); if (HttpHeaders.ACCEPT.equalsIgnoreCase(headerName)) { acceptParser.addAcceptHeaderValue(headerValue); acceptLineNumber = currentLine.getLineNumber(); } else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(headerName)) { acceptParser.addAcceptLanguageHeaderValue(headerValue); acceptLanguageLineNumber = currentLine.getLineNumber(); } else { headers.addHeader(headerName, Header.splitValuesByComma(headerValue), currentLine.getLineNumber()); } } else { isHeader = false; } } headers.addHeader(HttpHeaders.ACCEPT, acceptParser.parseAcceptHeaders(), acceptLineNumber); headers.addHeader(HttpHeaders.ACCEPT_LANGUAGE, acceptParser.parseAcceptableLanguages(), acceptLanguageLineNumber); return headers; } }
BatchParserCommon { public static Header consumeHeaders(final List<Line> remainingMessage) throws BatchException { final int headerLineNumber = !remainingMessage.isEmpty() ? remainingMessage.get(0).getLineNumber() : 0; final Header headers = new Header(headerLineNumber); final Iterator<Line> iter = remainingMessage.iterator(); final AcceptParser acceptParser = new AcceptParser(); Line currentLine; int acceptLineNumber = 0; int acceptLanguageLineNumber = 0; boolean isHeader = true; while (iter.hasNext() && isHeader) { currentLine = iter.next(); final Matcher headerMatcher = PATTERN_HEADER_LINE.matcher(currentLine.toString()); if (headerMatcher.matches() && headerMatcher.groupCount() == 2) { iter.remove(); String headerName = headerMatcher.group(1).trim(); String headerValue = headerMatcher.group(2).trim(); if (HttpHeaders.ACCEPT.equalsIgnoreCase(headerName)) { acceptParser.addAcceptHeaderValue(headerValue); acceptLineNumber = currentLine.getLineNumber(); } else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(headerName)) { acceptParser.addAcceptLanguageHeaderValue(headerValue); acceptLanguageLineNumber = currentLine.getLineNumber(); } else { headers.addHeader(headerName, Header.splitValuesByComma(headerValue), currentLine.getLineNumber()); } } else { isHeader = false; } } headers.addHeader(HttpHeaders.ACCEPT, acceptParser.parseAcceptHeaders(), acceptLineNumber); headers.addHeader(HttpHeaders.ACCEPT_LANGUAGE, acceptParser.parseAcceptableLanguages(), acceptLanguageLineNumber); return headers; } private  BatchParserCommon(); }
BatchParserCommon { public static Header consumeHeaders(final List<Line> remainingMessage) throws BatchException { final int headerLineNumber = !remainingMessage.isEmpty() ? remainingMessage.get(0).getLineNumber() : 0; final Header headers = new Header(headerLineNumber); final Iterator<Line> iter = remainingMessage.iterator(); final AcceptParser acceptParser = new AcceptParser(); Line currentLine; int acceptLineNumber = 0; int acceptLanguageLineNumber = 0; boolean isHeader = true; while (iter.hasNext() && isHeader) { currentLine = iter.next(); final Matcher headerMatcher = PATTERN_HEADER_LINE.matcher(currentLine.toString()); if (headerMatcher.matches() && headerMatcher.groupCount() == 2) { iter.remove(); String headerName = headerMatcher.group(1).trim(); String headerValue = headerMatcher.group(2).trim(); if (HttpHeaders.ACCEPT.equalsIgnoreCase(headerName)) { acceptParser.addAcceptHeaderValue(headerValue); acceptLineNumber = currentLine.getLineNumber(); } else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(headerName)) { acceptParser.addAcceptLanguageHeaderValue(headerValue); acceptLanguageLineNumber = currentLine.getLineNumber(); } else { headers.addHeader(headerName, Header.splitValuesByComma(headerValue), currentLine.getLineNumber()); } } else { isHeader = false; } } headers.addHeader(HttpHeaders.ACCEPT, acceptParser.parseAcceptHeaders(), acceptLineNumber); headers.addHeader(HttpHeaders.ACCEPT_LANGUAGE, acceptParser.parseAcceptableLanguages(), acceptLanguageLineNumber); return headers; } private  BatchParserCommon(); static String trimLineListToLength(final List<Line> list, final int length); static String lineListToString(final List<Line> list); static InputStream convertToInputStream(final String contentType, final BatchQueryOperation operation,
                                                 final int contentLength); static Line removeEndingCRLF(final Line line); static Header consumeHeaders(final List<Line> remainingMessage); static void consumeBlankLine(final List<Line> remainingMessage, final boolean isStrict); static String getBoundary(final String contentType, final int line); static Map<String, List<String>> parseQueryParameter(final Line httpRequest); }
BatchParserCommon { public static Header consumeHeaders(final List<Line> remainingMessage) throws BatchException { final int headerLineNumber = !remainingMessage.isEmpty() ? remainingMessage.get(0).getLineNumber() : 0; final Header headers = new Header(headerLineNumber); final Iterator<Line> iter = remainingMessage.iterator(); final AcceptParser acceptParser = new AcceptParser(); Line currentLine; int acceptLineNumber = 0; int acceptLanguageLineNumber = 0; boolean isHeader = true; while (iter.hasNext() && isHeader) { currentLine = iter.next(); final Matcher headerMatcher = PATTERN_HEADER_LINE.matcher(currentLine.toString()); if (headerMatcher.matches() && headerMatcher.groupCount() == 2) { iter.remove(); String headerName = headerMatcher.group(1).trim(); String headerValue = headerMatcher.group(2).trim(); if (HttpHeaders.ACCEPT.equalsIgnoreCase(headerName)) { acceptParser.addAcceptHeaderValue(headerValue); acceptLineNumber = currentLine.getLineNumber(); } else if (HttpHeaders.ACCEPT_LANGUAGE.equalsIgnoreCase(headerName)) { acceptParser.addAcceptLanguageHeaderValue(headerValue); acceptLanguageLineNumber = currentLine.getLineNumber(); } else { headers.addHeader(headerName, Header.splitValuesByComma(headerValue), currentLine.getLineNumber()); } } else { isHeader = false; } } headers.addHeader(HttpHeaders.ACCEPT, acceptParser.parseAcceptHeaders(), acceptLineNumber); headers.addHeader(HttpHeaders.ACCEPT_LANGUAGE, acceptParser.parseAcceptableLanguages(), acceptLanguageLineNumber); return headers; } private  BatchParserCommon(); static String trimLineListToLength(final List<Line> list, final int length); static String lineListToString(final List<Line> list); static InputStream convertToInputStream(final String contentType, final BatchQueryOperation operation,
                                                 final int contentLength); static Line removeEndingCRLF(final Line line); static Header consumeHeaders(final List<Line> remainingMessage); static void consumeBlankLine(final List<Line> remainingMessage, final boolean isStrict); static String getBoundary(final String contentType, final int line); static Map<String, List<String>> parseQueryParameter(final Line httpRequest); static final Pattern PATTERN_MULTIPART_MIXED; static final Pattern PATTERN_CONTENT_TYPE_APPLICATION_HTTP; static final Pattern PATTERN_RELATIVE_URI; }