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.web.servlets;
23:
24: import java.io.IOException;
25: import java.io.PrintWriter;
26: import java.security.Principal;
27: import javax.servlet.RequestDispatcher;
28: import javax.servlet.ServletConfig;
29: import javax.servlet.ServletException;
30: import javax.servlet.http.HttpServlet;
31: import javax.servlet.http.HttpServletRequest;
32: import javax.servlet.http.HttpServletResponse;
33:
34: /**
35: *
36: * @author Scott.Stark@jboss.org
37: * @version $Revision: 57211 $
38: */
39: public class IncludeServlet extends HttpServlet {
40: protected void processRequest(HttpServletRequest request,
41: HttpServletResponse response) throws ServletException,
42: IOException {
43: Principal user = request.getUserPrincipal();
44: boolean isSecure = request.getRemoteUser() != null;
45: response.setBufferSize(2048);
46: PrintWriter out = response.getWriter();
47: response.setContentType("text/html");
48: out.println("<html>");
49: out.println("<head><title>IncludeServlet</title></head>");
50: out.println("<h1>IncludeServlet Accessed</h1>");
51: out.println("<body>You have accessed this servlet as user:"
52: + user);
53: try {
54: out
55: .println("Accessing /restricted/SecureEJBAccess?includeHead=false<br>");
56: RequestDispatcher rd = request
57: .getRequestDispatcher("/restricted/SecureEJBAccess?includeHead=false");
58: rd.include(request, response);
59: } catch (ServletException e) {
60: if (isSecure == true)
61: throw e;
62: out
63: .println("Access to /restricted/SecureEJBAccess failed as expected<br>");
64: }
65:
66: out
67: .println("Accessing /UnsecureEJBAccess?includeHead=false<br>");
68: RequestDispatcher rd = request
69: .getRequestDispatcher("/UnsecureEJBAccess?includeHead=false");
70: rd.include(request, response);
71: out.println("</body></html>");
72: out.close();
73: }
74:
75: protected void doGet(HttpServletRequest request,
76: HttpServletResponse response) throws ServletException,
77: IOException {
78: processRequest(request, response);
79: }
80:
81: protected void doPost(HttpServletRequest request,
82: HttpServletResponse response) throws ServletException,
83: IOException {
84: processRequest(request, response);
85: }
86:
87: }
|