aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Making runtime configuration changes using mbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Making runtime configuration changes using mbeans" Watch "Making runtime configuration changes using mbeans" New topic
Author

Making runtime configuration changes using mbeans

Nikita Manohar
Greenhorn

Joined: Jan 06, 2010
Posts: 8
Hello,

We are working on a project and need to run Mbeans with tomcat. what we want to do is actually make config changes in web.xml at runtime using mbeans. Is it possible to do so? could anyone give an idea?

Thank you
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Nikita,

I'm actually not sure if you can use the web.xml descriptor at runtime. Of course you can edit the file but I think even if a servlet container recognizes the changes it wouldn't be possible to deal with all changes without restarting the whole application.

The question is why would you want to externalize your application configuration with MBeans (which is a good idea, I think) and then use the indirection with the web.xml descriptor to change your application configuration? Why not just implement a solid configuration mechanism and make it accessible via MBeans? What exactly do you want to change in the web.xml descriptor?

Marco
Nikita Manohar
Greenhorn

Joined: Jan 06, 2010
Posts: 8
Hi..

Actually we need to toggle our entire web application from http to https dynamically. So we were thinking if we could make modifications to web.xml in the security constraint and we wanted to access the web.xml using mbeans. Do you think this is possible?

Thanks
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi,

without knowing more details this doesn't sound like a very good idea to me to use MBeans to toggle such essential security features.

You have to configure Tomcat before running your app anyway to provide support for HTTP and HTTPS. Why can't you use the static security options in web.xml? Or use the usual web mechanisms like a redirect to forward a client to a HTTPS url?

Marco
Nikita Manohar
Greenhorn

Joined: Jan 06, 2010
Posts: 8
Hi,

We would like to know what do you exactly mean by "Why not just implement a solid configuration mechanism and make it accessible via MBeans?"
Please elaborate.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Nikita,

from what you've described so far I'm not exactly sure what you are really trying to achieve. So I can only make a few assumptions. Perhaps you could elaborate a bit on the requirements in more detail.

My advice regarding the "configuration mechanism" was just an idea to externalize configuration parameters. But as you pointed out you're trying to use MBeans to switch between the HTTP and HTTPS protocols. And that's still the point which is unclear to me.

Please provide us some more details about the real requirements (if possible) and what you have to achieve and why you think MBeans are good way to achieve this goal. This makes it easier to give you useful advices

Marco
Nikita Manohar
Greenhorn

Joined: Jan 06, 2010
Posts: 8
Hi Marco,

We have a web application coded in Java and deployed on Tomcat. Right now by making changes in the web.xml, the entire web app runs on HTTPS. Now we need to give the user an option of toggling the entire web app to http and vice-versa.

So now we need to access Tomcat through our code and make changes to toggle between http/https. We need to access the http-connector (in web.xml) through mbean that will allow to enable and disable the connector at runtime.

Could you please help us. We're at our wits end.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Nikita,

as to my knowledge there's no way to turn on and off Tomcat connectors at runtime. Which usually makes perfect sense, because you don't have to use a specific connector just because it is there. If Tomcat is running with HTTP and HTTPS support you are still free to use either one in a web application as long as you don't force SSL support by activating it in the web.xml descriptor.

So from this point of view there's no need to activate or deactivate Tomcat connectors. What you really need is a way to allow end users to toggle between HTTP and HTTPS, right?

Why don't you just include a link or button or something like this into the web interface which could then call a Servlet to determine if the application is currently running with HTTP or HTTPS and redirect the user to the same URL but with the opposite protocol if he/she clicks on the link? This sounds much easier to me than messing around with Tomcat internals and connectors.

What do you think about this idea?

Marco
Nikita Manohar
Greenhorn

Joined: Jan 06, 2010
Posts: 8
Hi,

Using java code, we are able to use the "removeConnector" method. We can successfully remove/disable the http or https connector. Now we want to enable it. However, we are not able to figure out how to use createConnector method.

private String createConnector(String parent, String address, int port,boolean isAjp,boolean isSSL) throws Exception

What do we pass as the parent here? We are passing the address as localhost and port as 8080. I hope atleast these two parameters are correct?

Thanks,

nikita
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making runtime configuration changes using mbeans