List of usage examples for javax.servlet.http Cookie getName
public String getName()
From source file:ed.net.CookieJar.java
/** * Performs RFC 2109 {@link Cookie} validation * /*from ww w .jav a2 s . c o m*/ * @param url the source of the cookie * @param cookie The cookie to validate. * @throws IllegalArgumentException if an exception occurs during validation */ private void validate(URL url, Cookie cookie) { String host = url.getHost(); int port = url.getPort(); String path = url.getPath(); // based on org.apache.commons.httpclient.cookie.CookieSpecBase if (host == null) { throw new IllegalArgumentException("Host of origin may not be null"); } if (host.trim().equals("")) { throw new IllegalArgumentException("Host of origin may not be blank"); } if (port < 0) port = 80; if (path == null) { throw new IllegalArgumentException("Path of origin may not be null."); } if (path.trim().equals("")) { path = "/"; } host = host.toLowerCase(); // check version if (cookie.getVersion() < 0) { throw new MalformedCookieException("Illegal version number " + cookie.getValue()); } // security check... we musn't allow the server to give us an // invalid domain scope // Validate the cookies domain attribute. NOTE: Domains without // any dots are allowed to support hosts on private LANs that don't // have DNS names. Since they have no dots, to domain-match the // request-host and domain must be identical for the cookie to sent // back to the origin-server. if (host.indexOf(".") >= 0) { // Not required to have at least two dots. RFC 2965. // A Set-Cookie2 with Domain=ajax.com will be accepted. // domain must match host if (!host.endsWith(cookie.getDomain())) { String s = cookie.getDomain(); if (s.startsWith(".")) { s = s.substring(1, s.length()); } if (!host.equals(s)) { throw new MalformedCookieException("Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\""); } } } else { if (!host.equals(cookie.getDomain())) { throw new MalformedCookieException("Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\""); } } // another security check... we musn't allow the server to give us a // cookie that doesn't match this path if (!path.startsWith(cookie.getPath())) { throw new MalformedCookieException( "Illegal path attribute \"" + cookie.getPath() + "\". Path of origin: \"" + path + "\""); } // Validate using RFC 2109 // -------------------------------------------------------- if (cookie.getName().indexOf(' ') != -1) { throw new MalformedCookieException("Cookie name may not contain blanks"); } if (cookie.getName().startsWith("$")) { throw new MalformedCookieException("Cookie name may not start with $"); } if (cookie.getDomain() != null && (!cookie.getDomain().equals(host))) { // domain must start with dot if (!cookie.getDomain().startsWith(".")) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot"); } // domain must have at least one embedded dot int dotIndex = cookie.getDomain().indexOf('.', 1); if (dotIndex < 0 || dotIndex == cookie.getDomain().length() - 1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: domain must contain an embedded dot"); } host = host.toLowerCase(); if (!host.endsWith(cookie.getDomain())) { throw new MalformedCookieException("Illegal domain attribute \"" + cookie.getDomain() + "\". Domain of origin: \"" + host + "\""); } // host minus domain may not contain any dots String hostWithoutDomain = host.substring(0, host.length() - cookie.getDomain().length()); if (hostWithoutDomain.indexOf('.') != -1) { throw new MalformedCookieException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: host minus domain may not contain any dots"); } } }
From source file:com.lp.webapp.zemecs.CommandZE.java
private String getCookieValue(String key, HttpServletRequest request) { if (request != null && request.getCookies() != null) { for (int i = 0; i < request.getCookies().length; i++) { Cookie cookie = request.getCookies()[i]; if (cookie.getName().equals(key)) { return cookie.getValue(); }//from w w w . j av a 2 s. c om } } return null; }
From source file:och.front.service.FrontAppTest.java
private void assertEmptyRemCookie() { boolean foundEmptyRemCookie = false; for (Cookie cookie : resp.cookies) { if (cookie.getName().equals(REM_TOKEN)) { assertEquals("", cookie.getValue()); assertEquals(0, cookie.getMaxAge()); foundEmptyRemCookie = true; break; }//from www . ja v a 2 s. com } assertTrue(String.valueOf(resp.cookies), foundEmptyRemCookie); }
From source file:au.org.emii.portal.composer.MapComposer.java
public String getCookieValue(String cookieName) { try {/*ww w. j a v a 2 s.c om*/ for (Cookie c : ((HttpServletRequest) Executions.getCurrent().getNativeRequest()).getCookies()) { if (c.getName().equals(cookieName)) { return c.getValue(); } } } catch (Exception e) { //does not matter if it does not work } return null; }
From source file:och.front.service.FrontAppTest.java
private void test_create_restore_remMe() throws Exception { resetWeb();/*www . ja va 2 s . com*/ //try restore with no cookie assertNull(security.restoreUserSession(req, resp)); //first login asyncFutures.clear(); security.createUserSession(req, resp, new LoginUserReq(mail1, psw1, true)); asyncFutures.get(0).get(); assertNotNull(req.session.getAttribute(SESSION_OBJ_KEY)); assertEquals(1, resp.cookies.size()); Cookie cookie1 = resp.cookies.get(0); assertEquals(REM_TOKEN, cookie1.getName()); //try restore with full session and NO cookie assertNull(security.restoreUserSession(req, resp)); //try restore with empty session and NO cookie req.clearSessionAttrs(); assertNull(security.restoreUserSession(req, resp)); //restore session with cookie asyncFutures.clear(); req.clearSessionAttrs(); req.setCookies(cookie1); resp.clearCookies(); assertNotNull(security.restoreUserSession(req, resp)); assertNotNull(req.session.getAttribute(SESSION_OBJ_KEY)); asyncFutures.get(0).get(); //after restored it has new cookie assertEquals(1, resp.cookies.size()); Cookie cookie_AfterResore = resp.cookies.get(0); //try restore with old cookie req.clearSessionAttrs(); req.clearCookies(); req.setCookies(cookie1); resp.clearCookies(); assertNull(security.restoreUserSession(req, resp)); //restore with new cookie req.clearCookies(); req.setCookies(cookie_AfterResore); resp.clearCookies(); assertNotNull(security.restoreUserSession(req, resp)); asyncFutures.get(0).get(); cookie1 = resp.cookies.get(0); //create agian with exists session assertNotNull(req.session.getAttribute(SESSION_OBJ_KEY)); try { security.createUserSession(req, resp, new LoginUserReq(login1, psw1, true)); fail_exception_expected(); } catch (UserSessionAlreadyExistsException e) { //ok } //create again with clear inputs //it will be TWO tokens in DB asyncFutures.clear(); req.clearSessionAttrs(); req.clearCookies(); resp.clearCookies(); security.createUserSession(req, resp, new LoginUserReq(mail1, psw1, true)); asyncFutures.get(0).get(); Cookie cookie2 = resp.cookies.get(0); assertFalse(cookie1.getValue().equals(cookie2.getValue())); // try to restore with old cookie req.clearSessionAttrs(); req.setCookies(cookie1); assertNotNull(security.restoreUserSession(req, resp)); // restore with new cookie req.setCookies(cookie2); req.clearSessionAttrs(); assertNotNull(security.restoreUserSession(req, resp)); }
From source file:de.innovationgate.wgpublisher.WGPDispatcher.java
public Map<String, de.innovationgate.wga.server.api.Cookie> fetchHttpCookies( javax.servlet.http.HttpServletRequest request) { Map<String, de.innovationgate.wga.server.api.Cookie> cookies = new HashMap<String, de.innovationgate.wga.server.api.Cookie>(); Cookie[] rawCookies = request.getCookies(); if (rawCookies != null) { for (javax.servlet.http.Cookie c : rawCookies) { cookies.put(c.getName(), new de.innovationgate.wga.server.api.Cookie(c)); }/*from www. j a v a 2s . c om*/ } return cookies; }
From source file:de.innovationgate.wgpublisher.WGPDispatcher.java
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { if (!isServePages()) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Website is currently updating configuration. Please try again later."); return;//from w w w. j av a 2 s. c o m } Date startDate = new Date(); if (this._contextPath == null) { this._contextPath = request.getContextPath(); this._listenPort = request.getServerPort(); } WGARequestInformation reqInfo = (WGARequestInformation) request .getAttribute(WGARequestInformation.REQUEST_ATTRIBUTENAME); try { // Parse request WGPRequestPath path = WGPRequestPath.parseRequest(this, request, response); request.setAttribute(WGACore.ATTRIB_REQUESTPATH, path); // If database login failed or access was denied exit immediately if (!path.isProceedRequest()) { return; } // Set access logging for this request if (path.getDatabase() != null) { String accessLoggingEnabled = (String) path.getDatabase() .getAttribute(WGACore.DBATTRIB_ENABLE_ACCESSLOGGING); if (accessLoggingEnabled != null) { if (reqInfo != null) { reqInfo.setLoggingEnabled(Boolean.parseBoolean(accessLoggingEnabled)); } } } int iPathType = path.getPathType(); // Treatment of special URL types String dbKey = path.getDatabaseKey(); if (iPathType == WGPRequestPath.TYPE_INVALID) { throw new HttpErrorException(404, "Invalid path: " + path.getBasePath(), dbKey); } if (iPathType == WGPRequestPath.TYPE_INVALID_DB) { throw new HttpErrorException(404, "Specified application '" + dbKey + "' is unknown", null); } if (iPathType == WGPRequestPath.TYPE_UNKNOWN_CONTENT) { sendNoContentNotification(path, request, response, path.getDatabase()); return; } if (iPathType == WGPRequestPath.TYPE_GOTO_HOMEPAGE) { iPathType = determineHomepage(request, path, iPathType); } if (iPathType == WGPRequestPath.TYPE_UNAVAILABLE_DB) { throw new HttpErrorException(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "The website is currently unavailable", path.getDatabaseKey()); } if (iPathType == WGPRequestPath.TYPE_UNDEFINED_HOMEPAGE) { throw new HttpErrorException( HttpServletResponse.SC_NOT_FOUND, "No home page was defined for app '" + path.getDatabaseKey() + "'. Please specify an explicit content path.", path.getDatabaseKey()); } if (iPathType == WGPRequestPath.TYPE_TMLDEBUG) { _tmlDebugger.performDebugMode(request, response, request.getSession()); return; } if (iPathType == WGPRequestPath.TYPE_JOBLOG) { sendJobLog(request, response, request.getSession()); return; } if (iPathType == WGPRequestPath.TYPE_LOGOUT) { WGDatabase db = (WGDatabase) _core.getContentdbs().get(dbKey); String domain = (String) db.getAttribute(WGACore.DBATTRIB_DOMAIN); _core.logout(domain, request.getSession(), request, response, true); removeSessionCookie(response, request.getSession(), db); iPathType = WGPRequestPath.TYPE_REDIRECT; } if (iPathType == WGPRequestPath.TYPE_FAVICON) { String faviconPath = determineFavicon(request); if (faviconPath != null) { iPathType = WGPRequestPath.TYPE_REDIRECT; path.setResourcePath(faviconPath); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Favicon not defined"); return; } } if (iPathType == WGPRequestPath.TYPE_TMLFORM) { dispatchTmlFormRequest(path, request, response); return; } // Treatment of base URL Types if (iPathType == WGPRequestPath.TYPE_REDIRECT) { String url = path.getResourcePath(); if (path.appendQueryString() == true && request.getQueryString() != null && !request.getQueryString().equals("")) { if (url.indexOf("?") != -1) { url += "&" + request.getQueryString(); } else { url += "?" + request.getQueryString(); } } if (path.isPermanentRedirect()) { sendPermanentRedirect(response, url); } else { sendRedirect(request, response, url); } } else if (iPathType != WGPRequestPath.TYPE_RESOURCE && iPathType != WGPRequestPath.TYPE_STATICTML && !_core.getContentdbs().containsKey(path.getDatabaseKey())) { throw new HttpErrorException(404, "Database '" + dbKey + "' is unknown", null); } else { String requestMethod = request.getMethod().toLowerCase(); switch (iPathType) { case (WGPRequestPath.TYPE_TML): case (WGPRequestPath.TYPE_TITLE_PATH): // Fetch the redirect cookie Cookie lastRedirectCookie = null; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(COOKIE_LASTREDIRECT)) { lastRedirectCookie = cookie; break; } } } // If path is not complete redirect it to the complete path, if possible. Set redirect cookie to prevent endless redirections if (!path.isCompletePath()) { String redirectPath = path.expandToCompletePath(request); if (isRedirectable(request, redirectPath, lastRedirectCookie)) { lastRedirectCookie = new WGCookie(COOKIE_LASTREDIRECT, Hex.encodeHexString(redirectPath.getBytes("UTF-8"))); lastRedirectCookie.setMaxAge(-1); lastRedirectCookie.setPath("/"); ((WGCookie) lastRedirectCookie).addCookieHeader(response); sendRedirect(request, response, redirectPath); break; } } // Delete redirect cookie when exists on normal dispatching if (lastRedirectCookie != null) { lastRedirectCookie = new WGCookie(COOKIE_LASTREDIRECT, ""); lastRedirectCookie.setMaxAge(0); lastRedirectCookie.setPath("/"); ((WGCookie) lastRedirectCookie).addCookieHeader(response); } // Dispatch dispatchTmlRequest(path, request, response, startDate); break; case (WGPRequestPath.TYPE_FILE): dispatchFileRequest(path, request, response); break; case (WGPRequestPath.TYPE_CSS): case (WGPRequestPath.TYPE_JS): dispatchCssjsRequest(path, request, response); break; case (WGPRequestPath.TYPE_RESOURCE): dispatchResourceRequest(path, request, response); break; case (WGPRequestPath.TYPE_STATICTML): dispatchStaticTmlRequest(path, request, response); break; default: throw new HttpErrorException(500, "Invalid url format", dbKey); } } // moved from finally block to ensure errorpage can be displayed commitResponse(response); } catch (ClientAccessException exc) { response.sendError(403, exc.getMessage()); } catch (AjaxFailureException exc) { handleAjaxFailure(exc, request, response); } catch (HttpErrorException exc) { request.setAttribute(WGACore.ATTRIB_EXCEPTION, exc); ProblemOccasion occ = new PathDispatchingOccasion(request, exc.getDbHint()); _core.getProblemRegistry().addProblem( Problem.create(occ, "dispatching.http404#" + request.getRequestURL(), ProblemSeverity.LOW)); if (!response.isCommitted()) { // throw exception to display errorpage - with senderror() the // applicationserver use the buildin errorpage if (exc.getCode() == HttpServletResponse.SC_NOT_FOUND || exc.getCode() == HttpServletResponse.SC_FORBIDDEN || exc.getCode() == HttpServletResponse.SC_PRECONDITION_FAILED) { response.sendError(exc.getCode(), exc.getMessage()); } else { _log.error("Exception in processing request from " + request.getRemoteAddr() + " to URL " + String.valueOf(request.getRequestURL())); throw new ServletException(exc); } } } catch (SocketException exc) { _log.warn("Socket Exception: " + exc.getMessage()); } catch (Exception exc) { _log.error("Exception in processing of request URL " + String.valueOf(request.getRequestURL()), exc); request.setAttribute(WGACore.ATTRIB_EXCEPTION, exc); throw new ServletException(exc); } catch (Error err) { _log.error("Error in processing of request URL " + String.valueOf(request.getRequestURL()), err); request.setAttribute(WGACore.ATTRIB_EXCEPTION, err); throw new ServletException(err); } finally { if (reqInfo != null) { reqInfo.setCommited(true); } } }
From source file:net.lightbody.bmp.proxy.jetty.servlet.Dump.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("Dump", this); request.setCharacterEncoding("ISO_8859_1"); getServletContext().setAttribute("Dump", this); String info = request.getPathInfo(); if (info != null && info.endsWith("Exception")) { try {//w w w.j a v a2 s . c o m throw (Throwable) (Loader.loadClass(this.getClass(), info.substring(1)).newInstance()); } catch (Throwable th) { throw new ServletException(th); } } String redirect = request.getParameter("redirect"); if (redirect != null && redirect.length() > 0) { response.getOutputStream().println("THIS SHOULD NOT BE SEEN!"); response.sendRedirect(redirect); response.getOutputStream().println("THIS SHOULD NOT BE SEEN!"); return; } String error = request.getParameter("error"); if (error != null && error.length() > 0) { response.getOutputStream().println("THIS SHOULD NOT BE SEEN!"); response.sendError(Integer.parseInt(error)); response.getOutputStream().println("THIS SHOULD NOT BE SEEN!"); return; } String length = request.getParameter("length"); if (length != null && length.length() > 0) { response.setContentLength(Integer.parseInt(length)); } String buffer = request.getParameter("buffer"); if (buffer != null && buffer.length() > 0) response.setBufferSize(Integer.parseInt(buffer)); request.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); if (info != null && info.indexOf("Locale/") >= 0) { try { String locale_name = info.substring(info.indexOf("Locale/") + 7); Field f = java.util.Locale.class.getField(locale_name); response.setLocale((Locale) f.get(null)); } catch (Exception e) { LogSupport.ignore(log, e); response.setLocale(Locale.getDefault()); } } String cn = request.getParameter("cookie"); String cv = request.getParameter("value"); String v = request.getParameter("version"); if (cn != null && cv != null) { Cookie cookie = new Cookie(cn, cv); cookie.setComment("Cookie from dump servlet"); if (v != null) { cookie.setMaxAge(300); cookie.setPath("/"); cookie.setVersion(Integer.parseInt(v)); } response.addCookie(cookie); } String pi = request.getPathInfo(); if (pi != null && pi.startsWith("/ex")) { OutputStream out = response.getOutputStream(); out.write("</H1>This text should be reset</H1>".getBytes()); if ("/ex0".equals(pi)) throw new ServletException("test ex0", new Throwable()); if ("/ex1".equals(pi)) throw new IOException("test ex1"); if ("/ex2".equals(pi)) throw new UnavailableException("test ex2"); if ("/ex3".equals(pi)) throw new HttpException(501); } PrintWriter pout = response.getWriter(); Page page = null; try { page = new Page(); page.title("Dump Servlet"); page.add(new Heading(1, "Dump Servlet")); Table table = new Table(0).cellPadding(0).cellSpacing(0); page.add(table); table.newRow(); table.addHeading("getMethod: ").cell().right(); table.addCell("" + request.getMethod()); table.newRow(); table.addHeading("getContentLength: ").cell().right(); table.addCell(Integer.toString(request.getContentLength())); table.newRow(); table.addHeading("getContentType: ").cell().right(); table.addCell("" + request.getContentType()); table.newRow(); table.addHeading("getCharacterEncoding: ").cell().right(); table.addCell("" + request.getCharacterEncoding()); table.newRow(); table.addHeading("getRequestURI: ").cell().right(); table.addCell("" + request.getRequestURI()); table.newRow(); table.addHeading("getRequestURL: ").cell().right(); table.addCell("" + request.getRequestURL()); table.newRow(); table.addHeading("getContextPath: ").cell().right(); table.addCell("" + request.getContextPath()); table.newRow(); table.addHeading("getServletPath: ").cell().right(); table.addCell("" + request.getServletPath()); table.newRow(); table.addHeading("getPathInfo: ").cell().right(); table.addCell("" + request.getPathInfo()); table.newRow(); table.addHeading("getPathTranslated: ").cell().right(); table.addCell("" + request.getPathTranslated()); table.newRow(); table.addHeading("getQueryString: ").cell().right(); table.addCell("" + request.getQueryString()); table.newRow(); table.addHeading("getProtocol: ").cell().right(); table.addCell("" + request.getProtocol()); table.newRow(); table.addHeading("getScheme: ").cell().right(); table.addCell("" + request.getScheme()); table.newRow(); table.addHeading("getServerName: ").cell().right(); table.addCell("" + request.getServerName()); table.newRow(); table.addHeading("getServerPort: ").cell().right(); table.addCell("" + Integer.toString(request.getServerPort())); table.newRow(); table.addHeading("getLocalName: ").cell().right(); table.addCell("" + request.getLocalName()); table.newRow(); table.addHeading("getLocalAddr: ").cell().right(); table.addCell("" + request.getLocalAddr()); table.newRow(); table.addHeading("getLocalPort: ").cell().right(); table.addCell("" + Integer.toString(request.getLocalPort())); table.newRow(); table.addHeading("getRemoteUser: ").cell().right(); table.addCell("" + request.getRemoteUser()); table.newRow(); table.addHeading("getRemoteAddr: ").cell().right(); table.addCell("" + request.getRemoteAddr()); table.newRow(); table.addHeading("getRemoteHost: ").cell().right(); table.addCell("" + request.getRemoteHost()); table.newRow(); table.addHeading("getRemotePort: ").cell().right(); table.addCell("" + request.getRemotePort()); table.newRow(); table.addHeading("getRequestedSessionId: ").cell().right(); table.addCell("" + request.getRequestedSessionId()); table.newRow(); table.addHeading("isSecure(): ").cell().right(); table.addCell("" + request.isSecure()); table.newRow(); table.addHeading("isUserInRole(admin): ").cell().right(); table.addCell("" + request.isUserInRole("admin")); table.newRow(); table.addHeading("getLocale: ").cell().right(); table.addCell("" + request.getLocale()); Enumeration locales = request.getLocales(); while (locales.hasMoreElements()) { table.newRow(); table.addHeading("getLocales: ").cell().right(); table.addCell(locales.nextElement()); } table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Other HTTP Headers") .attribute("COLSPAN", "2").left(); Enumeration h = request.getHeaderNames(); String name; while (h.hasMoreElements()) { name = (String) h.nextElement(); Enumeration h2 = request.getHeaders(name); while (h2.hasMoreElements()) { String hv = (String) h2.nextElement(); table.newRow(); table.addHeading(name + ": ").cell().right(); table.addCell(hv); } } table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Request Parameters") .attribute("COLSPAN", "2").left(); h = request.getParameterNames(); while (h.hasMoreElements()) { name = (String) h.nextElement(); table.newRow(); table.addHeading(name + ": ").cell().right(); table.addCell(request.getParameter(name)); String[] values = request.getParameterValues(name); if (values == null) { table.newRow(); table.addHeading(name + " Values: ").cell().right(); table.addCell("NULL!!!!!!!!!"); } else if (values.length > 1) { for (int i = 0; i < values.length; i++) { table.newRow(); table.addHeading(name + "[" + i + "]: ").cell().right(); table.addCell(values[i]); } } } table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Cookies").attribute("COLSPAN", "2").left(); Cookie[] cookies = request.getCookies(); for (int i = 0; cookies != null && i < cookies.length; i++) { Cookie cookie = cookies[i]; table.newRow(); table.addHeading(cookie.getName() + ": ").cell().attribute("VALIGN", "TOP").right(); table.addCell(cookie.getValue()); } /* ------------------------------------------------------------ */ table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Request Attributes") .attribute("COLSPAN", "2").left(); Enumeration a = request.getAttributeNames(); while (a.hasMoreElements()) { name = (String) a.nextElement(); table.newRow(); table.addHeading(name + ": ").cell().attribute("VALIGN", "TOP").right(); table.addCell("<pre>" + toString(request.getAttribute(name)) + "</pre>"); } /* ------------------------------------------------------------ */ table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Servlet InitParameters") .attribute("COLSPAN", "2").left(); a = getInitParameterNames(); while (a.hasMoreElements()) { name = (String) a.nextElement(); table.newRow(); table.addHeading(name + ": ").cell().attribute("VALIGN", "TOP").right(); table.addCell("<pre>" + toString(getInitParameter(name)) + "</pre>"); } table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Context InitParameters") .attribute("COLSPAN", "2").left(); a = getServletContext().getInitParameterNames(); while (a.hasMoreElements()) { name = (String) a.nextElement(); table.newRow(); table.addHeading(name + ": ").cell().attribute("VALIGN", "TOP").right(); table.addCell("<pre>" + toString(getServletContext().getInitParameter(name)) + "</pre>"); } table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Context Attributes") .attribute("COLSPAN", "2").left(); a = getServletContext().getAttributeNames(); while (a.hasMoreElements()) { name = (String) a.nextElement(); table.newRow(); table.addHeading(name + ": ").cell().attribute("VALIGN", "TOP").right(); table.addCell("<pre>" + toString(getServletContext().getAttribute(name)) + "</pre>"); } if (request.getContentType() != null && request.getContentType().startsWith("multipart/form-data") && request.getContentLength() < 1000000) { MultiPartRequest multi = new MultiPartRequest(request); String[] parts = multi.getPartNames(); table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Multi-part content") .attribute("COLSPAN", "2").left(); for (int p = 0; p < parts.length; p++) { name = parts[p]; table.newRow(); table.addHeading(name + ": ").cell().attribute("VALIGN", "TOP").right(); table.addCell("<pre>" + multi.getString(parts[p]) + "</pre>"); } } String res = request.getParameter("resource"); if (res != null && res.length() > 0) { table.newRow(); table.newHeading().cell().nest(new Font(2, true)).add("<BR>Get Resource: " + res) .attribute("COLSPAN", "2").left(); table.newRow(); table.addHeading("this.getClass(): ").cell().right(); table.addCell("" + this.getClass().getResource(res)); table.newRow(); table.addHeading("this.getClass().getClassLoader(): ").cell().right(); table.addCell("" + this.getClass().getClassLoader().getResource(res)); table.newRow(); table.addHeading("Thread.currentThread().getContextClassLoader(): ").cell().right(); table.addCell("" + Thread.currentThread().getContextClassLoader().getResource(res)); table.newRow(); table.addHeading("getServletContext(): ").cell().right(); try { table.addCell("" + getServletContext().getResource(res)); } catch (Exception e) { table.addCell("" + e); } } /* ------------------------------------------------------------ */ page.add(Break.para); page.add(new Heading(1, "Request Wrappers")); ServletRequest rw = request; int w = 0; while (rw != null) { page.add((w++) + ": " + rw.getClass().getName() + "<br/>"); if (rw instanceof HttpServletRequestWrapper) rw = ((HttpServletRequestWrapper) rw).getRequest(); else if (rw instanceof ServletRequestWrapper) rw = ((ServletRequestWrapper) rw).getRequest(); else rw = null; } page.add(Break.para); page.add(new Heading(1, "International Characters")); page.add("Directly encoced: Drst<br/>"); page.add("HTML reference: Dürst<br/>"); page.add("Decimal (252) 8859-1: Dürst<br/>"); page.add("Hex (xFC) 8859-1: Dürst<br/>"); page.add( "Javascript unicode (00FC) : <script language='javascript'>document.write(\"D\u00FCrst\");</script><br/>"); page.add(Break.para); page.add(new Heading(1, "Form to generate GET content")); TableForm tf = new TableForm(response.encodeURL(getURI(request))); tf.method("GET"); tf.addTextField("TextField", "TextField", 20, "value"); tf.addButton("Action", "Submit"); page.add(tf); page.add(Break.para); page.add(new Heading(1, "Form to generate POST content")); tf = new TableForm(response.encodeURL(getURI(request))); tf.method("POST"); tf.addTextField("TextField", "TextField", 20, "value"); Select select = tf.addSelect("Select", "Select", true, 3); select.add("ValueA"); select.add("ValueB1,ValueB2"); select.add("ValueC"); tf.addButton("Action", "Submit"); page.add(tf); page.add(new Heading(1, "Form to upload content")); tf = new TableForm(response.encodeURL(getURI(request))); tf.method("POST"); tf.attribute("enctype", "multipart/form-data"); tf.addFileField("file", "file"); tf.addButton("Upload", "Upload"); page.add(tf); page.add(new Heading(1, "Form to get Resource")); tf = new TableForm(response.encodeURL(getURI(request))); tf.method("POST"); tf.addTextField("resource", "resource", 20, ""); tf.addButton("Action", "getResource"); page.add(tf); } catch (Exception e) { log.warn(LogSupport.EXCEPTION, e); } page.write(pout); String data = request.getParameter("data"); if (data != null && data.length() > 0) { int d = Integer.parseInt(data); while (d > 0) { pout.println("1234567890123456789012345678901234567890123456789\n"); d = d - 50; } } pout.close(); if (pi != null) { if ("/ex4".equals(pi)) throw new ServletException("test ex4", new Throwable()); if ("/ex5".equals(pi)) throw new IOException("test ex5"); if ("/ex6".equals(pi)) throw new UnavailableException("test ex6"); if ("/ex7".equals(pi)) throw new HttpException(501); } request.getInputStream().close(); }