• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to stop and start existing application in tomcat

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I developed simple application "myproject" and deployed in tomcat-6.0.29.

Application stopped when i execute this "http://localhost:8080/manager/stop?path=/myproject".

Is possible to stop this application using java program?

Is possible to start this application using java program?

Help me.
Thanks in advane
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jack,

Try this

Process p = r.exec("wget http://tomcatusername:tomcatepassword@localhost:8080/manager/" + action + "?path=/myproject -O - -q");

 
Robert Jack
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi eswar. Thanks for your support.

I check your code. It works fine in Linux Ubuntu. Windows not support
I got error when execute in windows

Error is:



Anyone help me.
 
Saloon Keeper
Posts: 28492
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the reasons why Linux is so much better for software development than Windows is that Linux comes with an immense number of developer utility programs. Windows does not.

You have 2 choices.

1. You can download and install Cygwin, which allows you to run Linux programs under Windows

2. You can google around and find and install a Windows native "wget" program from some third party.

For a single need, I recommend answer #2, since Cywin is practically an OS in its own right, but either solution will work.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whats wrong with using java.net.HttpURLConnection and the rest of the standard library to do a GET request and read the response?

Why would you need to create a Process?

Bill
 
Tim Holloway
Saloon Keeper
Posts: 28492
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, now that I look at the original question, yes, there are several ways in Java to start/stop apps in Java code.

I believe JSR-77 specifies one of them. JMX provides another, I think. Neither requires the existence of an external program such as wget.
 
Robert Jack
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Actually, now that I look at the original question, yes, there are several ways in Java to start/stop apps in Java code.

I believe JSR-77 specifies one of them. JMX provides another, I think. Neither requires the existence of an external program such as wget.



Hi Tim Holloway,
Thanks for your response.
But i can't get your idea.

Can you give me some more idea about your answer or reference,
regarding start/stop an existing application in tomcat using java code.


Help me.
Thanks in advance.
 
Robert Jack
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:Whats wrong with using java.net.HttpURLConnection and the rest of the standard library to do a GET request and read the response?

Why would you need to create a Process?

Bill



Hi William Brogden, Thanks for your effort
I got exception when i use HttpURLConnection. I don't know, where i made mistake?
Error is
IOException: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/html/stop?path=/myproject
My code is:




Help me.
Thanks in advance
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
401 = UNAUTHORIZED - the management app is protected, you need a user in the "managememt" role in order to run the manager app.

Bill
 
Robert Jack
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:401 = UNAUTHORIZED - the management app is protected, you need a user in the "managememt" role in order to run the manager app.

Bill


Thanks for your support.

How i configure the 'user' in the management role in order to run the manage application?

Help me
Thanks in advance.
 
Robert Jack
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I check My tomcat-user.xml file. But its not working

I need to add any role in my tomcat-user.xml file.

 
Tim Holloway
Saloon Keeper
Posts: 28492
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There should be model role definitions in the originally-supplied tomcat-users.xml file that will suffice. Although as shipped they may be commented out.

When a server returns a 401 response, the client must log in. That means that a request containing the encoded userid and password must be sent to Tomcat to be validated. Once your client app has logged in, then you can send Tomcat admin URLs.

And, no, I don't have any code like that lying around. I'd have to do the same thing I recommend that you do: Google. Useful magic words include "RFC" and "Basic Authentication", since the definitive documentation for handling a 401 (Basic Authentication) request is one of the Internet RFC documents, which will typically include simple examples of how things are done. If your client app hasn't disabled cookies, a successful login request will return a cookie which will be used to maintain the session context for future requests. And, if you're using the HttpURLConnection, cookie handling is completely automatic, so you don't need to code anything for it.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that you have to restart Tomcat if you change the users xml file.

Test by using the html interface with a browser - http://yoursite/manager/html/list - you should get a security dialog to enter name and password.

If that works then http://username:userpw@yoursite/manager.... etc should work as the url to GET

Bill
 
Tim Holloway
Saloon Keeper
Posts: 28492
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:Note that you have to restart Tomcat if you change the users xml file.



That was true with the original MemoryRealm. I think its newer derivatives are smarter about that. Can't hurt, though.


If that works then http://username:userpw@yoursite/manager.... etc should work as the url to GET



Or better, use the https protocol. The http protocol is vulnerable to wire sniffing. Even if only intranet clients control Tomcat this way. it's good practice.
 
Robert Jack
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not working.
My "tomcat-users.xml" file content

I deploy my web application in my local system. application name is "jsfproject"
Then my java code like this

Eventhough i got message "Method failed: HTTP/1.1 401 Unauthorized". I don't know whats wrong my code


Step 1 : I create simple JSF project. and deployed in tomcat. project name "jsfproject"

Step 2 : I create another one JSF application "Demo Project"

Stpe 3 : This "Demo Project" have only one "test.jsp" page. I create only one button "Stop JSF project" in that test.jsp page

Stpe 4 :

Step 5 :

I got the following message when i click "stop JSF project" button

Going to stop the application......
Method failed: HTTP/1.1 401 Unauthorized



Help me,
Thanks for valuable effort


reply
    Bookmark Topic Watch Topic
  • New Topic