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?
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?
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?
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?
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
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.
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.
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.