Class TomcatManager

  • All Implemented Interfaces:
    Loggable

    public class TomcatManager
    extends LoggedObject
    A Tomcat manager webapp invocation wrapper.
    • Constructor Summary

      Constructors 
      Constructor Description
      TomcatManager​(URL url)
      Creates a Tomcat manager wrapper for the specified URL that uses a username of admin, an empty password and ISO-8859-1 URL encoding.
      TomcatManager​(URL url, String username)
      Creates a Tomcat manager wrapper for the specified URL and username that uses an empty password and ISO-8859-1 URL encoding.
      TomcatManager​(URL url, String username, String password)
      Creates a Tomcat manager wrapper for the specified URL, username and password that uses ISO-8859-1 URL encoding.
      TomcatManager​(URL url, String username, String password, String charset)
      Creates a Tomcat manager wrapper for the specified URL, username, password and URL encoding.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void deploy​(String path, File war)
      Deploys the specified WAR as a HTTP PUT to the specified context path.
      void deploy​(String path, File war, boolean update)
      Deploys the specified WAR as a HTTP PUT to the specified context path, optionally undeploying the webapp if it already exists.
      void deploy​(String path, File war, boolean update, String tag)
      Deploys the specified WAR as a HTTP PUT to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
      void deploy​(String path, String version, File war, boolean update, String tag)
      Deploys the specified WAR as a HTTP PUT to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
      void deploy​(String path, URL war)
      Deploys the specified WAR as a URL to the specified context path.
      void deploy​(String path, URL war, boolean update)
      Deploys the specified WAR as a URL to the specified context path, optionally undeploying the webapp if it already exists.
      void deploy​(String path, URL war, boolean update, String tag)
      Deploys the specified WAR as a URL to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
      void deployContext​(String path, URL config)
      Deploys the specified context XML configuration to the specified context path.
      void deployContext​(String path, URL config, boolean update)
      Deploys the specified context XML configuration to the specified context path, optionally undeploying the webapp if it already exists.
      void deployContext​(String path, URL config, boolean update, String tag)
      Deploys the specified context XML configuration to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
      void deployContext​(String path, URL config, URL war)
      Deploys the specified context XML configuration and WAR as a URL to the specified context path.
      void deployContext​(String path, URL config, URL war, boolean update)
      Deploys the specified context XML configuration and WAR as a URL to the specified context path, optionally undeploying the webapp if it already exists.
      void deployContext​(String path, URL config, URL war, boolean update, String tag)
      Deploys the specified context XML configuration and WAR as a URL to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
      protected static String extractHeaderComponent​(String header, String component)
      Extract a component of a header.
      String getCharset()
      Gets the URL encoding charset to use when communicating with Tomcat manager.
      String getPassword()
      Gets the password to use when authenticating with Tomcat manager.
      TomcatDeployableStatus getStatus​(String path)
      Return the status of the webapp at the specified context path.
      URL getURL()
      Gets the full URL of the Tomcat manager instance.
      String getUserAgent()
      Gets the user agent name to use when communicating with Tomcat manager.
      String getUserName()
      Gets the username to use when authenticating with Tomcat manager.
      protected void invoke​(String path)
      Invokes Tomcat manager with the specified command.
      protected String invoke​(String path, File fileData, String digestData)
      Invokes Tomcat manager with the specified command and content data.
      String list()
      List currently deployed webapps.
      void reload​(String path)
      Reloads the webapp at the specified context path.
      void remove​(String path)
      Removes the webapp at the specified context path.
      void setTimeout​(int timeout)
      Operation timeout when communicating with Tomcat manager
      void setUserAgent​(String userAgent)
      Sets the user agent name to use when communicating with Tomcat manager.
      void start​(String path)
      Starts the webapp at the specified context path.
      void stop​(String path)
      Stops the webapp at the specified context path.
      void undeploy​(String path)
      Undeploys the webapp at the specified context path.
      void undeploy​(String path, String version)
      Undeploys the webapp at the specified context path.
    • Constructor Detail

      • TomcatManager

        public TomcatManager​(URL url)
        Creates a Tomcat manager wrapper for the specified URL that uses a username of admin, an empty password and ISO-8859-1 URL encoding.
        Parameters:
        url - the full URL of the Tomcat manager instance to use
      • TomcatManager

        public TomcatManager​(URL url,
                             String username)
        Creates a Tomcat manager wrapper for the specified URL and username that uses an empty password and ISO-8859-1 URL encoding.
        Parameters:
        url - the full URL of the Tomcat manager instance to use
        username - the username to use when authenticating with Tomcat manager
      • TomcatManager

        public TomcatManager​(URL url,
                             String username,
                             String password)
        Creates a Tomcat manager wrapper for the specified URL, username and password that uses ISO-8859-1 URL encoding.
        Parameters:
        url - the full URL of the Tomcat manager instance to use
        username - the username to use when authenticating with Tomcat manager
        password - the password to use when authenticating with Tomcat manager
      • TomcatManager

        public TomcatManager​(URL url,
                             String username,
                             String password,
                             String charset)
        Creates a Tomcat manager wrapper for the specified URL, username, password and URL encoding.
        Parameters:
        url - the full URL of the Tomcat manager instance to use
        username - the username to use when authenticating with Tomcat manager
        password - the password to use when authenticating with Tomcat manager
        charset - the URL encoding charset to use when communicating with Tomcat manager
    • Method Detail

      • getURL

        public URL getURL()
        Gets the full URL of the Tomcat manager instance.
        Returns:
        the full URL of the Tomcat manager instance
      • getUserName

        public String getUserName()
        Gets the username to use when authenticating with Tomcat manager.
        Returns:
        the username to use when authenticating with Tomcat manager
      • getPassword

        public String getPassword()
        Gets the password to use when authenticating with Tomcat manager.
        Returns:
        the password to use when authenticating with Tomcat manager
      • getCharset

        public String getCharset()
        Gets the URL encoding charset to use when communicating with Tomcat manager.
        Returns:
        the URL encoding charset to use when communicating with Tomcat manager
      • getUserAgent

        public String getUserAgent()
        Gets the user agent name to use when communicating with Tomcat manager.
        Returns:
        the user agent name to use when communicating with Tomcat manager
      • setUserAgent

        public void setUserAgent​(String userAgent)
        Sets the user agent name to use when communicating with Tomcat manager.
        Parameters:
        userAgent - the user agent name to use when communicating with Tomcat manager
      • deploy

        public void deploy​(String path,
                           URL war,
                           boolean update)
                    throws TomcatManagerException,
                           IOException
        Deploys the specified WAR as a URL to the specified context path, optionally undeploying the webapp if it already exists.
        Parameters:
        path - the webapp context path to deploy to
        war - the URL of the WAR to deploy
        update - whether to first undeploy the webapp if it already exists
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deploy

        public void deploy​(String path,
                           URL war,
                           boolean update,
                           String tag)
                    throws TomcatManagerException,
                           IOException
        Deploys the specified WAR as a URL to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
        Parameters:
        path - the webapp context path to deploy to
        war - the URL of the WAR to deploy
        update - whether to first undeploy the webapp if it already exists
        tag - the tag name to use
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deploy

        public void deploy​(String path,
                           File war,
                           boolean update)
                    throws TomcatManagerException,
                           IOException
        Deploys the specified WAR as a HTTP PUT to the specified context path, optionally undeploying the webapp if it already exists.
        Parameters:
        path - the webapp context path to deploy to
        war - the WAR file to deploy
        update - whether to first undeploy the webapp if it already exists
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deploy

        public void deploy​(String path,
                           File war,
                           boolean update,
                           String tag)
                    throws TomcatManagerException,
                           IOException
        Deploys the specified WAR as a HTTP PUT to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
        Parameters:
        path - the webapp context path to deploy to
        war - the WAR file to deploy
        update - whether to first undeploy the webapp if it already exists
        tag - the tag name to use
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deploy

        public void deploy​(String path,
                           String version,
                           File war,
                           boolean update,
                           String tag)
                    throws TomcatManagerException,
                           IOException
        Deploys the specified WAR as a HTTP PUT to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
        Parameters:
        path - the webapp context path to deploy to
        version - the webapp version
        war - the WAR file to deploy
        update - whether to first undeploy the webapp if it already exists
        tag - the tag name to use
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deployContext

        public void deployContext​(String path,
                                  URL config)
                           throws TomcatManagerException,
                                  IOException
        Deploys the specified context XML configuration to the specified context path.
        Parameters:
        path - the webapp context path to deploy to
        config - the URL of the context XML configuration to deploy
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deployContext

        public void deployContext​(String path,
                                  URL config,
                                  boolean update)
                           throws TomcatManagerException,
                                  IOException
        Deploys the specified context XML configuration to the specified context path, optionally undeploying the webapp if it already exists.
        Parameters:
        path - the webapp context path to deploy to
        config - the URL of the context XML configuration to deploy
        update - whether to first undeploy the webapp if it already exists
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deployContext

        public void deployContext​(String path,
                                  URL config,
                                  boolean update,
                                  String tag)
                           throws TomcatManagerException,
                                  IOException
        Deploys the specified context XML configuration to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
        Parameters:
        path - the webapp context path to deploy to
        config - the URL of the context XML configuration to deploy
        update - whether to first undeploy the webapp if it already exists
        tag - the tag name to use
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deployContext

        public void deployContext​(String path,
                                  URL config,
                                  URL war)
                           throws TomcatManagerException,
                                  IOException
        Deploys the specified context XML configuration and WAR as a URL to the specified context path.
        Parameters:
        path - the webapp context path to deploy to
        config - the URL of the context XML configuration to deploy
        war - the URL of the WAR to deploy
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deployContext

        public void deployContext​(String path,
                                  URL config,
                                  URL war,
                                  boolean update)
                           throws TomcatManagerException,
                                  IOException
        Deploys the specified context XML configuration and WAR as a URL to the specified context path, optionally undeploying the webapp if it already exists.
        Parameters:
        path - the webapp context path to deploy to
        config - the URL of the context XML configuration to deploy
        war - the URL of the WAR to deploy
        update - whether to first undeploy the webapp if it already exists
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • deployContext

        public void deployContext​(String path,
                                  URL config,
                                  URL war,
                                  boolean update,
                                  String tag)
                           throws TomcatManagerException,
                                  IOException
        Deploys the specified context XML configuration and WAR as a URL to the specified context path, optionally undeploying the webapp if it already exists and using the specified tag name.
        Parameters:
        path - the webapp context path to deploy to
        config - the URL of the context XML configuration to deploy
        war - the URL of the WAR to deploy
        update - whether to first undeploy the webapp if it already exists
        tag - the tag name to use
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • invoke

        protected String invoke​(String path,
                                File fileData,
                                String digestData)
                         throws TomcatManagerException,
                                IOException
        Invokes Tomcat manager with the specified command and content data.
        Parameters:
        path - the Tomcat manager command to invoke
        fileData - the file to stream as content data, if needed
        digestData - HTTP Digest authentication data, if available
        Returns:
        the result of the invoking command, as returned by the Tomcat Manager application
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if an i/o error occurs
      • extractHeaderComponent

        protected static String extractHeaderComponent​(String header,
                                                       String component)
        Extract a component of a header.
        Parameters:
        header - header to extract from
        component - component to extract
        Returns:
        Extracted component, null if component doesn't exist in header
      • setTimeout

        public void setTimeout​(int timeout)
        Operation timeout when communicating with Tomcat manager
        Parameters:
        timeout - in milliseconds; max is Integer.MAX_VALUE