User: cgjung
Date: 01/10/03 06:20:32
Added: jboss.net/src/main/org/jboss/net/jmx/server Constants.java
MBeanProvider.java package.html
Log:
restructured server/client parts, invocationhandler support.
MBeanProvider for exposing MBeans as web-services.
JMXConnector.
Revision Changes Path
1.1
contrib/jboss.net/src/main/org/jboss/net/jmx/server/Constants.java
Index: Constants.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
// $Id: Constants.java,v 1.1 2001/10/03 13:20:32 cgjung Exp $
package org.jboss.net.jmx.server;
import org.apache.log4j.Category;
/**
* 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 $
*/
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.";
}
1.1
contrib/jboss.net/src/main/org/jboss/net/jmx/server/MBeanProvider.java
Index: MBeanProvider.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
// $Id: MBeanProvider.java,v 1.1 2001/10/03 13:20:32 cgjung Exp $
package org.jboss.net.jmx.server;
import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.providers.BasicProvider;
import org.apache.axis.message.RPCElement;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.message.RPCParam;
import org.apache.axis.Handler;
import org.apache.axis.utils.JavaUtils;
import org.apache.log4j.Category;
import javax.management.MBeanServerFactory;
import javax.management.MBeanServer;
import javax.management.MBeanException;
import javax.management.ReflectionException;
import javax.management.InstanceNotFoundException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.util.Iterator;
import java.util.List;
/**
* Exposes mbeans as targets (pivot-handlers) of web-services. To
* deploy a particular mbean as a web-service, a deployment descriptor
* would look like:
*
* <admin:deploy xmlns:admin="AdminService"/>
* <handler name="MBeanDispatcher" class="org.jboss.net.jmx.MBeanProvider"/>
* <service name="${ServiceName}" pivot="MBeanDispatcher">
* <option name="ObjectName" value="${JMX_ObjectName}"/>
* </service>
* </admin:deploy>
*
* The message format (WSDL generation is to come ...) requires the first
* parameter being always a String[] of the length of the following
* parameters that describes the signature of the target method.
*
* @created 1. Oktober 2001, 16:38
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @version $Revision: 1.1 $
*/
public class MBeanProvider extends BasicProvider implements Constants {
/** Creates new MBeanProvider */
public MBeanProvider() {
}
/**
* Invoke is called to do the actual work of the Handler object.
*/
public void invoke(MessageContext msgContext) throws AxisFault {
// the options of the service
String serviceName = msgContext.getTargetService();
Handler service = msgContext.getServiceHandler();
// 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.getAsSOAPEnvelope();
Message resMsg = msgContext.getResponseMessage();
SOAPEnvelope resEnv = (resMsg == null) ?
new SOAPEnvelope() :
(SOAPEnvelope)resMsg.getAsSOAPEnvelope();
// copied code from RobJ, duh?
if (msgContext.getResponseMessage() == null) {
resMsg = new Message(resEnv);
msgContext.setResponseMessage( resMsg );
}
// navigate the bodies
Iterator allBodies = reqEnv.getBodyElements().iterator();
while(allBodies.hasNext()) {
Object nextBody=allBodies.next();
if(nextBody instanceof RPCElement) {
RPCElement body = (RPCElement) nextBody;
String mName = body.getMethodName();
List args = body.getParams();
Object[] arguments;
String[] classNames;
// parameter preprocessing
if(args==null || args.size()==0) {
arguments=new Object[0];
classNames=new String[0];
} else {
arguments=new Object[args.size()-1];
RPCParam param=(RPCParam) args.get(0);
try{
classNames=(String[])
JavaUtils.convert(param.getValue(),String[].class);
for(int count=0; count<classNames.length; count++) {
param=(RPCParam) args.get(count+1);
try{
arguments[count]=JavaUtils.convert(param.getValue(),
msgContext.getClassLoader().loadClass(classNames[count]));
} catch(ClassNotFoundException e) {
throw new AxisFault(CLASS_NOT_FOUND,e);
}
}
} catch(ClassCastException e) {
throw new AxisFault(COULD_NOT_CONVERT_PARAMS,e);
}
}
// now do the JMX call
try{
Object result =
server.invoke(name,mName,arguments,classNames);
// and encode it back to the response
RPCElement resBody = new RPCElement(mName + "Response");
resBody.setPrefix( body.getPrefix() );
resBody.setNamespaceURI( body.getNamespaceURI() );
RPCParam param = new RPCParam(mName + "Result", result);
resBody.addParam(param);
resEnv.addBodyElement( resBody );
resEnv.setEncodingStyleURI(org.apache.axis.Constants.URI_SOAP_ENC);
} catch(InstanceNotFoundException e) {
throw new AxisFault(NO_MBEAN_INSTANCE,e);
} catch(MBeanException e) {
throw new AxisFault(MBEAN_EXCEPTION,e);
} catch(ReflectionException e) {
throw new AxisFault(EXCEPTION_OCCURED,e.getTargetException());
}
} // if(nextBody instanceof RPCElement)
} // // while(allBodies.hasNext())
} // invoke
/**
* ToDo, inspect mbean-interfaces or so?
*/
public void generateWSDL(MessageContext msgContext) throws AxisFault {
}
/**
* ToDo, called when a fault occurs to 'undo' whatever 'invoke' did.
*/
public void undo(MessageContext msgContext) {
// unbelievable this foresight
}
}
1.1 contrib/jboss.net/src/main/org/jboss/net/jmx/server/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>JMX server package</TITLE>
</HEAD>
<BODY>
Hosts provider functionality to turn MBeans into web services.
</BODY>
</HTML>
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development