1 22 package org.jboss.ejb3.test.clusteredservice.servlets; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 27 import java.util.Properties ; 28 29 import javax.management.MBeanServer ; 30 import javax.management.ObjectName ; 31 import javax.naming.Context ; 32 import javax.naming.InitialContext ; 33 import javax.servlet.ServletException ; 34 import javax.servlet.http.HttpServlet ; 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 38 import org.jboss.ejb3.test.clusteredservice.ServiceRemote; 39 import org.jboss.logging.Logger; 40 41 45 public class EJBServlet extends HttpServlet 46 { 47 private static final Logger log = Logger.getLogger(EJBServlet.class); 48 49 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 50 throws ServletException , IOException 51 { 52 try 53 { 54 ServiceRemote test = (ServiceRemote) getInitialContext().lookup("ServiceBean/remote"); 55 test.remoteMethod(); 56 57 62 } 63 catch (Exception e) 64 { 65 e.printStackTrace(); 66 67 throw new ServletException ("Failed to call ServiceBean through remote or local interfaces", e); 68 } 69 response.setContentType("text/html"); 70 PrintWriter out = response.getWriter(); 71 out.println("<html>"); 72 out.println("<head><title>EJBServlet</title></head>"); 73 out.println("<body>Tests passed<br></body>"); 74 out.println("</html>"); 75 out.close(); 76 } 77 78 protected InitialContext getInitialContext() throws Exception 79 { 80 Properties p = new Properties (); 81 p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 82 p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces"); 83 p.put(Context.PROVIDER_URL, "localhost:1100"); 84 return new InitialContext (p); 85 } 86 87 protected void doGet(HttpServletRequest request, HttpServletResponse response) 88 throws ServletException , IOException 89 { 90 processRequest(request, response); 91 } 92 93 protected void doPost(HttpServletRequest request, HttpServletResponse response) 94 throws ServletException , IOException 95 { 96 processRequest(request, response); 97 } 98 } 99 | Popular Tags |