private Range getRange(final String[] values) throws MalformedInputException { try { return new Range(Long.parseLong(values[0].trim()), Long.parseLong(values[1].trim())); } catch (NumberFormatException e) { throw new MalformedInputException("Invalid range value, unable to parse numeric values " + e.getMessage()); } } }
status = statusParser.parse(getStatusLine(in)); } catch (MalformedInputException e) { throw new MalformedStatusLineException("Malformed status line " + e.getMessage());
/** * {@inheritDoc} */ @Override public List<Range> parse(final String input) throws MalformedInputException { List<Range> rangeList = new ArrayList<>(); String inputNormalized = input.toLowerCase().trim(); if (!inputNormalized.startsWith(START_WORD)) { throw new MalformedInputException("Header value must start with bytes="); } String[] rangesString = inputNormalized.substring(START_WORD.length()).split(RANGES_SEPARATOR); for (String rangeString : rangesString) { if (rangeString.indexOf(RANGE_SEPARATOR) == -1) { throw new MalformedInputException("Invalid range value " + rangeString); } String[] values = rangeString.split(RANGE_SEPARATOR); if (values.length != 2) { throw new MalformedInputException("Invalid range value " + rangeString); } rangeList.add(getRange(values)); } return rangeList; }
int quotationMarkPosition = name.indexOf("\""); if (quotationMarkPosition == -1) { throw new MalformedInputException("Malformed header, unable to detect value beginning"); } else { name = name.substring(0, quotationMarkPosition); throw new MalformedInputException("Malformed header, unable to detect value end"); } else { fileName = fileName.substring(0, quotationMark2Position);
throw new MalformedInputException("Input status string should be composed out of " + NUMBER_OF_CHUNKS + " chunks. Received " + input);
@Test(expected = ProtocolException.class) public void shouldThrowProtocolExceptionOnMalformedHeaders() throws Exception { when(headersParser.parse(any(String.class))).thenThrow(new MalformedInputException("ANY")); factory.createFromSocket(socket); }
@Test public void shouldAssignNoCookieOnMalformedCookieString() throws Exception { headers.setHeader(Headers.HEADER_COOKIE, "ANYTHING"); when(cookieParser.parse(any(String.class))).thenThrow(new MalformedInputException("ANY")); HttpServletRequestImpl request = factory.createFromSocket(socket); assertThat(request.getCookies().length, is(0)); verify(cookieParser, times(1)).parse(any(String.class)); }
private void handlePostRequest(final HttpServletRequestImpl.Builder builder, final InputStream in, final Headers headers) throws IOException, MalformedInputException { int postLength; if (headers.containsHeader(Headers.HEADER_CONTENT_LENGTH)) { try { postLength = Integer.parseInt(headers.getHeader(Headers.HEADER_CONTENT_LENGTH)); } catch (NumberFormatException e) { throw new MalformedInputException(e.getMessage()); } } else { throw new LengthRequiredException(); } // Only if post length is greater than 0 // Keep 0 value - makes no sense to parse the data if (postLength < 1) { return; } if (postLength > POST_MAX_LENGTH) { throw new PayloadTooLargeProtocolException("Payload of " + postLength + "b exceeds the limit of " + POST_MAX_LENGTH + "b"); } if (isMultipartRequest(headers)) { handlePostMultipartRequest(builder, headers, in, postLength); } else { handlePostPlainRequest(builder, in, postLength); } }