InvokerServletpublic class InvokerServlet extends HttpServlet This servlet accepts a post containing a MarshalledInvocation, extracts
the Invocation object, and then routes the invocation via JMX to either:
1. the MBean specified via the invokerName ini parameter
2. the MBean whose object name hash is specified by the invocation.getObjectName()
value. This name's hash must have been entered into the Registry.
The method signature of the invoker must be Object invoke(org.jboss.invocation.Invocation). |
Fields Summary |
---|
private static Logger | log | private static String | REQUEST_CONTENT_TYPEA serialized MarshalledInvocation | private static String | RESPONSE_CONTENT_TYPEA serialized MarshalledValue | private MBeanServer | mbeanServer |
Methods Summary |
---|
public void | destroy()Destroys the servlet.
| protected void | doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Handles the HTTP GET method.
processRequest (request, response);
| protected void | doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Handles the HTTP POST method.
processRequest (request, response);
| public java.lang.String | getServletInfo()Returns a short description of the servlet.
return "An HTTP to JMX MBeanServer servlet";
| public void | init(javax.servlet.ServletConfig config)Initializes the servlet.
super.init (config);
// Lookup the MBeanServer
mbeanServer = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
if( mbeanServer == null )
throw new ServletException ("Failed to locate the MBeanServer");
| protected void | processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Read a MarshalledInvocation and dispatch it to the target JMX object
invoke(Invocation) object.
boolean trace = log.isTraceEnabled ();
if( trace )
{
log.trace ("processRequest, ContentLength: "+request.getContentLength ());
log.trace ("processRequest, ContentType: "+request.getContentType ());
}
try
{
response.setContentType (RESPONSE_CONTENT_TYPE);
// See if the request already has the MarshalledInvocation
Object mi = request.getAttribute ("RemoteMBeanInvocation");
if( mi == null )
{
// Get the invocation from the post
javax.servlet.ServletInputStream sis = request.getInputStream ();
java.io.ObjectInputStream ois = new java.io.ObjectInputStream (sis);
mi = ois.readObject ();
ois.close ();
}
// Forward the invocation onto the JMX bus
Object value = null;
if (mi instanceof RemoteMBeanInvocation)
{
RemoteMBeanInvocation invocation = (RemoteMBeanInvocation)mi;
value = mbeanServer.invoke (invocation.targetObjectName, invocation.actionName, invocation.params, invocation.signature);
}
else
{
RemoteMBeanAttributeInvocation invocation = (RemoteMBeanAttributeInvocation)mi;
value = mbeanServer.getAttribute(invocation.targetObjectName, invocation.attributeName);
}
org.jboss.invocation.MarshalledValue mv = new org.jboss.invocation.MarshalledValue (value);
javax.servlet.ServletOutputStream sos = response.getOutputStream ();
java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream (sos);
oos.writeObject (mv);
oos.close ();
}
catch(Throwable t)
{
t = org.jboss.mx.util.JMXExceptionDecoder.decode (t);
org.jboss.invocation.InvocationException appException = new org.jboss.invocation.InvocationException (t);
log.debug ("Invoke threw exception", t);
// Marshall the exception
response.resetBuffer ();
org.jboss.invocation.MarshalledValue mv = new org.jboss.invocation.MarshalledValue (appException);
javax.servlet.ServletOutputStream sos = response.getOutputStream ();
java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream (sos);
oos.writeObject (mv);
oos.close ();
}
|
|