protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
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 ();
}
}
Read a MarshalledInvocation and dispatch it to the target JMX object
invoke(Invocation) object. |