Announcement Announcement Module
Collapse
No announcement yet.
Spring JMX - server/client remote access Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JMX - server/client remote access

    Hello,
    I am trying to implemet JMX client / server side.
    I am using JSR-160 Connectors.
    Any help is appreciated.

    I create a server and register a POJO as an MBEAN on a remote MBEAN server (although I am pointing to localhost).
    My client is then trying to access the the MBEAN on the remote MBEAN server.
    I successfully register the bean on the MBEAN server using ConnectorServerFactoryBean.
    But when I run the client I am getting the following exception:

    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mbeanExporter' defined in class path resource [com/interface21/spring/jmx/basic/clientDemo.xml]: Invocation of init method failed; nested exception is org.springframework.jmx.access.InvalidInvocationEx ception: Operation 'toString' is not exposed on the management interface
    Caused by: org.springframework.jmx.access.InvalidInvocationEx ception: Operation 'toString' is not exposed on the management interface
    at org.springframework.jmx.access.MBeanClientIntercep tor.invokeOperation(MBeanClientInterceptor.java:35 9)
    at org.springframework.jmx.access.MBeanClientIntercep tor.invoke(MBeanClientInterceptor.java:302)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :161)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:203)
    at $Proxy0.toString(Unknown Source)
    at java.lang.String.valueOf(String.java:1499)
    at java.lang.StringBuffer.append(StringBuffer.java:22 0)
    at org.springframework.jmx.export.MBeanExporter.creat eAndConfigureMBean(MBeanExporter.java:710)
    at org.springframework.jmx.export.MBeanExporter.regis terBeanInstance(MBeanExporter.java:601)
    at org.springframework.jmx.export.MBeanExporter.regis terBeanNameOrInstance(MBeanExporter.java:570)
    at org.springframework.jmx.export.MBeanExporter.regis terBeans(MBeanExporter.java:499)
    at org.springframework.jmx.export.MBeanExporter.after PropertiesSet(MBeanExporter.java:388)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1175)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1145)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:427)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 51)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:144)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:279)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:360)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:91)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:75)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:65)
    at com.interface21.spring.jmx.basic.ClientDemo.main(C lientDemo.java:31)


    Here is my server side xml:
    <beans>
    <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistr yFactoryBean">
    <property name="port" value="8999"/>
    </bean>
    <bean id="serverConnector"
    class="org.springframework.jmx.support.ConnectorSe rverFactoryBean">
    <property name="objectName" value="connector:name=rmi"/>
    <property name="serviceUrl"
    value="service:jmx:rmi://localhost/jndi/rmi://localhost:8999/myconnector"/>
    </bean>
    <!-- define an MBeanExporter -->
    <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporte r" lazy-init="false">
    <!-- the beans to be exported to JMX -->
    <property name="beans">
    <map>
    <entry key="i21:name=messageService">
    <ref local="basicBean"/>
    </entry>
    </map>
    </property>
    </bean>
    <!-- define a simple service bean -->
    <bean id="basicBean" class="com.interface21.spring.jmx.basic.MessageSer vice"/>


    Here is my client side xml:

    <beans>
    <!-- define a simple service bean -->

    <!-- define an MBeanExporter -->
    <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporte r" lazy-init="false">
    <!-- the beans to be exported to JMX -->
    <property name="autodetectModeName" value="AUTODETECT_ALL" />
    <property name="beans">
    <map>
    <entry key="Services:name=proxy"
    value-ref="proxy" />
    </map>
    </property>
    </bean>
    <bean id="clientConnector" class="org.springframework.jmx.support.MBeanServer ConnectionFactoryBean">
    <property name="serviceUrl" value="service:jmx:rmi:///jndi/rmi://localhost:8999/myconnector"/>
    </bean>
    <bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFa ctoryBean">
    <property name="objectName" value="i21:name=messageService"/>
    <property name="proxyInterface" value="com.interface21.spring.jmx.basic.MessageSer viceInf"/>
    <property name="server" ref="clientConnector"/>
    </bean>

  • #2
    Hi!

    I'm not sure what you want to do here? Why is your client registering the 'proxy' bean. Do you want to access the MBean on the remote server? Try to simple remove the 'mbeanExporter' bean from your client configuration.

    Kind regards
    Juergen

    Comment


    • #3
      That worked, thanks very much! HTTPAdaptor???

      Thanks very much!
      That worked.
      I was indeed trying to access the MBean on the remote server via the client.

      My end goal is to use the HttpAdaptor in the client so I can easily view the registered mbeans on the remote server.

      Do you have references on how to do this.
      I found (and ran) an example of sorts of this, but in the example, the HTTPAdaptor was exported along with the beans on the server side.
      I want to register the mbeans to monitor seperately on the client.

      Do you know any better way to do this?

      Thanks again for all your help. I am very new to this and am trying to learn as much as I can.

      Comment


      • #4
        I got the HTTPAdaptor to work w/the client side - Is this reasonable?

        Hello,

        I got the HTTPAdaptor(using XSLTProcessor) to work on the client side.
        I connect to the remote MBEAN server and i am able to display through a browser the MBEANS I register.

        I just want to make sure I am doing this correctly, and not hacking.

        Thanks for all your help:

        Here's my client code main method:

        String SPRING_FILE = "com/interface21/spring/jmx/basic/clientDemo.xml";

        ApplicationContext context = new ClassPathXmlApplicationContext(SPRING_FILE);
        MBeanServerConnection connector = (MBeanServerConnection) context.getBean("clientConnector");
        ObjectName exampleServiceName = ObjectName.getInstance("i21:name=messageService");
        boolean isregistered = connector.isRegistered(exampleServiceName);

        ObjectName name = new ObjectName("Server:name=HttpAdaptor,port=8080,host =localhost,processor=mx4j.tools.adaptor.http.XSLTP rocessor");
        ObjectName processorName = new ObjectName("Server:name=XSLTProcessor");

        boolean ishttpregistered = connector.isRegistered(name);
        boolean isprocessorregistered = connector.isRegistered(processorName);
        if (!ishttpregistered)
        {
        connector.createMBean("mx4j.tools.adaptor.http.Htt pAdaptor", name);
        }
        if (!isprocessorregistered)
        {
        connector.createMBean("mx4j.tools.adaptor.http.XSL TProcessor", processorName);
        }
        connector.setAttribute(name, new Attribute("Port", 8090));
        connector.setAttribute(name, new Attribute("Host", "dnavsa1"));
        connector.setAttribute(name, new Attribute("ProcessorName", processorName));
        connector.invoke(name, "start", null, null);


        Here's the client.xml:
        <beans>
        <!-- define a simple service bean -->

        <!-- define an MBeanExporter -->

        <bean id="clientConnector" class="org.springframework.jmx.support.MBeanServer ConnectionFactoryBean">
        <property name="serviceUrl" value="service:jmx:rmi:///jndi/rmi://localhost:8999/myconnector"/>
        </bean>
        <bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFa ctoryBean">
        <property name="objectName" value="i21:name=messageService"/>
        <property name="proxyInterface" value="com.interface21.spring.jmx.basic.MessageSer viceInf"/>
        <property name="server" ref="clientConnector"/>
        </bean>
        <bean id="XSLTProcessor"
        class="mx4j.tools.adaptor.http.XSLTProcessor" />
        <bean id="HttpAdaptor"
        class="mx4j.tools.adaptor.http.HttpAdaptor">
        <property name="processor" ref="XSLTProcessor"/>
        <property name="port" value="8080"/>
        </bean>


        </beans>

        Comment

        Working...
        X