3 Replies Latest reply on Dec 19, 2012 7:07 AM by iabughosh

    Stop JSF application in tomcat using Java code?

    Eswara MoorthyNEC Newbie



           I developed JSF & richfaces application. And i deployed my war into tomcat 6.0.29.


      When i use hit this url in browser 'http://localhost:8080/manager/html/stop?path=/jsfproject'. Then this application stopped.


      I need to stop the application by programatic.


      Help me.

      Thanks in advance

        • 1. Re: Stop JSF application in tomcat using Java code?
          iabughosh Master

          Hello Eswara,

          you can use http client to access urls programmitcally.



          • 2. Re: Stop JSF application in tomcat using Java code?
            Eswara MoorthyNEC Newbie

            Thanks for your support. But its not working


            My tomcat-users.xml file



                    <role rolename="manager"/>
                    <user username="tomcat" password="s3cret" roles="manager" />


            My code is :


            import org.apache.commons.httpclient.*;
            import org.apache.commons.httpclient.methods.*;
            import org.apache.commons.httpclient.params.HttpMethodParams;
            import java.io.*;
            public class HttpClientTutorial
                private static String url = "http://localhost:8080/manager/html/stop?path=/jsfproject";
                public static void main(String[] args)
                    // Create an instance of HttpClient.
                    HttpClient client = new HttpClient();
                    // Create a method instance.
                    GetMethod method = new GetMethod(url);
                    // Provide custom retry handler is necessary
                            new DefaultHttpMethodRetryHandler(3, false));
                        // Execute the method.
                        int statusCode = client.executeMethod(method);
                        if (statusCode != HttpStatus.SC_OK)
                            System.err.println("Method failed: " + method.getStatusLine());
                        // Read the response body.
                        byte[] responseBody = method.getResponseBody();
                        // Deal with the response.
                        // Use caution: ensure correct character encoding and is not binary data
                        System.out.println(new String(responseBody));
                    catch (HttpException e)
                        System.err.println("Fatal protocol violation: " + e.getMessage());
                    catch (IOException e)
                        System.err.println("Fatal transport error: " + e.getMessage());
                        // Release the connection.


            But not stopped application. I got the follwing message in my console



            log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.HttpClient).
            log4j:WARN Please initialize the log4j system properly.
            Method failed: HTTP/1.1 401 Unauthorized

              <title>401 Unauthorized</title>
                BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;font-size:12px;}
                H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
                PRE, TT {border: 1px dotted #525D76}
                A {color : black;}A.name {color : black;}
               <h1>401 Unauthorized</h1>
                You are not authorized to view this page. If you have not changed
                any configuration files, please examine the file
                <tt>conf/tomcat-users.xml</tt> in your installation. That
                file will contain the credentials to let you use this webapp.
                You will need to add <tt>manager</tt> role to the config file listed above.
                For example:
            &lt;role rolename="manager"/&gt;
            &lt;user username="tomcat" password="s3cret" roles="manager"/&gt;
                For more information - please see the
                <a href="/docs/manager-howto.html">Manager App HOW-TO</a>.


            Help me.

            Thanks in advance

            • 3. Re: Stop JSF application in tomcat using Java code?
              iabughosh Master

              it seems that tomcat container itself doesn't allow external application to perform stop/undeploy operations.