01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25: import java.io.PrintWriter;
26: import javax.servlet.http.HttpServlet;
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29: import javax.servlet.ServletConfig;
30: import javax.servlet.ServletException;
31: import javax.naming.InitialContext;
32: import javax.naming.Context;
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: 57211 $
41: */
42: public class LookupServlet extends HttpServlet {
43: /**
44: *
45: * @param servletConfig
46: * @throws javax.servlet.ServletException
47: */
48: public void init(ServletConfig servletConfig)
49: throws ServletException {
50: super .init(servletConfig);
51: }
52:
53: protected void doGet(HttpServletRequest request,
54: HttpServletResponse response) throws ServletException,
55: IOException {
56: processRequest(request, response);
57: }
58:
59: protected void doPost(HttpServletRequest request,
60: HttpServletResponse response) throws ServletException,
61: IOException {
62: processRequest(request, response);
63: }
64:
65: private void processRequest(HttpServletRequest request,
66: HttpServletResponse response) throws ServletException,
67: IOException {
68: response.setContentType("text/html");
69: PrintWriter pw = response.getWriter();
70: pw
71: .println("<html><head><title>LookupServlet Scoping Test</title></head>");
72: pw.println("<body><h1>LookupServlet Scoping Test</h1>");
73: pw
74: .println("BindValue.CS: "
75: + BindValue.class.getProtectionDomain()
76: .getCodeSource());
77: pw.println("<ul>");
78:
79: try {
80: InitialContext ctx = new InitialContext();
81: Context testCtx = (Context) ctx.lookup("shared-context");
82: Integer count = (Integer) testCtx.lookup("KeyCount");
83: for (int n = 0; n < count.intValue(); n++) {
84: String key = "Key#" + n;
85: BindValue value = (BindValue) testCtx.lookup(key);
86: pw.println("\t<li>" + value.getValue() + "</li>");
87: }
88: } catch (Exception e) {
89: throw new ServletException(
90: "Failed to validate shared-context", e);
91: }
92: pw.println("</ul>");
93: pw.println("</body></html>");
94: }
95: }
|