KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > web > servlets > EntityFacadeServlet


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.web.servlets;
23
24 import java.io.IOException JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import javax.naming.Context JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.servlet.ServletException JavaDoc;
29 import javax.servlet.http.HttpServlet JavaDoc;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32 import org.jboss.test.web.interfaces.EntityFacade;
33 import org.jboss.test.web.interfaces.EntityFacadeHome;
34 import org.jboss.test.web.util.Util;
35
36 /** A servlet that accesses an entity EJB
37
38 @author Scott.Stark@jboss.org
39 @version $Revision: 37755 $
40 */

41 public class EntityFacadeServlet extends HttpServlet JavaDoc
42 {
43     protected void processRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
44         throws ServletException JavaDoc, IOException JavaDoc
45     {
46         try
47         {
48             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
49             Context JavaDoc enc = (Context JavaDoc) ctx.lookup("java:comp/env");
50             EntityFacadeHome home = (EntityFacadeHome) enc.lookup("ejb/EntityFacade");
51             EntityFacade bean = home.create();
52             bean.write(7890, true);
53             bean.write(7890, false);
54             bean.remove();
55         }
56         catch(Exception JavaDoc e)
57         {
58             throw new ServletException JavaDoc("Failed to call EntityFacade through remote interfaces", e);
59         }
60         response.setContentType("text/html");
61         PrintWriter JavaDoc out = response.getWriter();
62         out.println("<html>");
63         out.println("<head><title>EntityFacadeServlet</title></head>");
64         out.println("<body>Tests passed<br>Time:"+Util.getTime()+"</body>");
65         out.println("</html>");
66         out.close();
67     }
68
69     protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
70         throws ServletException JavaDoc, IOException JavaDoc
71     {
72         processRequest(request, response);
73     }
74
75     protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
76         throws ServletException JavaDoc, IOException JavaDoc
77     {
78         processRequest(request, response);
79     }
80 }
81
Popular Tags