Class HttpUtil

java.lang.Object
org.apache.camel.support.http.HttpUtil

public final class HttpUtil extends Object
  • Method Details

    • determineResponseCode

      public static int determineResponseCode(org.apache.camel.Exchange camelExchange, Object body)
      Given an exchange handling HTTP, determines the status response code to return for the caller
      Parameters:
      camelExchange - the exchange to evaluate
      body - an optional payload (i.e.: the message body) carrying a response code
      Returns:
      An integer value with the response code
    • getCharsetFromContentType

      @Deprecated(since="4.3.0") public static String getCharsetFromContentType(String contentType)
      Deprecated.
      use IOHelper.getCharsetNameFromContentType(String)
      Deprecated way to extract the charset value from the content type string
      Parameters:
      contentType - the content type string
      Returns:
      the charset value or null if there is nothing to extract
    • setCharsetFromContentType

      public static void setCharsetFromContentType(String contentType, org.apache.camel.Exchange exchange)
      Extracts the charset value from the content type string and sets it on the given exchange
      Parameters:
      contentType - the content type string
      exchange - the exchange to set the charset value
    • recreateUrl

      public static String recreateUrl(Map<String,Object> map, String url)
      Recreates the URL from a map of options
      Parameters:
      map - the map of options
      url - the base URL
      Returns:
      the recreated URL
    • addCommonFilters

      public static void addCommonFilters(Set<String> filterSet)
      Add common in/out filters used in HTTP components
      Parameters:
      filterSet - The set instance containing the out filters
    • isStatusCodeOk

      public static boolean isStatusCodeOk(int statusCode, String okStatusCodeRange)
      Checks whether the given http status code is within the ok range
      Parameters:
      statusCode - the status code
      okStatusCodeRange - the ok range (inclusive)
      Returns:
      true if ok, false otherwise
    • parseStatusRange

      public static boolean parseStatusRange(String range, BiConsumer<Integer,Integer> consumer)
      Parse a HTTP status range and passes the values to the consumer method
      Parameters:
      range - the HTTP status range in the format "XXX-YYY" (i.e.: 200-299)
      consumer - a consumer method to receive the parse ranges
      Returns:
      true if the range was parsed or false otherwise
    • applyHeader

      public static void applyHeader(org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy, org.apache.camel.Exchange exchange, Iterator<?> it, org.apache.camel.TypeConverter tc, String key, BiConsumer<List<String>,String> consumer)
      Iterates over a list of values and passes them to the consumer after applying the filter strategy. This is mostly used to simplify setting headers for HTTP responses
      Parameters:
      headerFilterStrategy - the filter strategy to apply
      exchange - an exchange to apply the header strategy
      it - the iterator providing the values
      tc - a type converter instance so that the values can be converted to string
      key - a key associated with the values being iterated
      consumer - a consumer method to receive the converted values. It can receive either a list of values or a single value.
    • filterCheck

      public static boolean filterCheck(String templateUri, String queryParameters, String headerName, boolean answer)