Class HttpUtils

java.lang.Object
com.erudika.para.server.utils.HttpUtils

public final class HttpUtils extends Object
Various utilities for HTTP stuff - cookies, AJAX, etc.
Author:
Alex Bogdanovski [[email protected]]
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    getCookieValue(javax.servlet.http.HttpServletRequest req, String name)
    Reads a cookie.
    static String
    getStateParam(String name, javax.servlet.http.HttpServletRequest req)
    Reads a cookie.
    static boolean
    isAjaxRequest(javax.servlet.http.HttpServletRequest request)
    Checks if a request comes from JavaScript.
    static void
    removeStateParam(String name, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
    Deletes a cookie.
    static void
    setAuthCookie(String name, String value, boolean httpOnly, int maxAge, String sameSite, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Sets the auth cookie.
    static void
    setAuthCookie(String name, String value, int maxAge, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Sets the auth cookie.
    static void
    setRawCookie(String name, String value, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, boolean httpOnly, int maxAge)
    Sets a cookie.
    static void
    setStateParam(String name, String value, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
    Sets a cookie.
    static void
    setStateParam(String name, String value, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, boolean httpOnly)
    Sets a cookie.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isAjaxRequest

      public static boolean isAjaxRequest(javax.servlet.http.HttpServletRequest request)
      Checks if a request comes from JavaScript.
      Parameters:
      request - HTTP request
      Returns:
      true if AJAX
    • setStateParam

      public static void setStateParam(String name, String value, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
      Sets a cookie.
      Parameters:
      name - the name
      value - the value
      req - HTTP request
      res - HTTP response
    • setStateParam

      public static void setStateParam(String name, String value, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, boolean httpOnly)
      Sets a cookie.
      Parameters:
      name - the name
      value - the value
      req - HTTP request
      res - HTTP response
      httpOnly - HTTP only flag
    • getStateParam

      public static String getStateParam(String name, javax.servlet.http.HttpServletRequest req)
      Reads a cookie.
      Parameters:
      name - the name
      req - HTTP request
      Returns:
      the cookie value
    • removeStateParam

      public static void removeStateParam(String name, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
      Deletes a cookie.
      Parameters:
      name - the name
      req - HTTP request
      res - HTTP response
    • setRawCookie

      public static void setRawCookie(String name, String value, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, boolean httpOnly, int maxAge)
      Sets a cookie.
      Parameters:
      name - the name
      value - the value
      req - HTTP request
      res - HTTP response
      httpOnly - HTTP only flag
      maxAge - max age
    • getCookieValue

      public static String getCookieValue(javax.servlet.http.HttpServletRequest req, String name)
      Reads a cookie.
      Parameters:
      req - HTTP request
      name - the name
      Returns:
      the cookie value
    • setAuthCookie

      public static void setAuthCookie(String name, String value, int maxAge, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Sets the auth cookie.
      Parameters:
      name - name
      value - value
      maxAge - maxAge
      request - request
      response - response
    • setAuthCookie

      public static void setAuthCookie(String name, String value, boolean httpOnly, int maxAge, String sameSite, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Sets the auth cookie.
      Parameters:
      name - name
      value - value
      httpOnly - HTTP only flag
      maxAge - cookie validity in seconds
      sameSite - SameSite value
      request - request
      response - response