com.ibm.commerce.server

Class ServletHelper

  • java.lang.Object
    • com.ibm.commerce.server.ServletHelper
  • All Implemented Interfaces:
    ECConstants
    Direct Known Subclasses:
    JSPHelper


    public class ServletHelper
    extends java.lang.Object
    implements ECConstants
    This class contains static methods used by the request servlet.
    • Constructor Detail

      • ServletHelper

        public ServletHelper()
    • Method Detail

      • arrayCopy

        public static void arrayCopy(java.lang.String[] fromArray,
                                     java.lang.String[] toArray)
        Deprecated. 
        This method copies the content of one String array to another String array.
        Parameters:
        fromArray - The original array.
        toArray - The new array.
      • buildHttpsRedirectUrl

        public static java.lang.String buildHttpsRedirectUrl(java.lang.String inUrl,
                                                             TypedProperty reqProperties,
                                                             javax.servlet.http.HttpServletResponse response,
                                                             java.lang.String encoding)
                                                      throws ECApplicationException
        This method builds the URL for redirection. All URL parameters will be encrypted.
        Parameters:
        inUrl - The URL.
        reqProperties - The request properties.
        response - An HttpServletResponse object.
        encoding - The character encoding.
        Returns:
        The redirect URL.
        Throws:
        ECApplicationException
      • buildRedirectUrl

        public static java.lang.String buildRedirectUrl(java.lang.String inUrl,
                                                        TypedProperty reqProperties,
                                                        javax.servlet.http.HttpServletResponse response,
                                                        java.lang.String encoding)
                                                 throws ECApplicationException
        This method builds the URL for redirection. All URL parameters will be encrypted.
        Parameters:
        inUrl - The URL.
        reqProperties - The request properties.
        response - An HttpServletResponse object.
        encoding - The character encoding.
        Returns:
        The redirect URL.
        Throws:
        ECApplicationException
      • buildRedirectUrl

        public static java.lang.String buildRedirectUrl(java.lang.String inUrl,
                                                        TypedProperty reqProperties,
                                                        javax.servlet.http.HttpServletResponse response,
                                                        boolean encrypt,
                                                        java.lang.String encoding)
                                                 throws ECApplicationException
        This method builds the URL for redirection.
        Parameters:
        inUrl - The URL.
        reqProperties - The request properties.
        response - An HttpServletResponse object.
        encrypt - A boolean value; true if the URL parameters will be encrypted and false otherwise.
        encoding - A character encoding.
        Returns:
        The redirect URL.
        Throws:
        ECApplicationException
      • composeQueryString

        public static java.lang.String composeQueryString(TypedProperty prop)
        This method composes a query string from a TypedProperty object.
        Parameters:
        prop - A TypedProperty object.
        Returns:
        The query string.
      • extractEncodedRequestParameters

        public static TypedProperty extractEncodedRequestParameters(java.lang.String queryString,
                                                                    java.lang.String encoding)
                                                             throws ECApplicationException
        This method extracts the request parameters from a query string where each parameter is encoded, and converts it to a TypedProperty object.
        Parameters:
        queryString - A query string.
        encoding - A character encoding.
        Returns:
        A TypedProperty object.
        Throws:
        ECApplicationException
      • extractRequestParameters

        public static TypedProperty extractRequestParameters(java.lang.String queryString)
                                                      throws ECApplicationException
        This method extracts the request parameters from a query string and converts it to a TypedProperty object. It is assumed that each parameter is not encoded.
        Parameters:
        queryString - A query string.
        Returns:
        A TypedProperty object.
        Throws:
        ECApplicationException
      • extractRequestParameters

        public static TypedProperty extractRequestParameters(javax.servlet.http.HttpServletRequest req)
                                                      throws ECApplicationException
        This method extracts the request parameters from an HttpServletRequest and builds a TypedProperty object based on the parameters.
        Parameters:
        req - An HttpServletRequest object.
        Returns:
        A TypedProperty object.
        Throws:
        ECApplicationException
      • extractMultipartParameters

        public static TypedProperty extractMultipartParameters(javax.servlet.http.HttpServletRequest req)
                                                        throws ECApplicationException
        This method extracts multipart request parameters from an HttpServletRequest object and builds a TypedProperty object based on the parameters.
        Parameters:
        req - An HttpServletRequest object.
        Returns:
        A TypedProperty object.
        Throws:
        ECApplicationException
      • getNVPHash

        public static java.util.Hashtable getNVPHash(javax.servlet.http.HttpServletRequest request)
        This method gets the name/value pairs.
        Parameters:
        request - An HttpServletRequest object.
        Returns:
        A Hashtable of the name/value pairs.
      • getNVPHashArray

        public static java.util.Hashtable getNVPHashArray(javax.servlet.http.HttpServletRequest request)
        This method returns a Hashtable of key/value pairs, where the values are arrays of String objects. Keys that appear once in the query string have, in the Hashtable, a String array of length one as their value. Keys that appear twice have a String array of length two, and so forth.
        Parameters:
        request - An HttpServletRequest object.
        Returns:
        A Hashtable of the name/value pairs.
      • getParameter

        public static java.lang.String getParameter(javax.servlet.http.HttpServletRequest request,
                                                    java.lang.String name)
        This method returns a parameter as a String from the HttpServletRequest.
        Parameters:
        request - An HttpServletRequest object.
        name - The name of the parameter.
        Returns:
        The parameter string.
      • getSessionID

        public static java.lang.String getSessionID(javax.servlet.http.HttpServletRequest req)
        This method gets the session id.
        Parameters:
        req - An HttpServletRequest object.
        Returns:
        The session id.
      • getURLParameters

        public static java.util.Vector getURLParameters(javax.servlet.http.HttpServletRequest request)
        This method gets the URL parameters.
        Parameters:
        req - An HttpServletRequest object.
        Returns:
        A Vector object that represents the URL parameters.
      • getUserRefNum

        public static java.lang.Integer getUserRefNum(javax.servlet.http.HttpServletRequest req)
        This method gets the user reference number.
        Parameters:
        req - An HttpServletRequest object.
        Returns:
        The user reference number.
      • markTransactionToRollback

        public static void markTransactionToRollback()
        This method marks the current transaction for roll back.
      • protectQueryString

        public static java.lang.String protectQueryString(java.lang.String queryString)
        This method parses a query string for protected parameters and replaces all protected parameter values with "*******"

        Parameters:
        queryString - A query string.
        Returns:
        A query string with protected values replaced.
      • rollbackTransaction

        public static void rollbackTransaction()
        This method rolls back the current transaction. This method is to be called when an error is detected in a JSP and the command associated with this JSP has to rollback.
      • servletRequestToString

        public static java.lang.String servletRequestToString(javax.servlet.http.HttpServletRequest request)
        This method extracts useful information from an HttpServletRequest for debugging purposes.
        Parameters:
        request - An HttpServletRequest object.
        Returns:
        A string of request information.
      • servletRequestToStringDebug

        public static java.lang.String servletRequestToStringDebug(javax.servlet.http.HttpServletRequest request)
        This method extracts all information from an HttpServletRequest object useful for debugging purposes.
        Parameters:
        request - An HttpServletRequest object.
        Returns:
        This method returns a String object of request information.
      • setEncoding

        public static java.lang.String setEncoding(javax.servlet.http.HttpServletRequest req,
                                                   java.lang.String strDefaultEncoding)
        Deprecated. Use setEncoding(HttpServletRequest req, String defaultEncoding, String cookiePreix) instead
        This method reserved for IBM Internal use only. This method sets the encoding used for retrieving request parameters.
        Parameters:
        req - An HttpServletRequest object for which the encoding is to be set.
        strDefaultEncoding - The encoding value.
        Returns:
        This method returns the encoding string.
      • setEncoding

        public static java.lang.String setEncoding(javax.servlet.http.HttpServletRequest req,
                                                   java.lang.String strDefaultEncoding,
                                                   java.lang.String strCookiePrefix)
        This method reserved for IBM Internal use only. This method sets the encoding for used for retrieving request parameters.
        Parameters:
        req - An HttpServletRequest object for which the encoding is to be set.
        strDefaultEncoding - The encoding value.
        strCookiePrefix - The cookie prefix used by the adapter, for example, WC or WCP.
        Returns:
        This method returns the encoding string.
      • stringToArray

        public static java.lang.String[] stringToArray(java.lang.String value)
        This method converts a string with values separated by commas to an array of strings.
        Parameters:
        value - A String object to be converted to an array.
        Returns:
        An array of string String objects.
      • stringToIntegerArray

        public static java.lang.Integer[] stringToIntegerArray(java.lang.String[] sarray)
        This method converts an array of String objects to an array of Integer objects.
        Parameters:
        sarray - An array of String objects.
        Returns:
        An array of Integer objects.
      • composeEncodedQueryString

        public static java.lang.String composeEncodedQueryString(TypedProperty prop)
        This method composes a query string from a TypedProperties object.
        Parameters:
        prop - A TypedProperties object.
        Returns:
        The query string.
      • getActivePointerName

        public static java.lang.String getActivePointerName(java.lang.String strCookiePrefix)
        This method returns the name of the active pointer cookie given a specified prefix.
        Parameters:
        strCookiePrefix - The prefix to be used at the beginning of the cookie. This could be null if the requesting servlet did not define cookiePrefix as an initParameter. If the case is unspecified, the default value of WC will be used as the cookie prefix.
        Returns:
        The name of the active pointer cookie given a specified prefix.
      • setEncoding

        public static void setEncoding(javax.servlet.http.HttpServletRequest req,
                                       java.lang.Integer sessionLangId,
                                       java.lang.Integer storeId,
                                       java.lang.String defaultEncoding)
        This method sets the encoding to be used to extract the input parameters.
        Parameters:
        req - The HttpServletRequest object.
        sessionLangId - The language id saved in the session.
        storeId - The store id.
        defaultEncoding - The default encoding.
      • getStoreIdFromQueryString

        public static java.lang.Integer getStoreIdFromQueryString(javax.servlet.http.HttpServletRequest req,
                                                                  java.lang.Integer defaultStoreId)
        This method gets the store id from the query string.
        Parameters:
        req - An HttpServletRequest object.
        defaultStoreId - The default store id.
        Returns:
        The store id.
      • encodeURL

        public static java.lang.String encodeURL(java.lang.String val,
                                                 java.lang.String encoding)
                                          throws java.io.UnsupportedEncodingException
        This method encodes a URL string with a given encoding. If encoding is null, the default encoding should be used.
        Parameters:
        val - The URL to encode.
        The - encoding to use.
        Returns:
        This method returns the encoded URL.
        Throws:
        java.io.UnsupportedEncodingException
      • decodeURL

        public static java.lang.String decodeURL(java.lang.String val,
                                                 java.lang.String encoding)
                                          throws java.io.UnsupportedEncodingException
        This method decodes a URL string with a given encoding. If encoding is null, the default encoding should be used.
        Parameters:
        val - The URL to decode.
        The - encoding to use.
        Returns:
        This method returns the decoded URL.
        Throws:
        java.io.UnsupportedEncodingException
      • buildRedirectUrl

        public static java.lang.String buildRedirectUrl(java.lang.String inUrl,
                                                        java.util.Map map,
                                                        javax.servlet.http.HttpServletResponse response,
                                                        boolean encrypt,
                                                        java.lang.String encoding)
                                                 throws java.lang.Exception
        This method builds a redirect URL.
        Parameters:
        inUrl - The base input URL.
        map - The URL parameters as a Map.
        response - An HttpServletResponse object.
        encrypt - A flag to indicate whether encryption is required.
        encoding - A character encoding
        Returns:
        A String object.
        Throws:
        java.lang.Exception
      • getConfigFileName

        public static java.lang.String getConfigFileName(javax.servlet.http.HttpServlet servlet)
                                                  throws javax.servlet.ServletException
        This method gets the configuration file name.
        Returns:
        The path to an EAR file.
        Throws:
        javax.servlet.ServletException
      • isSSLRequest

        public static boolean isSSLRequest(javax.servlet.http.HttpServletRequest req)
        This method determines whether the request comes on a secure connection.
        Parameters:
        req - An HttpServletRequest object.
        Returns:
        This method returns true if the request comes on a secure connection and false otherwise.
      • getRequestName

        public static java.lang.String getRequestName(javax.servlet.http.HttpServletRequest req)
        This method returns the request name that is used to select an action.
        Parameters:
        req - The servlet request.
        res - The servlet response.
        Returns:
        This method returns the request name.
      • findStoreUrlRegistryEntry

        public static com.ibm.commerce.registry.UrlRegistryEntry findStoreUrlRegistryEntry(java.lang.String name,
                                                                                           java.lang.Integer storeId)
        Look up URL registry entry from URL registry by from all URL registry sources for store modules.
        Parameters:
        name - the name of the URL entry
        storeId - the store ID of the URL entry
        Returns:
        the URL registry entry found.
      • checkRedirectAllowed

        public static void checkRedirectAllowed(java.lang.String url,
                                                java.lang.String servletContextName,
                                                java.lang.String requestStoreId,
                                                javax.servlet.http.HttpServletRequest req)
                                         throws ECApplicationException
        Check if the URL redirection is allowed based on the servlet context name and the store ID. The configuration for allowed URLS is stored in wc-server.xml
        Parameters:
        url - the url to verify
        servletContextName - the servlet context name. If null, no validation will be performed.
        requestStoreId - the request store ID, if null, only site-wide domains and hosts will be used.
        req - an HttpServletRequest object.
        Throws:
        ECApplicationException - if the URL isn't allowed to be used for a redirection.