Class HttpHeaderHelper


  • public final class HttpHeaderHelper
    extends java.lang.Object
    Class helper to manage specifics Vitam headers
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkVitamHeaders​(javax.ws.rs.core.HttpHeaders headers)
      Check specific vitam headers values with regular expression from the (define in VitamHttpHeader) At the first wrong value, treatment stops and throws an IllegalStateException Note that, the regular expression is case insensitive.
      static void checkVitamHeadersMap​(javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> requestHeaders)
      Check specific vitam headers values with regular expression from the (define in VitamHttpHeader) At the first wrong value, treatment stops and throws an IllegalStateException Note that, the regular expression is case insensitive.
      static java.util.List<java.lang.String> getHeaderValues​(javax.ws.rs.core.HttpHeaders headers, VitamHttpHeader name)
      Get header values from HttpHeaders for VitamHttpHeader
      static java.util.List<java.lang.String> getHeaderValues​(javax.ws.rs.core.HttpHeaders headers, java.lang.String name)
      Retrieve header values from HttpHeaders for VitamHttpHeader
      static boolean hasValuesFor​(javax.ws.rs.core.HttpHeaders headers, VitamHttpHeader vitamHeader)
      Check if headers are declared
      static void validateHeaderValue​(javax.ws.rs.core.HttpHeaders headers, javax.ws.rs.core.MultivaluedHashMap<java.lang.String,​java.lang.String> wantedHeaders)
      Validate HTTP header values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getHeaderValues

        public static java.util.List<java.lang.String> getHeaderValues​(javax.ws.rs.core.HttpHeaders headers,
                                                                       VitamHttpHeader name)
        Get header values from HttpHeaders for VitamHttpHeader
        Parameters:
        headers - the headers list
        name - the VitamHttpHeader with wanted header name
        Returns:
        the list of values for specified header name
        Throws:
        java.lang.IllegalArgumentException - if headers or name is null
      • getHeaderValues

        public static java.util.List<java.lang.String> getHeaderValues​(javax.ws.rs.core.HttpHeaders headers,
                                                                       java.lang.String name)
        Retrieve header values from HttpHeaders for VitamHttpHeader
        Parameters:
        headers - the headers list
        name - the header name
        Returns:
        the list of values for specified header name
        Throws:
        java.lang.IllegalArgumentException - if headers is null or name is null or empty
      • hasValuesFor

        public static boolean hasValuesFor​(javax.ws.rs.core.HttpHeaders headers,
                                           VitamHttpHeader vitamHeader)
        Check if headers are declared
        Parameters:
        headers - the headers list to check
        vitamHeader - the header to retreive
        Returns:
        true if the header is defined, false otherwise
        Throws:
        java.lang.IllegalArgumentException - if headers or vitamHeader is null
      • checkVitamHeaders

        public static void checkVitamHeaders​(javax.ws.rs.core.HttpHeaders headers)
        Check specific vitam headers values with regular expression from the (define in VitamHttpHeader) At the first wrong value, treatment stops and throws an IllegalStateException Note that, the regular expression is case insensitive.
        Parameters:
        headers - HTTP headers list to check
        Throws:
        java.lang.IllegalStateException - when a header value doesn't match with teh defined regular expression
        java.lang.IllegalArgumentException - if headers is null
      • checkVitamHeadersMap

        public static void checkVitamHeadersMap​(javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> requestHeaders)
        Check specific vitam headers values with regular expression from the (define in VitamHttpHeader) At the first wrong value, treatment stops and throws an IllegalStateException Note that, the regular expression is case insensitive.
        Parameters:
        requestHeaders - HTTP headers list to check
        Throws:
        java.lang.IllegalStateException - when a header value doesn't match with the defined regular expression
      • validateHeaderValue

        public static void validateHeaderValue​(javax.ws.rs.core.HttpHeaders headers,
                                               javax.ws.rs.core.MultivaluedHashMap<java.lang.String,​java.lang.String> wantedHeaders)
        Validate HTTP header values. If header is known by the VitamHttpHeader then check if format matches with the defined regular expression. Also check the wantedHeaders map values with VitamHttpHeader. Values of headers (from HTTP or from wanted list) can not be null (throw an exception). In case of error, the exception contains all errors in its message.
        Parameters:
        headers - the headers list to validate
        wantedHeaders - the map representing wanted header values with the key for header name and the value (list) for the wanted values for this specific header name
        Throws:
        java.lang.IllegalArgumentException - if headers is null
        java.lang.IllegalStateException - if one or more header values does not equal to wanted values, header values do not match with the defined regular expression, wanted values for a header are null, header values are null. This exception contains all errors in its message.