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, String username, String password)
      Creates a Tomcat manager wrapper for the specified URL, username and password that uses UTF-8 URL encoding.
      TomcatManager​(URL url, String username, String password, Charset charset)
      Creates a Tomcat manager wrapper for the specified URL, username, password and URL encoding.
    • Method Summary

      All 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.
      Charset 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.
      TomcatDeployableStatus getStatus​(String path, String version)
      Return the status of the webapp at the specified context path and version.
      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)
      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,
                             String username,
                             String password)
        Creates a Tomcat manager wrapper for the specified URL, username and password that uses UTF-8 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,
                             Charset 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 Charset 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • 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 connecting to the server fails
      • undeploy

        public void undeploy​(String path,
                             String version)
                      throws TomcatManagerException,
                             IOException
        Undeploys the webapp at the specified context path.
        Parameters:
        path - the webapp context path to undeploy
        version - the version of the webapp context path to undeploy
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if connecting to the server fails
      • invoke

        protected String invoke​(String path,
                                File fileData)
                         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
        Returns:
        the result of the invoking command, as returned by the Tomcat Manager application
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if connecting to the server fails
      • getStatus

        public TomcatDeployableStatus getStatus​(String path,
                                                String version)
                                         throws IOException,
                                                TomcatManagerException
        Return the status of the webapp at the specified context path and version.
        Parameters:
        path - the webapp context path to get status
        version - the version of the webapp context path to get status
        Returns:
        the current status of the webapp in the running container
        Throws:
        TomcatManagerException - if the Tomcat manager request fails
        IOException - if connecting to the server fails
      • setTimeout

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