1 22 package org.jboss.console.remote; 23 24 import javax.servlet.ServletException ; 25 26 27 41 public class InvokerServlet extends javax.servlet.http.HttpServlet 42 { 43 private static org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger (InvokerServlet.class); 44 45 private static String REQUEST_CONTENT_TYPE = 46 "application/x-java-serialized-object; class=org.jboss.console.remote.RemoteMBeanInvocation"; 47 48 private static String RESPONSE_CONTENT_TYPE = 49 "application/x-java-serialized-object; class=org.jboss.invocation.MarshalledValue"; 50 private javax.management.MBeanServer mbeanServer; 51 52 54 public void init (javax.servlet.ServletConfig config) throws ServletException 55 { 56 super.init (config); 57 58 mbeanServer = org.jboss.mx.util.MBeanServerLocator.locateJBoss(); 60 if( mbeanServer == null ) 61 throw new ServletException ("Failed to locate the MBeanServer"); 62 } 63 64 66 public void destroy () 67 { 68 69 } 70 71 77 protected void processRequest (javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ServletException , java.io.IOException 78 { 79 boolean trace = log.isTraceEnabled (); 80 if( trace ) 81 { 82 log.trace ("processRequest, ContentLength: "+request.getContentLength ()); 83 log.trace ("processRequest, ContentType: "+request.getContentType ()); 84 } 85 86 try 87 { 88 response.setContentType (RESPONSE_CONTENT_TYPE); 89 Object mi = request.getAttribute ("RemoteMBeanInvocation"); 91 if( mi == null ) 92 { 93 javax.servlet.ServletInputStream sis = request.getInputStream (); 95 java.io.ObjectInputStream ois = new java.io.ObjectInputStream (sis); 96 mi = ois.readObject (); 97 ois.close (); 98 } 99 100 Object value = null; 102 if (mi instanceof RemoteMBeanInvocation) 103 { 104 RemoteMBeanInvocation invocation = (RemoteMBeanInvocation)mi; 105 value = mbeanServer.invoke (invocation.targetObjectName, invocation.actionName, invocation.params, invocation.signature); 106 } 107 else 108 { 109 RemoteMBeanAttributeInvocation invocation = (RemoteMBeanAttributeInvocation)mi; 110 value = mbeanServer.getAttribute(invocation.targetObjectName, invocation.attributeName); 111 } 112 org.jboss.invocation.MarshalledValue mv = new org.jboss.invocation.MarshalledValue (value); 113 javax.servlet.ServletOutputStream sos = response.getOutputStream (); 114 java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream (sos); 115 oos.writeObject (mv); 116 oos.close (); 117 } 118 catch(Throwable t) 119 { 120 t = org.jboss.mx.util.JMXExceptionDecoder.decode (t); 121 org.jboss.invocation.InvocationException appException = new org.jboss.invocation.InvocationException (t); 122 log.debug ("Invoke threw exception", t); 123 response.resetBuffer (); 125 org.jboss.invocation.MarshalledValue mv = new org.jboss.invocation.MarshalledValue (appException); 126 javax.servlet.ServletOutputStream sos = response.getOutputStream (); 127 java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream (sos); 128 oos.writeObject (mv); 129 oos.close (); 130 } 131 } 132 133 137 protected void doGet (javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ServletException , java.io.IOException 138 { 139 processRequest (request, response); 140 } 141 142 146 protected void doPost (javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ServletException , java.io.IOException 147 { 148 processRequest (request, response); 149 } 150 151 153 public String getServletInfo () 154 { 155 return "An HTTP to JMX MBeanServer servlet"; 156 } 157 158 } 159 | Popular Tags |