Class HttpUtils

java.lang.Object
org.pac4j.core.util.HttpUtils

public final class HttpUtils extends Object
This class provides utility functions to deal with opening connections, building error messages and closing connections, etc.
Since:
1.8.0
Author:
Misagh Moayyed
  • Method Details

    • buildHttpErrorMessage

      public static String buildHttpErrorMessage(HttpURLConnection connection) throws IOException
      Build error message from connection in case of failure
      Parameters:
      connection - HttpURLConnection
      Returns:
      String by combining response code, message and error stream
      Throws:
      IOException - an IO exception
    • openPostConnection

      public static HttpURLConnection openPostConnection(URL url) throws IOException

      openPostConnection.

      Parameters:
      url - a URL object
      Returns:
      a HttpURLConnection object
      Throws:
      IOException - if any.
    • openPostConnection

      public static HttpURLConnection openPostConnection(URL url, Map<String,String> headers) throws IOException

      openPostConnection.

      Parameters:
      url - a URL object
      headers - a Map object
      Returns:
      a HttpURLConnection object
      Throws:
      IOException - if any.
    • openDeleteConnection

      public static HttpURLConnection openDeleteConnection(URL url) throws IOException

      openDeleteConnection.

      Parameters:
      url - a URL object
      Returns:
      a HttpURLConnection object
      Throws:
      IOException - if any.
    • openConnection

      protected static HttpURLConnection openConnection(URL url, String requestMethod, Map<String,String> headers) throws IOException

      openConnection.

      Parameters:
      url - a URL object
      requestMethod - a String object
      headers - a Map object
      Returns:
      a HttpURLConnection object
      Throws:
      IOException - if any.
    • readBody

      public static String readBody(HttpURLConnection connection) throws IOException

      readBody.

      Parameters:
      connection - a HttpURLConnection object
      Returns:
      a String object
      Throws:
      IOException - if any.
    • encodeQueryParam

      public static String encodeQueryParam(String paramName, String paramValue)

      encodeQueryParam.

      Parameters:
      paramName - a String object
      paramValue - a String object
      Returns:
      a String object
    • closeConnection

      public static void closeConnection(HttpURLConnection connection)

      closeConnection.

      Parameters:
      connection - a HttpURLConnection object
    • getConnectTimeout

      public static int getConnectTimeout()

      Getter for the field connectTimeout.

      Returns:
      a int
    • setConnectTimeout

      public static void setConnectTimeout(int connectTimeout)

      Setter for the field connectTimeout.

      Parameters:
      connectTimeout - a int
    • getReadTimeout

      public static int getReadTimeout()

      Getter for the field readTimeout.

      Returns:
      a int
    • setReadTimeout

      public static void setReadTimeout(int readTimeout)

      Setter for the field readTimeout.

      Parameters:
      readTimeout - a int