diff options
Diffstat (limited to 'test-jetty-webapp/src/main/java/com/acme/RegTest.java')
-rw-r--r-- | test-jetty-webapp/src/main/java/com/acme/RegTest.java | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/test-jetty-webapp/src/main/java/com/acme/RegTest.java b/test-jetty-webapp/src/main/java/com/acme/RegTest.java new file mode 100644 index 0000000000..8d99cd11a5 --- /dev/null +++ b/test-jetty-webapp/src/main/java/com/acme/RegTest.java @@ -0,0 +1,194 @@ +// +// ======================================================================== +// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.util.StringUtil; + + + + +/* ------------------------------------------------------------ */ +/** Rego Servlet - tests being accessed from servlet 3.0 programmatic + * configuration. + * + */ +public class RegTest extends HttpServlet +{ + + /* ------------------------------------------------------------ */ + @Override + public void init(ServletConfig config) throws ServletException + { + super.init(config); + } + + /* ------------------------------------------------------------ */ + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + doGet(request, response); + } + + /* ------------------------------------------------------------ */ + @Override + public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException + { + request.setCharacterEncoding("UTF-8"); + PrintWriter pout=null; + + try + { + pout =response.getWriter(); + } + catch(IllegalStateException e) + { + pout=new PrintWriter(new OutputStreamWriter(response.getOutputStream(),"UTF-8")); + } + + try + { + pout.write("<html>\n<body>\n"); + pout.write("<h1>Rego Servlet</h1>\n"); + pout.write("<table width=\"95%\">"); + pout.write("<tr>\n"); + pout.write("<th align=\"right\">getMethod: </th>"); + pout.write("<td>" + notag(request.getMethod())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getContentLength: </th>"); + pout.write("<td>"+Integer.toString(request.getContentLength())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getContentType: </th>"); + pout.write("<td>"+notag(request.getContentType())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getRequestURI: </th>"); + pout.write("<td>"+notag(request.getRequestURI())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getRequestURL: </th>"); + pout.write("<td>"+notag(request.getRequestURL().toString())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getContextPath: </th>"); + pout.write("<td>"+request.getContextPath()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getServletPath: </th>"); + pout.write("<td>"+notag(request.getServletPath())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getPathInfo: </th>"); + pout.write("<td>"+notag(request.getPathInfo())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getPathTranslated: </th>"); + pout.write("<td>"+notag(request.getPathTranslated())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getQueryString: </th>"); + pout.write("<td>"+notag(request.getQueryString())+"</td>"); + pout.write("</tr><tr>\n"); + + pout.write("<th align=\"right\">getProtocol: </th>"); + pout.write("<td>"+request.getProtocol()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getScheme: </th>"); + pout.write("<td>"+request.getScheme()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getServerName: </th>"); + pout.write("<td>"+notag(request.getServerName())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getServerPort: </th>"); + pout.write("<td>"+Integer.toString(request.getServerPort())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getLocalName: </th>"); + pout.write("<td>"+request.getLocalName()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getLocalAddr: </th>"); + pout.write("<td>"+request.getLocalAddr()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getLocalPort: </th>"); + pout.write("<td>"+Integer.toString(request.getLocalPort())+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getRemoteUser: </th>"); + pout.write("<td>"+request.getRemoteUser()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getUserPrincipal: </th>"); + pout.write("<td>"+request.getUserPrincipal()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getRemoteAddr: </th>"); + pout.write("<td>"+request.getRemoteAddr()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getRemoteHost: </th>"); + pout.write("<td>"+request.getRemoteHost()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getRemotePort: </th>"); + pout.write("<td>"+request.getRemotePort()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">getRequestedSessionId: </th>"); + pout.write("<td>"+request.getRequestedSessionId()+"</td>"); + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">isSecure(): </th>"); + pout.write("<td>"+request.isSecure()+"</td>"); + + pout.write("</tr><tr>\n"); + pout.write("<th align=\"right\">isUserInRole(admin): </th>"); + pout.write("<td>"+request.isUserInRole("admin")+"</td>"); + + pout.write("</tr></table>"); + + } + catch (Exception e) + { + getServletContext().log("dump "+e); + } + + + pout.write("</body>\n</html>\n"); + + pout.close(); + } + + + /* ------------------------------------------------------------ */ + @Override + public String getServletInfo() + { + return "Rego Servlet"; + } + + /* ------------------------------------------------------------ */ + @Override + public synchronized void destroy() + { + } + + + private String notag(String s) + { + if (s==null) + return "null"; + s=StringUtil.replace(s,"&","&"); + s=StringUtil.replace(s,"<","<"); + s=StringUtil.replace(s,">",">"); + return s; + } +} |