1 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 42 public class LookupServlet extends HttpServlet 43 { 44 49 public void init(ServletConfig servletConfig) throws ServletException 50 { 51 super.init(servletConfig); 52 } 53 54 protected void doGet(HttpServletRequest request, HttpServletResponse response) 55 throws ServletException , IOException 56 { 57 processRequest(request, response); 58 } 59 60 protected void doPost(HttpServletRequest request, HttpServletResponse response) 61 throws ServletException , IOException 62 { 63 processRequest(request, response); 64 } 65 66 private void processRequest(HttpServletRequest request, HttpServletResponse response) 67 throws ServletException , IOException 68 { 69 response.setContentType("text/html"); 70 PrintWriter 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 ctx = new InitialContext (); 79 Context testCtx = (Context ) ctx.lookup("shared-context"); 80 Integer count = (Integer ) testCtx.lookup("KeyCount"); 81 for(int n = 0; n < count.intValue(); n ++) 82 { 83 String key = "Key#" + n; 84 BindValue value = (BindValue) testCtx.lookup(key); 85 pw.println("\t<li>"+value.getValue()+"</li>"); 86 } 87 } 88 catch (Exception e) 89 { 90 throw new ServletException ("Failed to validate shared-context", e); 91 } 92 pw.println("</ul>"); 93 pw.println("</body></html>"); 94 } 95 } 96 | Popular Tags |