KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > classloader > scoping > naming > web > LookupServlet


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.classloader.scoping.naming.web;
23
24 import java.io.IOException JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import javax.servlet.http.HttpServlet JavaDoc;
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29 import javax.servlet.ServletConfig JavaDoc;
30 import javax.servlet.ServletException JavaDoc;
31 import javax.naming.InitialContext JavaDoc;
32 import javax.naming.Context JavaDoc;
33
34 import org.jboss.test.classloader.scoping.naming.service.BindValue;
35
36 /** A servlet that reads the bindings under the shared-context jndi context
37  * to test the behavior of jndi lookups across class loading scopes.
38  *
39  * @author Scott.Stark@jboss.org
40  * @version $Revision: 37406 $
41  */

42 public class LookupServlet extends HttpServlet JavaDoc
43 {
44    /**
45     *
46     * @param servletConfig
47     * @throws javax.servlet.ServletException
48     */

49    public void init(ServletConfig JavaDoc servletConfig) throws ServletException JavaDoc
50    {
51       super.init(servletConfig);
52    }
53
54    protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
55       throws ServletException JavaDoc, IOException JavaDoc
56    {
57       processRequest(request, response);
58    }
59
60    protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
61       throws ServletException JavaDoc, IOException JavaDoc
62    {
63       processRequest(request, response);
64    }
65
66    private void processRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
67       throws ServletException JavaDoc, IOException JavaDoc
68    {
69       response.setContentType("text/html");
70       PrintWriter JavaDoc pw = response.getWriter();
71       pw.println("<html><head><title>LookupServlet Scoping Test</title></head>");
72       pw.println("<body><h1>LookupServlet Scoping Test</h1>");
73       pw.println("BindValue.CS: "+BindValue.class.getProtectionDomain().getCodeSource());
74       pw.println("<ul>");
75
76       try
77       {
78          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
79          Context JavaDoc testCtx = (Context JavaDoc) ctx.lookup("shared-context");
80          Integer JavaDoc count = (Integer JavaDoc) testCtx.lookup("KeyCount");
81          for(int n = 0; n < count.intValue(); n ++)
82          {
83             String JavaDoc key = "Key#" + n;
84             BindValue value = (BindValue) testCtx.lookup(key);
85             pw.println("\t<li>"+value.getValue()+"</li>");
86          }
87       }
88       catch (Exception JavaDoc e)
89       {
90          throw new ServletException JavaDoc("Failed to validate shared-context", e);
91       }
92       pw.println("</ul>");
93       pw.println("</body></html>");
94    }
95 }
96
Popular Tags