You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Eric Herman <er...@mysql.com> on 2004/08/10 03:16:32 UTC
How to deploy a custom DynamicMBean
I'm looking for help from someone with some experience deploying
DynamicMBeans to Tomcat.
In short, my questions boil down to some very basic information gaps:
once we have a DynamicMBean,
(1) What do we need to add to the server.xml file?
(2) What other configuration file(s) need to be created/edited?
(3) What are the contents of those files?
Please feel free to tell me to "Read The Fine Manual" ... but I've had
some trouble locating meaningful docs. If the answers I seek are
documented somewhere, a pointer to those docs would be greatly
appreciated. Otherwise, I would be happy to put something together,
maybe a small how-to, once I have things working. I think a step-by-step
set of instructions around a concrete (if very simple) example would be
useful to others trying to do similar things.
Let me share what I've learned so far:
According to the "MBean Descriptor How To"
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/mbeans-descriptor-howto.html
Once we have an MBean, it looks like we need to create a
mbean-descriptor.xml and add it to the list of "descriptors" in the
ServerLifecycleListener tag. Something like:
<Listener
className="org.apache.catalina.mbeans.ServerLifecycleListener"
descriptors="/scratch/mbean-descriptor.xml"
debug="0"/>
I have tried this and get a very curious error:
org.xml.sax.SAXParseException: The processing instruction target
matching "[xX][mM][lL]" is not allowed.
Should it be the "GlobalResourcesLifecycleListener" tag? Using that
seems to avoid the stack-trace, but then it doesn't look like the custom
DynamicMBean is being instantiated, so if this is correct, there's
something else missing.
I found one reference to someone else having similar confusion but was
not able to use the information to good advantage:
http://www.junlu.com/msg/93635.html
I didn't see a description the "Engine" tag suggested in this thread.
Assuming we are supposed to create "mbean-descriptor.xml" files (and the
SAXParseException can be over-come) ... are these files usually packaged
up in the jar file (with the MBean class files) deployed to server/lib?
That's where I've put it, for the moment, but I am not sure this is a
good practice. It doesn't seem right to package JMX Agent specific files
inside the jar; a different file is needed with JBoss, for instance.
I have not seen a good example of what this descriptor file is expected
to contain, especially for DynamicMBean where the attributes my not be
known at deployment time. If you know of an example, please post the
url.
Next the Descriptor How To suggests that "You may also add MBean
descriptions for custom components in
org.apache.catalina.mbeans.mbeans-descriptor.xml file." After some
searching, I think this file is normally only contained in the
catalina.jar file in the server/lib directory. This feels like messing
with the Tomcat internals. Ideally, I wouldn't want our new MBeans
exposed as part of Tomcat itself. So, I don't understand when or why we
should modify that file.
To provide an DynamicMBean deployment example, I've attached a simple
"LightBulb" class to be managed, as well as a very naive DynamicMBean to
manage it. If we really had an application this simple, we probably
wouldn't be using a DynamicMBean, but I've tried to create something
simple enough to let us focus on the deployment issues.
Any input (kind or cruel) is welcome.
Cheers,
-- Eric
--
Eric Herman, Software Developer
MySQL AB, www.mysql.com
Office: +1 206 720 1724
Are you MySQL certified? www.mysql.com/certification
Re: How to deploy a custom DynamicMBean
Posted by Eric Herman <er...@mysql.com>.
Bill-
Thanks for the quick response. So the code which you supply allows us to
find a reference to the MBeanServer and instantiate our MBean inside
that server. But I'm a little surprised to find this driven by Java
code; I had really expected this to be done with configuration files.
However, my first thought as to how to apply this would be to create a
very tiny servlet which would be loaded by Tomcat upon startup. This
servlet could run the MBean creation code during it's initialization.
Do you have another thought as to how to apply this?
-- Eric
On Mon, 2004-08-09 at 23:10, Bill Barker wrote:
> The docs you've described are mostly for if you want custom Tomcat
> components (such as Valves or Realms). You'd want something basic like:
> MBeanServer mserver =
> (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
> ObjectName loader = new
> ObjectName("Catalina:type=WebappClassLoader,path=/myapp,host=localhost");
> ObjectName mylight = new ObjectName("MyApp:type=lightbulb");
> mserver.createMBean("scratch.LightBulbDynamicMBean", mylight, loader);
>
> Of course, you have to change the host and path to match your app, and the
> domain of the loader to match the Engine name if you've changed it from its
> default value.
>
> "Eric Herman" <er...@mysql.com> wrote in message
> news:1092100592.4890.268.camel@localhost...
> > I'm looking for help from someone with some experience deploying
> > DynamicMBeans to Tomcat.
> >
> > In short, my questions boil down to some very basic information gaps:
> > once we have a DynamicMBean,
> > (1) What do we need to add to the server.xml file?
> > (2) What other configuration file(s) need to be created/edited?
> > (3) What are the contents of those files?
[snip]
--
Eric Herman, Software Developer
MySQL AB, www.mysql.com
Office: +1 206 720 1724
Are you MySQL certified? www.mysql.com/certification
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: How to deploy a custom DynamicMBean
Posted by Bill Barker <wb...@wilshire.com>.
The docs you've described are mostly for if you want custom Tomcat
components (such as Valves or Realms). You'd want something basic like:
MBeanServer mserver =
(MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName loader = new
ObjectName("Catalina:type=WebappClassLoader,path=/myapp,host=localhost");
ObjectName mylight = new ObjectName("MyApp:type=lightbulb");
mserver.createMBean("scratch.LightBulbDynamicMBean", mylight, loader);
Of course, you have to change the host and path to match your app, and the
domain of the loader to match the Engine name if you've changed it from its
default value.
"Eric Herman" <er...@mysql.com> wrote in message
news:1092100592.4890.268.camel@localhost...
> I'm looking for help from someone with some experience deploying
> DynamicMBeans to Tomcat.
>
> In short, my questions boil down to some very basic information gaps:
> once we have a DynamicMBean,
> (1) What do we need to add to the server.xml file?
> (2) What other configuration file(s) need to be created/edited?
> (3) What are the contents of those files?
>
>
> Please feel free to tell me to "Read The Fine Manual" ... but I've had
> some trouble locating meaningful docs. If the answers I seek are
> documented somewhere, a pointer to those docs would be greatly
> appreciated. Otherwise, I would be happy to put something together,
> maybe a small how-to, once I have things working. I think a step-by-step
> set of instructions around a concrete (if very simple) example would be
> useful to others trying to do similar things.
>
>
> Let me share what I've learned so far:
>
> According to the "MBean Descriptor How To"
>
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/mbeans-descriptor-howto.html
>
> Once we have an MBean, it looks like we need to create a
> mbean-descriptor.xml and add it to the list of "descriptors" in the
> ServerLifecycleListener tag. Something like:
>
> <Listener
> className="org.apache.catalina.mbeans.ServerLifecycleListener"
> descriptors="/scratch/mbean-descriptor.xml"
> debug="0"/>
>
>
> I have tried this and get a very curious error:
> org.xml.sax.SAXParseException: The processing instruction target
> matching "[xX][mM][lL]" is not allowed.
>
> Should it be the "GlobalResourcesLifecycleListener" tag? Using that
> seems to avoid the stack-trace, but then it doesn't look like the custom
> DynamicMBean is being instantiated, so if this is correct, there's
> something else missing.
>
> I found one reference to someone else having similar confusion but was
> not able to use the information to good advantage:
>
> http://www.junlu.com/msg/93635.html
>
> I didn't see a description the "Engine" tag suggested in this thread.
>
>
> Assuming we are supposed to create "mbean-descriptor.xml" files (and the
> SAXParseException can be over-come) ... are these files usually packaged
> up in the jar file (with the MBean class files) deployed to server/lib?
> That's where I've put it, for the moment, but I am not sure this is a
> good practice. It doesn't seem right to package JMX Agent specific files
> inside the jar; a different file is needed with JBoss, for instance.
>
> I have not seen a good example of what this descriptor file is expected
> to contain, especially for DynamicMBean where the attributes my not be
> known at deployment time. If you know of an example, please post the
> url.
>
> Next the Descriptor How To suggests that "You may also add MBean
> descriptions for custom components in
> org.apache.catalina.mbeans.mbeans-descriptor.xml file." After some
> searching, I think this file is normally only contained in the
> catalina.jar file in the server/lib directory. This feels like messing
> with the Tomcat internals. Ideally, I wouldn't want our new MBeans
> exposed as part of Tomcat itself. So, I don't understand when or why we
> should modify that file.
>
> To provide an DynamicMBean deployment example, I've attached a simple
> "LightBulb" class to be managed, as well as a very naive DynamicMBean to
> manage it. If we really had an application this simple, we probably
> wouldn't be using a DynamicMBean, but I've tried to create something
> simple enough to let us focus on the deployment issues.
>
>
> Any input (kind or cruel) is welcome.
>
> Cheers,
> -- Eric
>
> --
> Eric Herman, Software Developer
> MySQL AB, www.mysql.com
> Office: +1 206 720 1724
>
> Are you MySQL certified? www.mysql.com/certification
>
>
----------------------------------------------------------------------------
----
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: How to get the context path for a web application?
Posted by Keith Bottner <kb...@comcast.net>.
Have you tried ?
request.getServletPath();
Keith
-----Original Message-----
From: Dov Rosenberg [mailto:dov.rosenberg@conviveon.com]
Sent: Monday, August 09, 2004 9:49 PM
To: Tomcat Users List
Subject: How to get the context path for a web application?
I need to find a way to get the context path of the current web application.
I would like to to it using the HttpSession, HttpServletRequest or response.
I tried the ServletContext.getServletContextName but it returns null in
Tomcat. Is there a cross container solution?
--
Dov Rosenberg
Conviveon Corporation
http://www.conviveon.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
How to get the context path for a web application?
Posted by Dov Rosenberg <do...@conviveon.com>.
I need to find a way to get the context path of the current web application.
I would like to to it using the HttpSession, HttpServletRequest or response.
I tried the ServletContext.getServletContextName but it returns null in
Tomcat. Is there a cross container solution?
--
Dov Rosenberg
Conviveon Corporation
http://www.conviveon.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org