// Forward the invocation onto the JMX invoker
Object value = mbeanServer.invoke(invokerName, "invoke", params, sig);
if( returnValueAsAttribute == null || returnValueAsAttribute.booleanValue() == false )
{
MarshalledValue mv = new MarshalledValue(value);
ServletOutputStream sos = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(sos);
oos.writeObject(mv);
oos.close();
}
else
{
request.setAttribute("returnValue", value);
}
}
catch(Throwable t)
{
t = JMXExceptionDecoder.decode(t);
// Unwrap any reflection InvocationTargetExceptions
if( t instanceof InvocationTargetException )
{
InvocationTargetException ite = (InvocationTargetException) t;
t = ite.getTargetException();
}
/* Wrap the exception in an InvocationException to distinguish
between application and transport exceptions
*/
InvocationException appException = new InvocationException(t);
// Marshall the exception
if( returnValueAsAttribute == null || returnValueAsAttribute.booleanValue() == false )
{
if (response.isCommitted())
{
// Cannot report back exception
log.error("Invoke threw exception, and response is already committed", t);
}
else
{
response.resetBuffer();
MarshalledValue mv = new MarshalledValue(appException);
ServletOutputStream sos = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(sos);
oos.writeObject(mv);
oos.close();
}
}