📄 warprequesthandler.java
字号:
} catch (Exception e) { logger.log(e); } request.finishRequest(); response.finishResponse(); if (Constants.DEBUG) logger.debug("Request has been processed"); break; } default: { String msg="Invalid packet "+packet.getType(); logger.log(msg); packet.reset(); packet.setType(Constants.TYPE_FATAL); packet.writeString(msg); connection.send(packet); return(false); } } } } private void processUri(WarpLogger logger, WarpRequest req, String uri) { // Parse any requested session ID out of the request URI int semicolon = uri.indexOf(match); if (semicolon >= 0) { String rest = uri.substring(semicolon + match.length()); int semicolon2 = rest.indexOf(';'); if (semicolon2 >= 0) { req.setRequestedSessionId(rest.substring(0, semicolon2)); rest = rest.substring(semicolon2); } else { req.setRequestedSessionId(rest); rest = ""; } req.setRequestedSessionURL(true); uri = uri.substring(0, semicolon) + rest; if (Constants.DEBUG) { logger.log("Requested URL session id is " + ((HttpServletRequest) req.getRequest()) .getRequestedSessionId()); } } else { req.setRequestedSessionId(null); req.setRequestedSessionURL(false); } req.setRequestURI(uri); } private void processHeader(WarpLogger logger, WarpRequest req, String name, String value) { if (Constants.DEBUG) logger.debug("Request header "+name+": "+value); if ("cookie".equalsIgnoreCase(name)) { Cookie cookies[] = RequestUtil.parseCookieHeader(value); for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals (Globals.SESSION_COOKIE_NAME)) { // Override anything requested in the URL if (!req.isRequestedSessionIdFromCookie()) { // Accept only the first session id cookie req.setRequestedSessionId (cookies[i].getValue()); req.setRequestedSessionCookie(true); req.setRequestedSessionURL(false); if (Constants.DEBUG) { logger.debug("Requested cookie session id is " + ((HttpServletRequest) req.getRequest()) .getRequestedSessionId()); } } } if (Constants.DEBUG) { logger.debug("Adding cookie "+cookies[i].getName()+"="+ cookies[i].getValue()); } req.addCookie(cookies[i]); } } if (name.equalsIgnoreCase("Accept-Language")) parseAcceptLanguage(logger,req,value); if (name.equalsIgnoreCase("Authorization")) req.setAuthorization(value); req.addHeader(name,value); } /** * Parse the value of an <code>Accept-Language</code> header, and add * the corresponding Locales to the current request. * * @param value The value of the <code>Accept-Language</code> header. */ private void parseAcceptLanguage(WarpLogger logger, WarpRequest request, String value) { // Store the accumulated languages that have been requested in // a local collection, sorted by the quality value (so we can // add Locales in descending order). The values will be ArrayLists // containing the corresponding Locales to be added TreeMap locales = new TreeMap(); // Preprocess the value to remove all whitespace int white = value.indexOf(' '); if (white < 0) white = value.indexOf('\t'); if (white >= 0) { StringBuffer sb = new StringBuffer(); int len = value.length(); for (int i = 0; i < len; i++) { char ch = value.charAt(i); if ((ch != ' ') && (ch != '\t')) sb.append(ch); } value = sb.toString(); } // Process each comma-delimited language specification parser.setString(value); // ASSERT: parser is available to us int length = parser.getLength(); while (true) { // Extract the next comma-delimited entry int start = parser.getIndex(); if (start >= length) break; int end = parser.findChar(','); String entry = parser.extract(start, end).trim(); parser.advance(); // For the following entry // Extract the quality factor for this entry double quality = 1.0; int semi = entry.indexOf(";q="); if (semi >= 0) { try { quality = Double.parseDouble(entry.substring(semi + 3)); } catch (NumberFormatException e) { quality = 0.0; } entry = entry.substring(0, semi); } // Skip entries we are not going to keep track of if (quality < 0.00005) continue; // Zero (or effectively zero) quality factors if ("*".equals(entry)) continue; // FIXME - "*" entries are not handled // Extract the language and country for this entry String language = null; String country = null; int dash = entry.indexOf('-'); if (dash < 0) { language = entry; country = ""; } else { language = entry.substring(0, dash); country = entry.substring(dash + 1); } // Add a new Locale to the list of Locales for this quality level Locale locale = new Locale(language, country); Double key = new Double(-quality); // Reverse the order ArrayList values = (ArrayList) locales.get(key); if (values == null) { values = new ArrayList(); locales.put(key, values); } values.add(locale); } // Process the quality values in highest->lowest order (due to // negating the Double value when creating the key) Iterator keys = locales.keySet().iterator(); while (keys.hasNext()) { Double key = (Double) keys.next(); ArrayList list = (ArrayList) locales.get(key); Iterator values = list.iterator(); while (values.hasNext()) { Locale locale = (Locale) values.next(); if (Constants.DEBUG) { logger.debug("Adding locale '" + locale + "'"); } request.addLocale(locale); } } } class BasicPrincipal implements Principal { private String user; BasicPrincipal(String user) { this.user = user; } public boolean equals(Object another) { return (another instanceof Principal && ((Principal)another).getName().equals(user)); } public String getName() { return user; } public String toString() { return getName(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -