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.servlet.ServletConfig ; 30 import javax.servlet.ServletException ; 31 import javax.servlet.http.HttpServlet ; 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 35 import org.jboss.test.web.interfaces.Entity; 36 import org.jboss.test.web.interfaces.EntityHome; 37 import org.jboss.test.web.util.Util; 38 39 44 public class EntityServlet extends HttpServlet 45 { 46 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 47 throws ServletException , IOException 48 { 49 try 50 { 51 InitialContext ctx = new InitialContext (); 52 Context enc = (Context ) ctx.lookup("java:comp/env"); 53 EntityHome home = (EntityHome) enc.lookup("ejb/Entity"); 54 Entity bean = home.create(12345, 6789); 55 bean.write(7890); 56 bean.read(); 57 bean.remove(); 58 } 59 catch(Exception e) 60 { 61 throw new ServletException ("Failed to call Entity through remote interfaces", e); 62 } 63 response.setContentType("text/html"); 64 PrintWriter out = response.getWriter(); 65 out.println("<html>"); 66 out.println("<head><title>EntityServlet</title></head>"); 67 out.println("<body>Tests passed<br>Time:"+Util.getTime()+"</body>"); 68 out.println("</html>"); 69 out.close(); 70 } 71 72 protected void doGet(HttpServletRequest request, HttpServletResponse response) 73 throws ServletException , IOException 74 { 75 processRequest(request, response); 76 } 77 78 protected void doPost(HttpServletRequest request, HttpServletResponse response) 79 throws ServletException , IOException 80 { 81 processRequest(request, response); 82 } 83 } 84 | Popular Tags |