Class Session


  • public class Session
    extends java.lang.Object
    • Constructor Detail

      • Session

        public Session​(Model model)
        Constructor for the current session. The current system time will be used as the session ID.
        Parameters:
        model -
    • Method Detail

      • discard

        protected void discard()
      • close

        protected void close()
      • getSessionDesc

        public java.lang.String getSessionDesc()
        Returns:
        Returns the sessionDesc.
      • getSessionId

        public long getSessionId()
        Returns:
        Returns the sessionId.
      • getSessionName

        public java.lang.String getSessionName()
        Returns:
        Returns the name.
      • getSiteTree

        public SiteMap getSiteTree()
        Returns:
        Returns the siteTree.
      • isNewState

        public boolean isNewState()
        Tells whether this session is in a new state or not. A session is in a new state if it was never saved or it was not loaded from an existing session.
        Returns:
        true if this session is in a new state, false otherwise.
      • open

        protected void open​(java.io.File file,
                            SessionListener callback)
      • open

        protected void open​(java.lang.String sessionFile,
                            SessionListener callback)
      • open

        protected void open​(java.lang.String fileName)
                     throws DatabaseException,
                            java.io.IOException,
                            java.lang.Exception
        Throws:
        DatabaseException
        java.io.IOException
        java.lang.Exception
      • save

        protected void save​(java.lang.String fileName,
                            SessionListener callback)
        Asynchronous call to save a session.
        Parameters:
        fileName -
        callback -
      • save

        protected void save​(java.lang.String fileName)
                     throws java.lang.Exception
        Synchronous call to save a session.
        Parameters:
        fileName -
        Throws:
        java.lang.Exception
      • persistProperties

        protected void persistProperties()
                                  throws java.lang.Exception
        Persists the properties (e.g. name, description) of the session.

        Should be called only by "core" classes.

        Throws:
        java.lang.Exception - if an error occurred while persisting the properties.
        Since:
        2.7.0
        See Also:
        setSessionName(String), setSessionDesc(String)
      • snapshot

        protected void snapshot​(java.lang.String fileName,
                                SessionListener callback)
        Asynchronous call to snapshot a session.
        Parameters:
        fileName -
        callback -
      • snapshot

        protected void snapshot​(java.lang.String fileName)
                         throws java.lang.Exception
        Synchronous call to snapshot a session.
        Parameters:
        fileName -
        Throws:
        java.lang.Exception
      • setSessionDesc

        public void setSessionDesc​(java.lang.String sessionDesc)
        Parameters:
        sessionDesc - The sessionDesc to set.
      • setSessionId

        public void setSessionId​(long sessionId)
        Parameters:
        sessionId - The sessionId to set.
      • setSessionName

        public void setSessionName​(java.lang.String name)
        Parameters:
        name - The name to set.
      • getFileName

        public java.lang.String getFileName()
      • getSessionFolder

        public java.lang.String getSessionFolder()
      • getExcludeFromProxyRegexs

        public java.util.List<java.lang.String> getExcludeFromProxyRegexs()
      • isIncludedInScope

        protected boolean isIncludedInScope​(SiteNode sn)
      • isExcludedFromScope

        protected boolean isExcludedFromScope​(SiteNode sn)
      • isInScope

        public boolean isInScope​(SiteNode sn)
      • isInScope

        public boolean isInScope​(java.lang.String url)
      • getNodesInScopeFromSiteTree

        public java.util.List<SiteNode> getNodesInScopeFromSiteTree()
        Gets the nodes from the site tree which are "In Scope". Searches recursively starting from the root node. Should be used with care, as it is time-consuming, querying the database for every node in the Site Tree.
        Returns:
        the nodes in scope from site tree
      • getTopNodesInScopeFromSiteTree

        public java.util.List<SiteNode> getTopNodesInScopeFromSiteTree()
        Gets the top nodes from the site tree which contain nodes that are "In Scope". Searches recursively starting from the root node. Should be used with care, as it is time-consuming, querying the database for every node in the Site Tree.
        Returns:
        the nodes in scope from site tree
      • getNodesInContextFromSiteTree

        public java.util.List<SiteNode> getNodesInContextFromSiteTree​(Context context)
        Gets the nodes from the site tree which are "In Scope" in a given context. Searches recursively starting from the root node. Should be used with care, as it is time-consuming, querying the database for every node in the Site Tree.
        Parameters:
        context - the context
        Returns:
        the nodes in scope from site tree
      • setExcludeFromProxyRegexs

        public void setExcludeFromProxyRegexs​(java.util.List<java.lang.String> ignoredRegexs)
                                       throws DatabaseException
        Throws:
        DatabaseException
      • getExcludeFromScanRegexs

        public java.util.List<java.lang.String> getExcludeFromScanRegexs()
      • getExcludeFromSpiderRegexs

        public java.util.List<java.lang.String> getExcludeFromSpiderRegexs()
        Gets the regular expressions used to exclude URLs from the spiders (e.g. traditional, AJAX).
        Returns:
        a List containing the regular expressions, never null.
      • addExcludeFromSpiderRegex

        public void addExcludeFromSpiderRegex​(java.lang.String ignoredRegex)
                                       throws DatabaseException
        Adds the given regular expression to the list of regular expressions used to exclude URLs from the spiders (e.g. traditional, AJAX).
        Parameters:
        ignoredRegex - the regular expression to be added
        Throws:
        java.lang.IllegalArgumentException - if the regular expression is not valid.
        DatabaseException - if an error occurred while persisting the list.
      • setExcludeFromSpiderRegexs

        public void setExcludeFromSpiderRegexs​(java.util.List<java.lang.String> ignoredRegexs)
                                        throws DatabaseException
        Sets the given regular expressions as the list of regular expressions used to exclude URLs from the spiders (e.g. traditional, AJAX).
        Parameters:
        ignoredRegexs - the regular expressions to be set
        Throws:
        java.lang.IllegalArgumentException - if any of the regular expressions is not valid.
        DatabaseException - if an error occurred while persisting the list.
      • forceGlobalExcludeURLRefresh

        @Deprecated
        public void forceGlobalExcludeURLRefresh()
        Deprecated.
        (2.12.0) No longer used/needed. It will be removed in a future release.
        Resets the global exclude URLs of the Local Proxy.

        This should be considered an internal method, to be called only by core code.

        Since:
        2.3.0
      • getGlobalExcludeURLRegexs

        public java.util.List<java.lang.String> getGlobalExcludeURLRegexs()
        Gets the global exclude URLs.

        Note: This method is only provided as a convenience, the global exclude URLs are not saved in the session.

        Returns:
        an unmodifiable List containing the URLs that should be excluded globally.
        Since:
        2.3.0
      • setGlobalExcludedUrlRegexsSupplier

        public void setGlobalExcludedUrlRegexsSupplier​(java.util.function.Supplier<java.util.List<java.lang.String>> supplier)
        Sets the supplier of global exclude URLs.

        Note: Not part of the public API.

        Parameters:
        supplier - the supplier of global exclude URLs.
        Since:
        2.13.0
      • getContextDataString

        public java.lang.String getContextDataString​(int contextId,
                                                     int type,
                                                     java.lang.String defaultValue)
                                              throws DatabaseException
        Returns a context data string of the given type and using the given default value if the value is not present
        Parameters:
        contextId - the context Id
        type - the data type required
        defaultValue - the default value to use if the type is not present
        Returns:
        the context data string
        Throws:
        DatabaseException
        Since:
        2.10.0
      • getContextDataInteger

        public int getContextDataInteger​(int contextId,
                                         int type,
                                         int defaultValue)
                                  throws DatabaseException
        Returns a context data integer of the given type and using the given default value if the value is not present
        Parameters:
        contextId - the context Id
        type - the data type required
        defaultValue - the default value to use if the type is not present
        Returns:
        the context data integer
        Throws:
        DatabaseException
        Since:
        2.10.0
      • setContextData

        public void setContextData​(int contextId,
                                   int type,
                                   java.util.List<java.lang.String> dataList)
                            throws DatabaseException
        Throws:
        DatabaseException
      • saveContext

        public void saveContext​(Context c)
      • saveAllContexts

        public void saveAllContexts()
      • getNewContext

        public Context getNewContext​(java.lang.String name)
        Gets a newly created context with the given name.

        The context is automatically added to the session.

        Parameters:
        name - the name of the context
        Returns:
        the new Context.
        Throws:
        IllegalContextNameException - (since 2.6.0) if the given name is null or empty or if a context with the given name already exists.
      • addContext

        public void addContext​(Context c)
        Adds the given context.
        Parameters:
        c - the context to be added
        Throws:
        java.lang.IllegalArgumentException - (since 2.6.0) if the given context is null.
        IllegalContextNameException - (since 2.6.0) if context's name is null or empty or if a context with the same name already exists.
      • deleteContext

        public void deleteContext​(Context c)
      • getContext

        public Context getContext​(int id)
      • getContext

        public Context getContext​(java.lang.String name)
      • getContexts

        public java.util.List<Context> getContexts()
      • getContextsForNode

        public java.util.List<Context> getContextsForNode​(SiteNode sn)
      • getContextsForUrl

        public java.util.List<Context> getContextsForUrl​(java.lang.String url)
      • exportContext

        public void exportContext​(int contextId,
                                  java.io.File file)
                           throws org.apache.commons.configuration.ConfigurationException
        Export the specified context to a file
        Parameters:
        contextId - the ID of the Context to be exported
        file - the File to which the Context should be exported
        Throws:
        org.apache.commons.configuration.ConfigurationException
      • exportContext

        public void exportContext​(Context c,
                                  java.io.File file)
                           throws org.apache.commons.configuration.ConfigurationException
        Export the specified context to a file
        Parameters:
        c -
        file -
        Throws:
        org.apache.commons.configuration.ConfigurationException
      • importContext

        public Context importContext​(java.io.File file)
                              throws org.apache.commons.configuration.ConfigurationException,
                                     java.lang.ClassNotFoundException,
                                     java.lang.InstantiationException,
                                     java.lang.IllegalAccessException,
                                     java.lang.IllegalArgumentException,
                                     java.lang.reflect.InvocationTargetException,
                                     java.lang.NoSuchMethodException,
                                     java.lang.SecurityException
        Imports a context from the specified (XML) file.
        Parameters:
        file - the (XML) file that contains the context data
        Returns:
        the imported Context, already added to the session.
        Throws:
        org.apache.commons.configuration.ConfigurationException
        java.lang.ClassNotFoundException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
        java.lang.reflect.InvocationTargetException
        java.lang.NoSuchMethodException
        java.lang.SecurityException
        IllegalContextNameException - (since 2.6.0) if context's name is not provided or it's empty or if a context with the same name already exists.
      • importContext

        public Context importContext​(ZapXmlConfiguration config)
                              throws org.apache.commons.configuration.ConfigurationException,
                                     java.lang.ClassNotFoundException,
                                     java.lang.InstantiationException,
                                     java.lang.IllegalAccessException,
                                     java.lang.IllegalArgumentException,
                                     java.lang.reflect.InvocationTargetException,
                                     java.lang.NoSuchMethodException,
                                     java.lang.SecurityException
        Imports a context from the specified XML config.
        Parameters:
        config - the XML config that contains the context data
        Returns:
        the imported Context, already added to the session.
        Throws:
        org.apache.commons.configuration.ConfigurationException
        java.lang.ClassNotFoundException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
        java.lang.reflect.InvocationTargetException
        java.lang.NoSuchMethodException
        java.lang.SecurityException
        IllegalContextNameException - if context's name is not provided or it's empty or if a context with the same name already exists.
        Since:
        2.13.0
      • getUrlParamParser

        public ParameterParser getUrlParamParser​(java.lang.String url)
        Returns the url parameter parser associated with the first context found that includes the URL, or the default parser if it is not in a context
        Parameters:
        url -
        Returns:
      • getFormParamParser

        public ParameterParser getFormParamParser​(java.lang.String url)
        Returns the form parameter parser associated with the first context found that includes the URL, or the default parser if it is not in a context
        Parameters:
        url -
        Returns:
      • getParams

        @Deprecated
        public java.util.Map<java.lang.String,​java.lang.String> getParams​(HttpMessage msg,
                                                                                HtmlParameter.Type type)
        Deprecated.
        2.10.0 use #getParameters(String) This method will lose duplicated parameter names
        Returns the specified parameters for the given message based on the parser associated with the first context found that includes the URL for the message, or the default parser if it is not in a context
        Parameters:
        msg -
        type -
        Returns:
      • getUrlParams

        @Deprecated
        public java.util.Map<java.lang.String,​java.lang.String> getUrlParams​(org.apache.commons.httpclient.URI uri)
                                                                            throws org.apache.commons.httpclient.URIException
        Deprecated.
        2.10.0 use #getUrlParameters(String)
        Returns the URL parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a context
        Parameters:
        uri -
        Returns:
        Throws:
        org.apache.commons.httpclient.URIException
      • getUrlParameters

        public java.util.List<NameValuePair> getUrlParameters​(org.apache.commons.httpclient.URI uri)
                                                       throws org.apache.commons.httpclient.URIException
        Returns the URL parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a context
        Parameters:
        uri -
        Returns:
        the URL parameters for the given URL
        Throws:
        org.apache.commons.httpclient.URIException
        Since:
        2.10.0
      • getFormParams

        @Deprecated
        public java.util.Map<java.lang.String,​java.lang.String> getFormParams​(org.apache.commons.httpclient.URI uri,
                                                                                    java.lang.String formData)
                                                                             throws org.apache.commons.httpclient.URIException
        Deprecated.
        2.10.0 use #getFormParameters(String)
        Returns the FORM parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a context
        Parameters:
        uri -
        formData -
        Returns:
        the FORM parameters for the given URL
        Throws:
        org.apache.commons.httpclient.URIException
      • getFormParameters

        public java.util.List<NameValuePair> getFormParameters​(org.apache.commons.httpclient.URI uri,
                                                               java.lang.String formData)
                                                        throws org.apache.commons.httpclient.URIException
        Returns the FORM parameters for the given URL based on the parser associated with the first context found that includes the URL, or the default parser if it is not in a context
        Parameters:
        uri -
        formData -
        Returns:
        the FORM parameters for the given URL
        Throws:
        org.apache.commons.httpclient.URIException
        Since:
        2.10.0
      • getTreePath

        @Deprecated
        public java.util.List<java.lang.String> getTreePath​(org.apache.commons.httpclient.URI uri)
                                                     throws org.apache.commons.httpclient.URIException
        Throws:
        org.apache.commons.httpclient.URIException