Class ServletUtils


  • public class ServletUtils
    extends java.lang.Object
    ServletUtils class of OneLogin's Java Toolkit. A class that contains several auxiliary methods related to HttpServletRequest and HttpServletResponse
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ServletUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getSelfHost​(javax.servlet.http.HttpServletRequest request)  
      static java.lang.String getSelfRoutedURLNoQuery​(javax.servlet.http.HttpServletRequest request)
      Returns the routed URL of the current host + current view.
      static java.lang.String getSelfURL​(javax.servlet.http.HttpServletRequest request)
      Returns the URL of the current context + current view + query
      static java.lang.String getSelfURLhost​(javax.servlet.http.HttpServletRequest request)
      Returns the protocol + the current host + the port (if different than common ports).
      static java.lang.String getSelfURLNoQuery​(javax.servlet.http.HttpServletRequest request)
      Returns the URL of the current host + current view.
      static boolean isHTTPS​(javax.servlet.http.HttpServletRequest request)
      Check if under https or http protocol
      static HttpRequest makeHttpRequest​(javax.servlet.http.HttpServletRequest req)
      Creates an HttpRequest from an HttpServletRequest.
      static void sendRedirect​(javax.servlet.http.HttpServletResponse response, java.lang.String location)
      Redirect to location url
      static void sendRedirect​(javax.servlet.http.HttpServletResponse response, java.lang.String location, java.util.Map<java.lang.String,​java.lang.String> parameters)
      Redirect to location url
      static java.lang.String sendRedirect​(javax.servlet.http.HttpServletResponse response, java.lang.String location, java.util.Map<java.lang.String,​java.lang.String> parameters, java.lang.Boolean stay)
      Redirect to location url
      • Methods inherited from class java.lang.Object

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

      • ServletUtils

        private ServletUtils()
    • Method Detail

      • makeHttpRequest

        public static HttpRequest makeHttpRequest​(javax.servlet.http.HttpServletRequest req)
        Creates an HttpRequest from an HttpServletRequest.
        Parameters:
        req - the incoming HttpServletRequest
        Returns:
        a HttpRequest
      • getSelfURLhost

        public static java.lang.String getSelfURLhost​(javax.servlet.http.HttpServletRequest request)
        Returns the protocol + the current host + the port (if different than common ports).
        Parameters:
        request - HttpServletRequest object to be processed
        Returns:
        the HOST URL
      • getSelfHost

        public static java.lang.String getSelfHost​(javax.servlet.http.HttpServletRequest request)
        Parameters:
        request - HttpServletRequest object to be processed
        Returns:
        the server name
      • isHTTPS

        public static boolean isHTTPS​(javax.servlet.http.HttpServletRequest request)
        Check if under https or http protocol
        Parameters:
        request - HttpServletRequest object to be processed
        Returns:
        false if https is not active
      • getSelfURL

        public static java.lang.String getSelfURL​(javax.servlet.http.HttpServletRequest request)
        Returns the URL of the current context + current view + query
        Parameters:
        request - HttpServletRequest object to be processed
        Returns:
        current context + current view + query
      • getSelfURLNoQuery

        public static java.lang.String getSelfURLNoQuery​(javax.servlet.http.HttpServletRequest request)
        Returns the URL of the current host + current view.
        Parameters:
        request - HttpServletRequest object to be processed
        Returns:
        current host + current view
      • getSelfRoutedURLNoQuery

        public static java.lang.String getSelfRoutedURLNoQuery​(javax.servlet.http.HttpServletRequest request)
        Returns the routed URL of the current host + current view.
        Parameters:
        request - HttpServletRequest object to be processed
        Returns:
        the current routed url
      • sendRedirect

        public static java.lang.String sendRedirect​(javax.servlet.http.HttpServletResponse response,
                                                    java.lang.String location,
                                                    java.util.Map<java.lang.String,​java.lang.String> parameters,
                                                    java.lang.Boolean stay)
                                             throws java.io.IOException
        Redirect to location url
        Parameters:
        response - HttpServletResponse object to be used
        location - target location url
        parameters - GET parameters to be added
        stay - True if we want to stay (returns the url string) False to execute redirection
        Returns:
        string the target URL
        Throws:
        java.io.IOException
        See Also:
        HttpServletResponse.sendRedirect(String)
      • sendRedirect

        public static void sendRedirect​(javax.servlet.http.HttpServletResponse response,
                                        java.lang.String location,
                                        java.util.Map<java.lang.String,​java.lang.String> parameters)
                                 throws java.io.IOException
        Redirect to location url
        Parameters:
        response - HttpServletResponse object to be used
        location - target location url
        parameters - GET parameters to be added
        Throws:
        java.io.IOException
        See Also:
        HttpServletResponse.sendRedirect(String)
      • sendRedirect

        public static void sendRedirect​(javax.servlet.http.HttpServletResponse response,
                                        java.lang.String location)
                                 throws java.io.IOException
        Redirect to location url
        Parameters:
        response - HttpServletResponse object to be used
        location - target location url
        Throws:
        java.io.IOException
        See Also:
        HttpServletResponse.sendRedirect(String)