public static int getContentLength(final Header headers) throws BatchDeserializerException { final HeaderField contentLengthField = headers.getHeaderField(HttpHeader.CONTENT_LENGTH); if (contentLengthField != null && contentLengthField.getValues().size() == 1) { final List<String> contentLengthValues = contentLengthField.getValues(); try { int contentLength = Integer.parseInt(contentLengthValues.get(0)); if (contentLength < 0) { throw new BatchDeserializerException( "Invalid content length", MessageKeys.INVALID_CONTENT_LENGTH, Integer.toString(contentLengthField.getLineNumber())); } return contentLength; } catch (NumberFormatException e) { throw new BatchDeserializerException( "Invalid content length", e, MessageKeys.INVALID_CONTENT_LENGTH, Integer.toString(contentLengthField.getLineNumber())); } } return -1; }
public static void validateContentTransferEncoding(final Header headers) throws BatchDeserializerException { final HeaderField contentTransferField = headers.getHeaderField(BatchParserCommon.CONTENT_TRANSFER_ENCODING); if (contentTransferField != null) { final List<String> contentTransferValues = contentTransferField.getValues(); if (contentTransferValues.size() == 1) { String encoding = contentTransferValues.get(0); if (!BatchParserCommon.BINARY_ENCODING.equalsIgnoreCase(encoding)) { throw new BatchDeserializerException( "Invalid content transfer encoding", MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING, Integer.toString(headers.getLineNumber())); } } else { throw new BatchDeserializerException( "Invalid Content-Transfer-Encoding header", MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING, Integer.toString(headers.getLineNumber())); } } else { throw new BatchDeserializerException( "Missing mandatory content transfer encoding", MessageKeys.MISSING_CONTENT_TRANSFER_ENCODING, Integer.toString(headers.getLineNumber())); } }
private void validateChangeSetBoundary(final String changeSetBoundary, final Header header) throws BatchDeserializerException { if (changeSetBoundary.equals(boundary)) { throw new BatchDeserializerException( "Change set boundary is equals to batch request boundary", BatchDeserializerException.MessageKeys.INVALID_BOUNDARY, Integer.toString(header.getHeaderField(HttpHeader.CONTENT_TYPE).getLineNumber())); } }
private List<List<Line>> splitChangeSet(List<Line> remainingMessage) throws BatchDeserializerException { final HeaderField contentTypeField = headers.getHeaderField(HttpHeader.CONTENT_TYPE); final String changeSetBoundary = BatchParserCommon.getBoundary( contentTypeField.getValue(), contentTypeField.getLineNumber()); validateChangeSetBoundary(changeSetBoundary, headers); return BatchParserCommon.splitMessageByBoundary(remainingMessage, changeSetBoundary); }