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()));
    }
  }
  public static void validateContentType(final Header headers, final ContentType expected)
      throws BatchDeserializerException {
    final List<String> contentTypes = headers.getHeaders(HttpHeader.CONTENT_TYPE);

    if (contentTypes.isEmpty()) {
      throw new BatchDeserializerException(
          "Missing content type",
          MessageKeys.MISSING_CONTENT_TYPE,
          Integer.toString(headers.getLineNumber()));
    }
    BatchParserCommon.parseContentType(contentTypes.get(0), expected, headers.getLineNumber());
  }
Ejemplo n.º 3
0
  private boolean isChangeSet(final Header headers) throws BatchDeserializerException {
    final List<String> contentTypes = headers.getHeaders(HttpHeader.CONTENT_TYPE);

    if (contentTypes.isEmpty()) {
      throw new BatchDeserializerException(
          "Missing content type",
          BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE,
          Integer.toString(headers.getLineNumber()));
    }

    boolean changeSet = false;
    for (String contentType : contentTypes) {
      if (isContentTypeMultiPartMixed(contentType)) {
        changeSet = true;
      }
    }
    return changeSet;
  }