Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Controlling log4j using Spring JMX and jmanage

  1. #1
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default 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 at 06:14 PM.
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    Thanks. I'll give those a try.
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  4. #4
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    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
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  5. #5
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    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
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  6. #6
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Can you please raise an issue on JIRA - attach also the war for weblogic and make a link to this topic.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  7. #7
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    Jira issue has been raised here.

    Let me know if you need anything else.

    Thanks for your help!

    -karl
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  8. #8
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    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
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  9. #9
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    Thanks Rob!
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  10. #10
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    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
    Karl Baum
    weblog: www.jroller.com/page/kbaum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •