Class HttpHelper

java.lang.Object
org.apache.camel.http.common.HttpHelper

public final class HttpHelper extends Object
  • Method Details Link icon

    • isSecureConnection Link icon

      public static boolean isSecureConnection(String uri)
    • parserHttpVersion Link icon

      public static int[] parserHttpVersion(String s) throws ProtocolException
      Throws:
      ProtocolException
    • setCharsetFromContentType Link icon

      public static void setCharsetFromContentType(String contentType, org.apache.camel.Exchange exchange)
    • getCharsetFromContentType Link icon

      public static String getCharsetFromContentType(String contentType)
    • writeObjectToServletResponse Link icon

      public static void writeObjectToServletResponse(jakarta.servlet.ServletResponse response, Object target) throws IOException
      Writes the given object as response body to the servlet response

      The content type will be set to HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT

      Parameters:
      response - servlet response
      target - object to write
      Throws:
      IOException - is thrown if error writing
    • writeObjectToStream Link icon

      public static void writeObjectToStream(OutputStream stream, Object target) throws IOException
      Writes the given object as response body to the output stream
      Parameters:
      stream - output stream
      target - object to write
      Throws:
      IOException - is thrown if error writing
    • deserializeJavaObjectFromStream Link icon

      @Deprecated public static Object deserializeJavaObjectFromStream(InputStream is) throws ClassNotFoundException, IOException
      Deprecated.
      Camel 3.0 Please use the one which has the parameter of camel context
      Deserializes the input stream to a Java object
      Parameters:
      is - input stream for the Java object
      Returns:
      the java object, or null if input stream was null
      Throws:
      ClassNotFoundException - is thrown if class not found
      IOException - can be thrown
    • deserializeJavaObjectFromStream Link icon

      public static Object deserializeJavaObjectFromStream(InputStream is, org.apache.camel.CamelContext context) throws ClassNotFoundException, IOException
      Deserializes the input stream to a Java object
      Parameters:
      is - input stream for the Java object
      context - the camel context which could help us to apply the customer classloader
      Returns:
      the java object, or null if input stream was null
      Throws:
      ClassNotFoundException - is thrown if class not found
      IOException - can be thrown
    • readRequestBodyFromServletRequest Link icon

      public static Object readRequestBodyFromServletRequest(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Exchange exchange) throws IOException
      Reads the request body from the given http servlet request.
      Parameters:
      request - http servlet request
      exchange - the exchange
      Returns:
      the request body, can be null if no body
      Throws:
      IOException - is thrown if error reading request body
    • cacheResponseBodyFromInputStream Link icon

      public static Object cacheResponseBodyFromInputStream(InputStream is, org.apache.camel.Exchange exchange) throws IOException
      Caches the response body from the given input stream, which is needed by PollingConsumer.
      Parameters:
      is - the input stream
      exchange - the exchange
      Returns:
      the cached response body
      Throws:
      IOException - is thrown if error reading response body
    • createURL Link icon

      public static String createURL(org.apache.camel.Exchange exchange, HttpCommonEndpoint endpoint)
      Creates the URL to invoke.
      Parameters:
      exchange - the exchange
      endpoint - the endpoint
      Returns:
      the URL to invoke
    • createURI Link icon

      public static URI createURI(org.apache.camel.Exchange exchange, String url, HttpCommonEndpoint endpoint) throws URISyntaxException
      Creates the URI to invoke.
      Parameters:
      exchange - the exchange
      url - the url to invoke
      endpoint - the endpoint
      Returns:
      the URI to invoke
      Throws:
      URISyntaxException
    • appendHeader Link icon

      public static void appendHeader(Map<String,Object> headers, String key, Object value)
      Appends the key/value to the headers.

      This implementation supports keys with multiple values. In such situations the value will be a List that contains the multiple values.

      Parameters:
      headers - headers
      key - the key
      value - the value
    • extractHttpParameterValue Link icon

      public static Object extractHttpParameterValue(String value)
      Extracts the parameter value.

      This implementation supports HTTP multi value parameters which is based on the syntax of [value1, value2, value3] by returning a List containing the values.

      If the value is not a HTTP mulit value the value is returned as is.

      Parameters:
      value - the parameter value
      Returns:
      the extracted parameter value, see more details in javadoc.
    • createMethod Link icon

      public static HttpMethods createMethod(org.apache.camel.Exchange exchange, HttpCommonEndpoint endpoint, boolean hasPayload) throws URISyntaxException
      Creates the HttpMethod to use to call the remote server, often either its GET or POST.
      Parameters:
      exchange - the exchange
      Returns:
      the created method
      Throws:
      URISyntaxException
    • isStatusCodeOk Link icon

      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
    • sanitizeLog Link icon

      public static String[] sanitizeLog(String[] input)
      Sanitize log: it removes any new line and carriage return in order to avoid third party integrations with logging system to suffer potential log injection.
      Parameters:
      input - the log trace
      Returns:
      a sanitized log trace