0

I have create a custom JavaBean I want to return from my MBean method. The following is the custom JavaBean:

package org.text.jmx;

public class Person {
 private firstName;
 private lastName;

 public Person(){
 }

 public Person(String firstName, String lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
 }

 public String getFirstName() {
  return firstName;
 }

 public String getLastName() {
  return lastName;
 }

 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 public void setLastName(String lastName) {
  this.lastName = lastName;
 }
}

The MBean interface is the following:

package org.text.jmx;

public interface TestJmxMBean {
 public Person getPerson();
 public void setPerson(String firstName, String lastName);
}

The class the implements the MBean:

package org.text.jmx;

public class TestJmx implements TestJmxMBean {
 private Person person = new Person();

 public Person getPerson() {
  return person;
 }

 public void setPerson(String firstName, String lastName) {
  person.setFirstName(firstName);
  person.setLastName(lastName);
 }
}

I create a server application that registers the above MBean, which is successful. I create a client application which successfully connects to the server application via JMX, but when I call the testJmx.getPerson() method from the client application is receive an error that it can't return the Person object. What am I doing wrong? It works fine is I just define the return type as as String or String[] from the TestJmx.getPerson().

ThomasD
  • 1
  • 2

1 Answers1

0

In order to expose a custom object as a JMX attribute, or the return value or an operation, it must be defined as an OpenType. The usual way of doing this is to define an MXBean. I answered a similar question which should give you an idea on how to proceed.

Community
  • 1
  • 1
Nicholas
  • 15,916
  • 4
  • 42
  • 66