1 22 package org.jboss.test.web.servlets; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import javax.rmi.PortableRemoteObject ; 30 import javax.servlet.ServletConfig ; 31 import javax.servlet.ServletException ; 32 import javax.servlet.http.HttpServlet ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import javax.sql.DataSource ; 36 37 import org.jboss.test.web.interfaces.ReferenceTest; 38 import org.jboss.test.web.interfaces.StatelessSession; 39 import org.jboss.test.web.interfaces.StatelessSessionHome; 40 import org.jboss.test.web.interfaces.StatelessSessionLocal; 41 import org.jboss.test.web.interfaces.StatelessSessionLocalHome; 42 import org.jboss.test.web.interfaces.ReturnData; 43 import org.jboss.test.web.util.Util; 44 45 51 public class EJBServlet extends HttpServlet 52 { 53 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 54 throws ServletException , IOException 55 { 56 try 57 { 58 InitialContext ctx = new InitialContext (); 59 Context enc = (Context ) ctx.lookup("java:comp/env"); 60 StatelessSessionHome home = (StatelessSessionHome) enc.lookup("ejb/OptimizedEJB"); 61 StatelessSession bean = home.create(); 62 bean.noop(new ReferenceTest(), true); 63 64 Object homeRef = enc.lookup("ejb/OptimizedEJB"); 65 home = (StatelessSessionHome) PortableRemoteObject.narrow(homeRef, StatelessSessionHome.class); 66 bean = home.create(); 67 bean.noop(new ReferenceTest(), true); 68 ReturnData data = bean.getData(); 69 70 StatelessSessionLocalHome localHome = (StatelessSessionLocalHome) enc.lookup("ejb/local/OptimizedEJB"); 71 StatelessSessionLocal localBean = localHome.create(); 72 localBean.noop(new ReferenceTest(), true); 73 } 74 catch (Exception e) 75 { 76 throw new ServletException ("Failed to call OptimizedEJB through remote and local interfaces", e); 77 } 78 response.setContentType("text/html"); 79 PrintWriter out = response.getWriter(); 80 out.println("<html>"); 81 out.println("<head><title>EJBServlet</title></head>"); 82 out.println("<body>Tests passed<br>Time:" + Util.getTime() + "</body>"); 83 out.println("</html>"); 84 out.close(); 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 |