Search code examples
c#.nettomcatwsdl

Programmatically start/stop tomcat webapps from c# code


I was recently searching how to remotely start/stop a webapp running under Tomcat - the requirement was because I was writing test code that needed to control the availability of a WSDL type service running on a remote Tomcat server. However the request always returns a 403 error.

string credentialsStr = "tomcatusr" + ":" + "tomcatpwd";
WebRequest request = WebRequest.Create("http://" + hostNameStr + "/manager/start?path=/" + Uri.EscapeDataString(appNameStr));
request.Method = "GET";
request.PreAuthenticate = true;
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(credentialsStr));
WebResponse response = request.GetResponse();

Solution

  • My snippet above seems to work as long as the tomcat user credendials have the manager-script role assigned (i.e. in conf/tomcat-users.xml on remote host).