Class TomcatManager
- java.lang.Object
-
- org.codehaus.cargo.util.log.LoggedObject
-
- org.codehaus.cargo.container.tomcat.internal.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 managervoid
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.-
Methods inherited from class org.codehaus.cargo.util.log.LoggedObject
getLogger, setLogger
-
-
-
-
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 useusername
- the username to use when authenticating with Tomcat managerpassword
- 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 useusername
- the username to use when authenticating with Tomcat managerpassword
- the password to use when authenticating with Tomcat managercharset
- 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) throws TomcatManagerException, IOException
Deploys the specified WAR as a URL to the specified context path.- Parameters:
path
- the webapp context path to deploy towar
- the URL of the WAR to deploy- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
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 towar
- the URL of the WAR to deployupdate
- whether to first undeploy the webapp if it already exists- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 towar
- the URL of the WAR to deployupdate
- whether to first undeploy the webapp if it already existstag
- the tag name to use- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
deploy
public void deploy(String path, File war) throws TomcatManagerException, IOException
Deploys the specified WAR as a HTTP PUT to the specified context path.- Parameters:
path
- the webapp context path to deploy towar
- the WAR file to deploy- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 towar
- the WAR file to deployupdate
- whether to first undeploy the webapp if it already exists- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 towar
- the WAR file to deployupdate
- whether to first undeploy the webapp if it already existstag
- the tag name to use- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 toversion
- the webapp versionwar
- the WAR file to deployupdate
- whether to first undeploy the webapp if it already existstag
- the tag name to use- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 toconfig
- the URL of the context XML configuration to deploy- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 toconfig
- the URL of the context XML configuration to deployupdate
- whether to first undeploy the webapp if it already exists- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 toconfig
- the URL of the context XML configuration to deployupdate
- whether to first undeploy the webapp if it already existstag
- the tag name to use- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 toconfig
- the URL of the context XML configuration to deploywar
- the URL of the WAR to deploy- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 toconfig
- the URL of the context XML configuration to deploywar
- the URL of the WAR to deployupdate
- whether to first undeploy the webapp if it already exists- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 toconfig
- the URL of the context XML configuration to deploywar
- the URL of the WAR to deployupdate
- whether to first undeploy the webapp if it already existstag
- the tag name to use- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
undeploy
public void undeploy(String path) throws TomcatManagerException, IOException
Undeploys the webapp at the specified context path.- Parameters:
path
- the webapp context path to undeploy- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 undeployversion
- the version of the webapp context path to undeploy- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
remove
public void remove(String path) throws TomcatManagerException, IOException
Removes the webapp at the specified context path.- Parameters:
path
- the webapp context path to remove- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
reload
public void reload(String path) throws TomcatManagerException, IOException
Reloads the webapp at the specified context path.- Parameters:
path
- the webapp context path to reload- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
start
public void start(String path) throws TomcatManagerException, IOException
Starts the webapp at the specified context path.- Parameters:
path
- the webapp context path to start- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
stop
public void stop(String path) throws TomcatManagerException, IOException
Stops the webapp at the specified context path.- Parameters:
path
- the webapp context path to stop- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
invoke
protected void invoke(String path) throws TomcatManagerException, IOException
Invokes Tomcat manager with the specified command.- Parameters:
path
- the Tomcat manager command to invoke- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- 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 invokefileData
- 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 failsIOException
- if connecting to the server fails
-
list
public String list() throws IOException, TomcatManagerException
List currently deployed webapps.- Returns:
- a string representing the result of invoked command
- Throws:
TomcatManagerException
- if the Tomcat manager request failsIOException
- if connecting to the server fails
-
getStatus
public TomcatDeployableStatus getStatus(String path) throws IOException, TomcatManagerException
Return the status of the webapp at the specified context path.- Parameters:
path
- 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 failsIOException
- 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 statusversion
- 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 failsIOException
- 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
-
-