User: cgjung
Date: 02/04/03 08:11:21
Modified: jboss.net/src/main/org/jboss/net/jmx/server Constants.java
MBeanProvider.java
Log:
On behalf of Peter Braswell who needs his rw back -
made MBeanProvider JMX1.1 and hence JBossJMX compatible.
Added additional testcase that is not yet completed in the
testsuite/build.xml
Revision Changes Path
1.2 +21 -14
contrib/jboss.net/src/main/org/jboss/net/jmx/server/Constants.java
Index: Constants.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/jmx/server/Constants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Constants.java 3 Oct 2001 13:20:32 -0000 1.1
+++ Constants.java 3 Apr 2002 16:11:21 -0000 1.2
@@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
-// $Id: Constants.java,v 1.1 2001/10/03 13:20:32 cgjung Exp $
+// $Id: Constants.java,v 1.2 2002/04/03 16:11:21 cgjung Exp $
package org.jboss.net.jmx.server;
@@ -15,20 +15,27 @@
* Some Constants for the jmx server package
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @created 1. October 2001
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface Constants {
-
- static final Category LOG=Category.getInstance(Constants.class.
- getPackage().getName());
- static final String MBEAN_SERVER_ID_PROPERTY="MBeanServerId";
- static final String OBJECTNAME_PROPERTY="ObjectName";
- static final String WRONG_OBJECT_NAME="ObjectName could not be converted to a
javax.management.ObjectName.";
- static final String NO_MBEAN_SERVER_FOUND="Could not find the associated
MBeanServer.";
- static final String COULD_NOT_CONVERT_PARAMS="Could not convert the parameters
to corresponding Java types.";
- static final String CLASS_NOT_FOUND="Could not find Java class.";
- static final String NO_MBEAN_INSTANCE="Could not find MBean instance.";
- static final String MBEAN_EXCEPTION="Problems while interfacing JMX.";
- static final String EXCEPTION_OCCURED="Exception occurred in the target MBean
method.";
-}
\ No newline at end of file
+
+ static final Category LOG =
+ Category.getInstance(Constants.class.getPackage().getName());
+ static final String MBEAN_SERVER_ID_PROPERTY = "MBeanServerId";
+ static final String OBJECTNAME_PROPERTY = "ObjectName";
+ static final String WRONG_OBJECT_NAME =
+ "ObjectName could not be converted to a javax.management.ObjectName.";
+ static final String NO_MBEAN_SERVER_FOUND =
+ "Could not find the associated MBeanServer.";
+ static final String COULD_NOT_CONVERT_PARAMS =
+ "Could not convert the parameters to corresponding Java types.";
+ static final String CLASS_NOT_FOUND = "Could not find Java class.";
+ static final String NO_MBEAN_INSTANCE = "Could not find MBean instance.";
+ static final String NO_SUCH_ATTRIBUTE = "Could not find MBean attribute.";
+ static final String INVALID_ARGUMENT = "Invalid Argument.";
+ static final String MBEAN_EXCEPTION = "Problems while interfacing JMX.";
+ static final String EXCEPTION_OCCURED =
+ "Exception occurred in the target MBean method.";
+ static final String INTROSPECTION_EXCEPTION="Could not introspect mbean.";
+}
\ No newline at end of file
1.4 +119 -47
contrib/jboss.net/src/main/org/jboss/net/jmx/server/MBeanProvider.java
Index: MBeanProvider.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/jmx/server/MBeanProvider.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MBeanProvider.java 2 Apr 2002 13:48:39 -0000 1.3
+++ MBeanProvider.java 3 Apr 2002 16:11:21 -0000 1.4
@@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
-// $Id: MBeanProvider.java,v 1.3 2002/04/02 13:48:39 cgjung Exp $
+// $Id: MBeanProvider.java,v 1.4 2002/04/03 16:11:21 cgjung Exp $
package org.jboss.net.jmx.server;
@@ -36,22 +36,32 @@
import javax.management.InstanceNotFoundException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import javax.management.Attribute;
+import javax.management.MBeanInfo;
+import javax.management.MBeanAttributeInfo;
+import javax.management.AttributeNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.IntrospectionException;
+import javax.management.ReflectionException;
// utils
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
/**
* Exposes mbeans as targets (pivot-handlers) of web-services. To
* deploy a particular mbean as a web-service, a deployment descriptor
* would look like:
*
- * <deployment>
+ * <wsdd:deployment>
* <handler name="MBeanDispatcher" class="org.jboss.net.jmx.MBeanProvider"/>
- * <service name="${ServiceName}" pivot="MBeanDispatcher">
+ * <wsdd:service name="${ServiceName}" handler="Handler">
+ * <option name="handlerClass" value="org.jboss.net.jmx.server.MBeanProvider"/>
* <option name="ObjectName" value="${JMX_ObjectName}"/>
- * </service>
- * </deployment>
+ * </wsdd:service>
+ * </wsdd:deployment>
*
* The message format (WSDL generation is to come ...) requires the first
* parameter being always a String[] of the length of the following
@@ -60,59 +70,102 @@
* <br>
* <h3>Change History</h3>
* <ul>
- * <li> jung, 21.03.2002: made apache axis beta1 compliant. </li>
+ * <li> jung, 03.04.2002: cache some meta-data about mbean. </li>
+ * <li> braswell, 03.04.2002: JMX1.1 does not expose attribut accessors as methods
anymore. </li>
+ * <li> jung, 21.03.2002: made apache axis beta1 compliant. </li>
* </ul>
*
* @created 1. Oktober 2001, 16:38
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
-public class MBeanProvider extends BasicProvider implements Constants {
+public class MBeanProvider extends BasicProvider {
+
+ /** stores meta-data about mbean */
+ protected MBeanInfo info;
+
+ /** stores attribute meta-data */
+ protected MBeanAttributeInfo[] attributes;
+
+ /** hashmap from attribute-name to attribute info */
+ protected Map attributeMap = new java.util.HashMap();
+
+ /** the server which we are tight to */
+ protected MBeanServer server;
+
+ /** the objectName which we are running into */
+ protected ObjectName name;
+
+ /** whether this provider has been already initialized */
+ protected boolean initialized;
/** Creates new MBeanProvider */
public MBeanProvider() {
}
+ /** initialize the meta-data */
+ protected synchronized void initialize(MessageContext msgContext)
+ throws AxisFault {
+ if (!initialized) {
+ initialized = true;
+ SOAPService service = msgContext.getService();
+ // include the JMX objectname
+ String objectName = (String)
service.getOption(Constants.OBJECTNAME_PROPERTY);
+ // and the server id (maybe)
+ String serverId =
+ (String) service.getOption(Constants.MBEAN_SERVER_ID_PROPERTY);
+
+ // process server id
+ Iterator allServers =
MBeanServerFactory.findMBeanServer(serverId).iterator();
+ if (!allServers.hasNext())
+ throw new AxisFault(Constants.NO_MBEAN_SERVER_FOUND);
+ else
+ server = (MBeanServer) allServers.next();
+
+ // process objectname
+ try {
+ name = new ObjectName(objectName);
+ } catch (MalformedObjectNameException e) {
+ throw new AxisFault(Constants.WRONG_OBJECT_NAME, e);
+ }
+
+ try {
+ info = server.getMBeanInfo(name);
+ } catch (InstanceNotFoundException e) {
+ throw new AxisFault(Constants.NO_MBEAN_INSTANCE, e);
+ } catch (IntrospectionException e) {
+ throw new AxisFault(Constants.INTROSPECTION_EXCEPTION, e);
+ } catch (ReflectionException e) {
+ throw new AxisFault(Constants.INTROSPECTION_EXCEPTION, e);
+ }
+
+ attributes = info.getAttributes();
+
+ for (int i = 0; i < attributes.length; ++i) {
+ attributeMap.put(attributes[i].getName(), attributes[i]);
+ }
+
+ }
+ }
+
/**
* Invoke is called to do the actual work of the Handler object.
*/
public void invoke(MessageContext msgContext) throws AxisFault {
+ // initialize first
+ initialize(msgContext);
+
// the options of the service
String serviceName = msgContext.getTargetService();
- SOAPService service = msgContext.getService();
- // include the JMX objectname
- String objectName = (String) service.getOption(OBJECTNAME_PROPERTY);
- // and the server id (maybe)
- String serverId = (String) service.getOption(MBEAN_SERVER_ID_PROPERTY);
-
- // process objectname
- ObjectName name = null;
-
- try {
- name = new ObjectName(objectName);
- } catch (MalformedObjectNameException e) {
- throw new AxisFault(WRONG_OBJECT_NAME, e);
- }
-
- // process server id
- MBeanServer server = null;
-
- Iterator allServers = MBeanServerFactory.findMBeanServer(serverId).iterator();
- if (!allServers.hasNext())
- throw new AxisFault(NO_MBEAN_SERVER_FOUND);
- else
- server = (MBeanServer) allServers.next();
// dissect the message
Message reqMsg = msgContext.getRequestMessage();
SOAPEnvelope reqEnv = (SOAPEnvelope) reqMsg.getSOAPEnvelope();
Message resMsg = msgContext.getResponseMessage();
SOAPEnvelope resEnv =
- (resMsg == null)
- ? new SOAPEnvelope()
- : (SOAPEnvelope) resMsg.getSOAPEnvelope();
+ (resMsg == null) ? new SOAPEnvelope() : (SOAPEnvelope)
resMsg.getSOAPEnvelope();
// copied code from RobJ, duh?
if (msgContext.getResponseMessage() == null) {
@@ -128,11 +181,11 @@
if (nextBody instanceof RPCElement) {
RPCElement body = (RPCElement) nextBody;
String mName = body.getMethodName();
- List args=null;
- try{
- args = body.getParams();
- } catch(SAXException e) {
- throw new AxisFault( EXCEPTION_OCCURED,e);
+ List args = null;
+ try {
+ args = body.getParams();
+ } catch (SAXException e) {
+ throw new AxisFault(Constants.EXCEPTION_OCCURED, e);
}
Object[] arguments;
String[] classNames;
@@ -154,17 +207,32 @@
param.getValue(),
msgContext.getClassLoader().loadClass(classNames[count]));
} catch (ClassNotFoundException e) {
- throw new AxisFault(CLASS_NOT_FOUND, e);
+ throw new AxisFault(Constants.CLASS_NOT_FOUND, e);
}
}
} catch (ClassCastException e) {
- throw new AxisFault(COULD_NOT_CONVERT_PARAMS, e);
+ throw new AxisFault(Constants.COULD_NOT_CONVERT_PARAMS, e);
}
}
// now do the JMX call
try {
- Object result = server.invoke(name, mName, arguments, classNames);
+ Object result;
+ // now we have to distinguish attribute from
+ // "regular" method access, taken over from MBeanProxy
+ if (mName.startsWith("get") && arguments.length == 0) {
+ String attrName = mName.substring(3);
+ result = server.getAttribute(name, attrName);
+ } else if (mName.startsWith("is") && arguments.length == 0) {
+ String attrName = mName.substring(2);
+ result = server.getAttribute(name, attrName);
+ } else if (mName.startsWith("set") && arguments.length == 1) {
+ String attrName = mName.substring(3);
+ server.setAttribute(name, new Attribute(attrName, arguments[0]));
+ result = null;
+ } else {
+ result = server.invoke(name, mName, arguments, classNames);
+ }
// and encode it back to the response
RPCElement resBody = new RPCElement(mName + "Response");
resBody.setPrefix(body.getPrefix());
@@ -174,13 +242,17 @@
resEnv.addBodyElement(resBody);
resEnv.setEncodingStyle(org.apache.axis.Constants.URI_SOAP_ENC);
} catch (InstanceNotFoundException e) {
- throw new AxisFault(NO_MBEAN_INSTANCE, e);
+ throw new AxisFault(Constants.NO_MBEAN_INSTANCE, e);
+ } catch (AttributeNotFoundException e) {
+ throw new AxisFault(Constants.NO_SUCH_ATTRIBUTE, e);
+ } catch (InvalidAttributeValueException e) {
+ throw new AxisFault(Constants.INVALID_ARGUMENT, e);
} catch (MBeanException e) {
- throw new AxisFault(MBEAN_EXCEPTION, e);
+ throw new AxisFault(Constants.MBEAN_EXCEPTION, e);
} catch (ReflectionException e) {
- throw new AxisFault(EXCEPTION_OCCURED, e.getTargetException());
- } catch(SOAPException e) {
- throw new AxisFault(EXCEPTION_OCCURED, e);
+ throw new AxisFault(Constants.EXCEPTION_OCCURED,
e.getTargetException());
+ } catch (SOAPException e) {
+ throw new AxisFault(Constants.EXCEPTION_OCCURED, e);
}
} // if(nextBody instanceof RPCElement)
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development