Announcement Announcement Module
Collapse
No announcement yet.
Controlling log4j using Spring JMX and jmanage Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controlling log4j using Spring JMX and jmanage

    I am trying to implement the jmx log4j control defined http://forum.springframework.org/showthread.php?t=18729 using jManage as a front end. I am also using weblogic 8.1 as my mbean server. JManage sees my log4j mbean but when I attempt to invoke the setLogger method through jManage, I get the following exception in the jManage log.

    SEVERE: Error executing operation setLogger on log4j:name=settings
    java.lang.RuntimeException: javax.management.ReflectionException: The target object class class javax.management.modelmb
    ean.ModelMBeanOperationInfo could not be found
    at org.jmanage.core.modules.weblogic.WLServerConnecti on.invoke(WLServerConnection.java:73)
    at org.jmanage.core.management.ServerConnectionProxy. invoke(ServerConnectionProxy.java:93)
    at org.jmanage.core.services.MBeanServiceImpl.execute MBeanOperation(MBeanServiceImpl.java:238)
    at org.jmanage.core.services.MBeanServiceImpl.invoke( MBeanServiceImpl.java:216)
    at org.jmanage.webui.actions.app.ExecuteMBeanOperatio nAction.execute(ExecuteMBeanOperationAction.java:6 7)
    at org.jmanage.webui.actions.BaseAction.execute(BaseA ction.java:41)
    at org.jmanage.webui.JManageRequestProcessor.processA ctionPerform(JManageRequestProcessor.java:93)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1420)
    at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:520)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
    at org.mortbay.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:358)
    at org.mortbay.jetty.servlet.WebApplicationHandler.di spatch(WebApplicationHandler.java:294)
    at org.mortbay.jetty.servlet.ServletHandler.handle(Se rvletHandler.java:567)
    at org.mortbay.http.HttpContext.handle(HttpContext.ja va:1807)
    at org.mortbay.jetty.servlet.WebApplicationContext.ha ndle(WebApplicationContext.java:525)
    at org.mortbay.http.HttpContext.handle(HttpContext.ja va:1757)
    at org.mortbay.http.HttpServer.service(HttpServer.jav a:879)
    at org.mortbay.http.HttpConnection.service(HttpConnec tion.java:790)
    at org.mortbay.http.HttpConnection.handleNext(HttpCon nection.java:961)
    at org.mortbay.http.HttpConnection.handle(HttpConnect ion.java:807)
    at org.mortbay.http.SocketListener.handleConnection(S ocketListener.java:197)
    at org.mortbay.util.ThreadedServer.handle(ThreadedSer ver.java:276)
    at org.mortbay.util.ThreadPool$PoolThread.run(ThreadP ool.java:511)
    Caused by: javax.management.ReflectionException: The target object class class javax.management.modelmbean.ModelMBeanOpe
    rationInfo could not be found
    at weblogic.rjvm.BasicOutboundRequest.sendReceive(Bas icOutboundRequest.java:108)
    at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicR emoteRef.java:137)
    at weblogic.management.internal.RemoteMBeanServerImpl _814_WLStub.invoke(Unknown Source)
    at org.jmanage.core.modules.weblogic.WLServerConnecti on.invoke(WLServerConnection.java:70)
    ... 24 more


    I followed the jManage weblogic setup. Is there something additional i need to do for Spring? Also, are there any other alternative jmx consoles I can use? I am using j2se 1.4, so I think jconsole is out of the question.

    thanks.

    -karl
    Last edited by robyn; May 14th, 2006, 07:14 PM.

  • #2
    There is mc4j (http://mc4j.sourceforge.net) plus a jmx servet console that you can find doing a google after jmx console (I found it on a site but I can't recall it's name). Note that I know of several problems with mc4j (beans which are not showned or failers in connecting).

    You can try also the following (I haven't):

    http://ejtools.sourceforge.net/appli...s/jmx.browser/
    http://jfoxcn.vicp.net/confluence/display/JFoxMX/Home

    Check out also the mx4j site and mailing list - there have been several discussions about on this topic.

    Comment


    • #3
      Thanks. I'll give those a try.

      Comment


      • #4
        I tried mc4j and still ran into the same exception. This is leading me to believe that this is not a jmanage issue.

        I emailed my web application and source code to a developer from jmanage who ran into the same exception when deploying the application on weblogic 8.1 sp4. The following is a quote from the message he sent me:

        I spent some time on this issue, but couldn't resolve it. It is either an issue with the
        JMX remote API that weblogic provides, or with the spring framework.

        I also tried using MC4J (another JMX console), and it has the same issue.

        There is also something weird with spring JMX exporter. It exports the get
        method both as an attribute and as an operation. When attribute's value
        is queried, it doesn't returns nothing. This seems like a bug in spring.
        My application context looks like:

        Code:
        <beans>
            
            <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter">
                <property name="beans">
                    <map>
                        <entry key="log4j&#58;name=settings" value-ref="log4jBean"/>
                    </map>
                </property>
                <property name="server">
                    <ref bean="mbeanServer"/>
                </property>
            </bean>
        
            <bean id="log4jBean" class="org.kbaum.log4j.Log4jConfig"/>
        
            <bean id="mbeanServer"
                class="org.kbaum.weblogic.jmx.WeblogicMBeanServerFactoryBean"/>
        
        </beans>
        My java code:

        Code:
        public class Log4jConfig &#123;
        
        	public void setLogger&#40;String category, String level&#41; &#123;  
        	   LogManager.getLogger&#40;category&#41;.setLevel&#40;Level.toLevel&#40;level&#41;&#41;;
        	&#125;
        	
        	public String getLog4jProperties&#40;&#41; &#123;
        		StringWriter writer = new StringWriter&#40;&#41;;
        		PrintWriter printWriter = new PrintWriter&#40;writer&#41;;
        		new PropertyPrinter&#40;printWriter&#41;;
        		printWriter.flush&#40;&#41;;
        		return writer.toString&#40;&#41;;
        	&#125;
        &#125;

        Code:
        public class WeblogicMBeanServerFactoryBean implements FactoryBean, InitializingBean &#123;
        
        	private MBeanServer server;
        	
        	public Object getObject&#40;&#41; throws Exception &#123;
        		return server;
        	&#125;
        
        	public Class getObjectType&#40;&#41; &#123;
        		return MBeanServer.class;
        	&#125;
        
        	public boolean isSingleton&#40;&#41; &#123;
        		return true;
        	&#125;
        
        	public void afterPropertiesSet&#40;&#41; throws Exception &#123;
        		MBeanHome mBeanHome = &#40;MBeanHome&#41; new JndiTemplate&#40;&#41;.lookup&#40;MBeanHome.LOCAL_JNDI_NAME&#41;; 
        		server = mBeanHome.getMBeanServer&#40;&#41;; 
        	&#125;
        
        &#125;
        If there is anything in the above configuration and java code that looks wrong, please let me know.

        Thanks.

        -karl

        Comment


        • #5
          The issue can easily be reproduced by deploying the war file available here to a weblogic 8.1 sp4 application server.

          The source code is available here.

          Thanks.

          -karl

          Comment


          • #6
            Can you please raise an issue on JIRA - attach also the war for weblogic and make a link to this topic.

            Comment


            • #7
              Jira issue has been raised here.

              Let me know if you need anything else.

              Thanks for your help!

              -karl

              Comment


              • #8
                Karl/All,

                I have this on my list of things to do tomorrow. There are some subtle issues related to classloading and JMX when operating on WLS 8.1 as I remember.

                To summarise the situation as I understand it right now:

                The issue has nothing to do with Spring exporting properties as both an MBean attribute and pair of operations. The JMX specification lays out the guidelines for exporting attributes using ModelMBeans on page 82 and requires that each attribute contains metadata for the get method and set method as appropriate (if not using a static value). The exact information contained in this metadata is *not* the name of java methods but rather the name of an exposed JMX operation corresponding to the getter/setter.

                The issue most likely lies in two places - classloading issues and settings for the caching descriptor. I'll take a look a both of these problems in the morning - most likely no fix will be required and the problem should be solvable with configuration.

                Rob

                Comment


                • #9
                  Thanks Rob!

                  Comment


                  • #10
                    Hi Rob/All,

                    I was able to invoke the mbean methods from jmanage by following the two steps you outlined in the jira issue comment. Because of a Weblogic limitation, one of these steps requires us to place many of our classes within the Weblogic system classpath. Unfortunately, this is not a change I can make to our current system.

                    Is there a way I can get around this limitation by creating my own MBeanServer using the MBeanServerFactoryBean. From the spring docs:

                    For this to work correctly, you must have a JMX implementation on your classpath.
                    I think the only jmx implementation I currently have in my classpath is weblogic's implementation. We already know there are limitations with that. What other implementations could I use?

                    Thanks again.

                    -karl

                    Comment


                    • #11
                      Karl,

                      I don't think it is even possible to get this to work, I seem to recall trying this in the past and having some issues with it. Give it a try though:

                      1. Download MX4J. This is a decent open source JMX impl
                      2. Add this to your WAR lib directory
                      3. Use MBeanServerFactoryBean to configure an instance of the MBeanServer
                      4. Add the following to weblogic.xml:

                      Code:
                      <container-descriptor>
                        	<prefer-web-inf-classes>true</prefer-web-inf-classes>
                        </container-descriptor>
                      Let me know how you go on.

                      Rob[/code]

                      Comment


                      • #12
                        Wich JMX-Implementation to use ?

                        Hi karl,

                        try out MX4J, itīs easy to set up and works fine.

                        Comment


                        • #13
                          Donīt see robs answer, sorry.

                          Sorry, didnīt see that karls question was answered on page 2 of this thread.

                          Comment


                          • #14
                            Posted an entry on how i got around the issue here.

                            Comment

                            Working...
                            X