1 7 package org.jboss.remoting.transport.servlet.web; 8 9 import java.io.IOException ; 10 import javax.management.MBeanServer ; 11 import javax.management.MBeanServerInvocationHandler ; 12 import javax.management.MalformedObjectNameException ; 13 import javax.management.ObjectName ; 14 import javax.servlet.ServletConfig ; 15 import javax.servlet.ServletException ; 16 import javax.servlet.http.HttpServlet ; 17 import javax.servlet.http.HttpServletRequest ; 18 import javax.servlet.http.HttpServletResponse ; 19 import org.jboss.logging.Logger; 20 import org.jboss.mx.util.MBeanServerLocator; 21 import org.jboss.remoting.transport.servlet.ServletServerInvokerMBean; 22 23 28 public class ServerInvokerServlet extends HttpServlet 29 { 30 private static Logger log = Logger.getLogger(ServerInvokerServlet.class); 31 private ServletServerInvokerMBean servletInvoker; 32 33 36 public void init(ServletConfig config) throws ServletException 37 { 38 super.init(config); 39 ObjectName localInvokerName = null; 40 try 41 { 42 String name = config.getInitParameter("invokerName"); 44 if(name != null) 45 { 46 localInvokerName = new ObjectName (name); 47 log.debug("localInvokerName=" + localInvokerName); 48 } 49 } 50 catch(MalformedObjectNameException e) 51 { 52 throw new ServletException ("Failed to build invokerName", e); 53 } 54 55 MBeanServer mbeanServer = MBeanServerLocator.locateJBoss(); 57 if(mbeanServer == null) 58 { 59 throw new ServletException ("Failed to locate the MBeanServer"); 60 } 61 else 62 { 63 servletInvoker = (ServletServerInvokerMBean) 64 MBeanServerInvocationHandler.newProxyInstance(mbeanServer, 65 localInvokerName, 66 ServletServerInvokerMBean.class, 67 false); 68 69 } 70 } 71 72 75 public void destroy() 76 { 77 78 } 79 80 87 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 88 throws ServletException , IOException 89 { 90 boolean trace = log.isTraceEnabled(); 91 if(trace) 92 { 93 log.trace("processRequest, ContentLength: " + request.getContentLength()); 94 log.trace("processRequest, ContentType: " + request.getContentType()); 95 } 96 97 servletInvoker.processRequest(request, response); 98 99 } 100 101 107 protected void doGet(HttpServletRequest request, HttpServletResponse response) 108 throws ServletException , IOException 109 { 110 processRequest(request, response); 111 } 112 113 119 protected void doPost(HttpServletRequest request, HttpServletResponse response) 120 throws ServletException , IOException 121 { 122 processRequest(request, response); 123 } 124 125 128 public String getServletInfo() 129 { 130 return "Servlet front to JBossRemoting servlet server invoker."; 131 } 132 133 } | Popular Tags |