Author: kkolinko Date: Thu Nov 10 06:14:08 2011 New Revision: 1200176 URL: http://svn.apache.org/viewvc?rev=1200176&view=rev Log: Merged revision 1187753 from tomcat/trunk: Clean-up. No functional change. Part 4.
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Request.java Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Request.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Request.java?rev=1200176&r1=1200175&r2=1200176&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Request.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Request.java Thu Nov 10 06:14:08 2011 @@ -5,17 +5,15 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - - package org.apache.catalina.connector; @@ -109,7 +107,7 @@ public class Request implements HttpServletRequest { private static final Log log = LogFactory.getLog(Request.class); - + // ----------------------------------------------------------- Constructors @@ -132,7 +130,7 @@ public class Request /** * Set the Coyote request. - * + * * @param coyoteRequest The Coyote request */ public void setCoyoteRequest(org.apache.coyote.Request coyoteRequest) { @@ -203,7 +201,7 @@ public class Request /** * List of read only attributes for this Request. */ - private HashMap<String,Object> readOnlyAttributes = + private final HashMap<String,Object> readOnlyAttributes = new HashMap<String,Object>(); @@ -225,19 +223,19 @@ public class Request */ protected String authType = null; - + /** * Associated event. */ protected CometEventImpl event = null; - + /** * Comet state */ protected boolean comet = false; - - + + /** * The current dispatcher type. */ @@ -253,7 +251,7 @@ public class Request /** * ServletInputStream. */ - protected CoyoteInputStream inputStream = + protected CoyoteInputStream inputStream = new CoyoteInputStream(inputBuffer); @@ -305,7 +303,7 @@ public class Request */ protected boolean secure = false; - + /** * The Subject associated with the current AccessControllerContext */ @@ -329,14 +327,14 @@ public class Request * The parts, if any, uploaded with this request. */ protected Collection<Part> parts = null; - - + + /** * The exception thrown, if any when parsing the parts. */ protected Exception partsParseException = null; - - + + /** * The currently active session for this request. */ @@ -382,7 +380,7 @@ public class Request /** * The string parser we will use for parsing request lines. */ - private StringParser parser = new StringParser(); + private final StringParser parser = new StringParser(); /** @@ -401,31 +399,31 @@ public class Request */ protected String remoteHost = null; - + /** * Remote port */ protected int remotePort = -1; - + /** * Local address */ protected String localAddr = null; - + /** * Local address */ protected String localName = null; - + /** - * AsyncContext + * AsyncContext */ protected volatile AsyncContextImpl asyncContext = null; - + protected Boolean asyncSupported = null; - - + + /** * Path parameters */ @@ -433,7 +431,7 @@ public class Request // --------------------------------------------------------- Public Methods - + protected void addPathParameter(String name, String value) { pathParameters.put(name, value); } @@ -463,7 +461,7 @@ public class Request event.clear(); event = null; } - + authType = null; inputBuffer.recycle(); usingInputStream = false; @@ -526,9 +524,11 @@ public class Request reader = null; } } - + asyncSupported = null; - if (asyncContext!=null) asyncContext.recycle(); + if (asyncContext!=null) { + asyncContext.recycle(); + } asyncContext = null; pathParameters.clear(); @@ -545,7 +545,7 @@ public class Request public void clearEncoders() { inputBuffer.clearEncoders(); } - + /** * Clear cached encoders (to save memory for Comet requests). @@ -554,7 +554,7 @@ public class Request throws IOException { return (inputBuffer.realReadBytes(null, 0, 0) > 0); } - + // -------------------------------------------------------- Request Methods @@ -621,7 +621,7 @@ public class Request /** * Set filter chain associated with the request. - * + * * @param filterChain new filter chain */ public void setFilterChain(FilterChain filterChain) { @@ -691,7 +691,7 @@ public class Request public HttpServletRequest getRequest() { if (facade == null) { facade = new RequestFacade(this); - } + } return facade; } @@ -741,7 +741,7 @@ public class Request /** * Set the URI converter. - * + * * @param URIConverter the new URI converter */ protected void setURIConverter(B2CConverter URIConverter) { @@ -782,7 +782,7 @@ public class Request * * @exception IOException if an input/output error occurs */ - public ServletInputStream createInputStream() + public ServletInputStream createInputStream() throws IOException { if (inputStream == null) { inputStream = new CoyoteInputStream(inputBuffer); @@ -927,15 +927,15 @@ public class Request public Object getAttribute(String name) { if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) { - return (internalDispatcherType == null) + return (internalDispatcherType == null) ? DispatcherType.REQUEST : internalDispatcherType; } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) { - return (requestDispatcherPath == null) + return (requestDispatcherPath == null) ? getRequestPathMB().toString() : requestDispatcherPath.toString(); } - + if (name.equals(Globals.ASYNC_SUPPORTED_ATTR)) { return asyncSupported; } @@ -949,14 +949,16 @@ public class Request Object attr=attributes.get(name); - if(attr!=null) + if(attr!=null) { return(attr); + } attr = coyoteRequest.getAttribute(name); - if(attr != null) + if(attr != null) { return attr; + } if( isSSLAttribute(name) ) { - coyoteRequest.action(ActionCode.REQ_SSL_ATTRIBUTE, + coyoteRequest.action(ActionCode.REQ_SSL_ATTRIBUTE, coyoteRequest); attr = coyoteRequest.getAttribute(Globals.CERTIFICATES_ATTR); if( attr != null) { @@ -1079,9 +1081,10 @@ public class Request @Override public ServletInputStream getInputStream() throws IOException { - if (usingReader) + if (usingReader) { throw new IllegalStateException (sm.getString("coyoteRequest.getInputStream.ise")); + } usingInputStream = true; if (inputStream == null) { @@ -1101,8 +1104,9 @@ public class Request @Override public Locale getLocale() { - if (!localesParsed) + if (!localesParsed) { parseLocales(); + } if (locales.size() > 0) { return locales.get(0); @@ -1121,11 +1125,13 @@ public class Request @Override public Enumeration<Locale> getLocales() { - if (!localesParsed) + if (!localesParsed) { parseLocales(); + } - if (locales.size() > 0) + if (locales.size() > 0) { return Collections.enumeration(locales); + } ArrayList<Locale> results = new ArrayList<Locale>(); results.add(defaultLocale); return Collections.enumeration(results); @@ -1143,8 +1149,9 @@ public class Request @Override public String getParameter(String name) { - if (!parametersParsed) + if (!parametersParsed) { parseParameters(); + } return coyoteRequest.getParameters().getParameter(name); @@ -1164,8 +1171,9 @@ public class Request @Override public Map<String, String[]> getParameterMap() { - if (parameterMap.isLocked()) + if (parameterMap.isLocked()) { return parameterMap; + } Enumeration<String> enumeration = getParameterNames(); while (enumeration.hasMoreElements()) { @@ -1187,8 +1195,9 @@ public class Request @Override public Enumeration<String> getParameterNames() { - if (!parametersParsed) + if (!parametersParsed) { parseParameters(); + } return coyoteRequest.getParameters().getParameterNames(); @@ -1204,8 +1213,9 @@ public class Request @Override public String[] getParameterValues(String name) { - if (!parametersParsed) + if (!parametersParsed) { parseParameters(); + } return coyoteRequest.getParameters().getParameterValues(name); @@ -1233,9 +1243,10 @@ public class Request @Override public BufferedReader getReader() throws IOException { - if (usingInputStream) + if (usingInputStream) { throw new IllegalStateException (sm.getString("coyoteRequest.getReader.ise")); + } usingReader = true; inputBuffer.checkConverter(); @@ -1259,8 +1270,9 @@ public class Request @Deprecated public String getRealPath(String path) { - if (context == null) + if (context == null) { return null; + } ServletContext servletContext = context.getServletContext(); if (servletContext == null) { return null; @@ -1308,7 +1320,7 @@ public class Request /** * Returns the Internet Protocol (IP) source port of the client * or last proxy that sent the request. - */ + */ @Override public int getRemotePort(){ if (remotePort == -1) { @@ -1316,7 +1328,7 @@ public class Request (ActionCode.REQ_REMOTEPORT_ATTRIBUTE, coyoteRequest); remotePort = coyoteRequest.getRemotePort(); } - return remotePort; + return remotePort; } /** @@ -1336,7 +1348,7 @@ public class Request /** * Returns the Internet Protocol (IP) address of the interface on * which the request was received. - */ + */ @Override public String getLocalAddr(){ if (localAddr == null) { @@ -1344,7 +1356,7 @@ public class Request (ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE, coyoteRequest); localAddr = coyoteRequest.localAddr().toString(); } - return localAddr; + return localAddr; } @@ -1361,7 +1373,7 @@ public class Request } return localPort; } - + /** * Return a RequestDispatcher that wraps the resource at the specified * path, which may be interpreted as relative to the current request path. @@ -1371,20 +1383,23 @@ public class Request @Override public RequestDispatcher getRequestDispatcher(String path) { - if (context == null) + if (context == null) { return null; + } // If the path is already context-relative, just pass it through - if (path == null) + if (path == null) { return null; - else if (path.startsWith("/")) + } else if (path.startsWith("/")) { return (context.getServletContext().getRequestDispatcher(path)); + } // Convert a request-relative path to a context-relative one String servletPath = (String) getAttribute( RequestDispatcher.INCLUDE_SERVLET_PATH); - if (servletPath == null) + if (servletPath == null) { servletPath = getServletPath(); + } // Add the path info, if there is any String pathInfo = getPathInfo(); @@ -1474,17 +1489,19 @@ public class Request } else { return; } - + // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); - if ((listeners == null) || (listeners.length == 0)) + if ((listeners == null) || (listeners.length == 0)) { return; + } ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); for (int i = 0; i < listeners.length; i++) { - if (!(listeners[i] instanceof ServletRequestAttributeListener)) + if (!(listeners[i] instanceof ServletRequestAttributeListener)) { continue; + } ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i]; try { @@ -1509,9 +1526,10 @@ public class Request public void setAttribute(String name, Object value) { // Name cannot be null - if (name == null) + if (name == null) { throw new IllegalArgumentException (sm.getString("coyoteRequest.setAttribute.namenull")); + } // Null value is the same as removeAttribute() if (value == null) { @@ -1526,7 +1544,7 @@ public class Request requestDispatcherPath = value; return; } - + if (name.equals(Globals.ASYNC_SUPPORTED_ATTR)) { this.asyncSupported = (Boolean)value; } @@ -1570,24 +1588,27 @@ public class Request if (name.startsWith("org.apache.tomcat.")) { coyoteRequest.setAttribute(name, value); } - + // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); - if ((listeners == null) || (listeners.length == 0)) + if ((listeners == null) || (listeners.length == 0)) { return; + } ServletRequestAttributeEvent event = null; - if (replaced) + if (replaced) { event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, oldValue); - else + } else { event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); + } for (int i = 0; i < listeners.length; i++) { - if (!(listeners[i] instanceof ServletRequestAttributeListener)) + if (!(listeners[i] instanceof ServletRequestAttributeListener)) { continue; + } ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i]; try { @@ -1622,16 +1643,17 @@ public class Request public void setCharacterEncoding(String enc) throws UnsupportedEncodingException { - if (usingReader) + if (usingReader) { return; - + } + // Ensure that the specified encoding is valid byte buffer[] = new byte[1]; buffer[0] = (byte) 'a'; // Confirm that the encoding name is valid B2CConverter.getCharset(enc); - + // Save the validated encoding coyoteRequest.setCharacterEncoding(enc); } @@ -1653,15 +1675,15 @@ public class Request if (!isAsyncSupported()) { throw new IllegalStateException("Not supported."); } - + if (asyncContext == null) { asyncContext = new AsyncContextImpl(this); } - + asyncContext.setStarted(getContext(), request, response, request==getRequest() && response==getResponse().getResponse()); asyncContext.setTimeout(getConnector().getAsyncTimeout()); - + return asyncContext; } @@ -1670,7 +1692,7 @@ public class Request if (asyncContext == null) { return false; } - + return asyncContext.isStarted(); } @@ -1696,7 +1718,7 @@ public class Request @Override public boolean isAsyncSupported() { - if (this.asyncSupported == null) { + if (this.asyncSupported == null) { return true; } @@ -1710,7 +1732,7 @@ public class Request @Override public DispatcherType getDispatcherType() { - if (internalDispatcherType == null) { + if (internalDispatcherType == null) { return DispatcherType.REQUEST; } @@ -1727,8 +1749,9 @@ public class Request */ public void addCookie(Cookie cookie) { - if (!cookiesParsed) + if (!cookiesParsed) { parseCookies(); + } int size = 0; if (cookies != null) { @@ -1906,7 +1929,7 @@ public class Request /** * Get the decoded request URI. - * + * * @return the URL decoded request URI */ public String getDecodedRequestURI() { @@ -1916,7 +1939,7 @@ public class Request /** * Get the decoded request URI. - * + * * @return the URL decoded request URI */ @Deprecated @@ -1934,8 +1957,9 @@ public class Request */ @Deprecated public void setServletPath(String path) { - if (path != null) + if (path != null) { mappingData.wrapperPath.setString(path); + } } @@ -1950,18 +1974,18 @@ public class Request if (Globals.IS_SECURITY_ENABLED){ HttpSession session = getSession(false); - if ( (subject != null) && + if ( (subject != null) && (!subject.getPrincipals().contains(principal)) ){ - subject.getPrincipals().add(principal); + subject.getPrincipals().add(principal); } else if (session != null && session.getAttribute(Globals.SUBJECT_ATTR) == null) { subject = new Subject(); - subject.getPrincipals().add(principal); + subject.getPrincipals().add(principal); } if (session != null){ session.setAttribute(Globals.SUBJECT_ATTR, subject); } - } + } this.userPrincipal = principal; } @@ -1991,7 +2015,7 @@ public class Request /** * Get the context path. - * + * * @return the context path */ @Deprecated @@ -2006,8 +2030,9 @@ public class Request @Override public Cookie[] getCookies() { - if (!cookiesParsed) + if (!cookiesParsed) { parseCookies(); + } return cookies; @@ -2038,8 +2063,9 @@ public class Request public long getDateHeader(String name) { String value = getHeader(name); - if (value == null) + if (value == null) { return (-1L); + } // Attempt to convert the date header in a variety of formats long result = FastHttpDateFormat.parseDate(value, formats); @@ -2125,7 +2151,7 @@ public class Request /** * Get the path info. - * + * * @return the path info */ @Deprecated @@ -2141,8 +2167,9 @@ public class Request @Override public String getPathTranslated() { - if (context == null) + if (context == null) { return null; + } if (getPathInfo() == null) { return null; @@ -2171,14 +2198,14 @@ public class Request if (userPrincipal == null) { return null; } - + return userPrincipal.getName(); } /** * Get the request path. - * + * * @return the request path */ public MessageBytes getRequestPathMB() { @@ -2227,7 +2254,9 @@ public class Request String scheme = getScheme(); int port = getServerPort(); if (port < 0) + { port = 80; // Work around java.net.URL bug + } url.append(scheme); url.append("://"); @@ -2255,7 +2284,7 @@ public class Request /** * Get the servlet path. - * + * * @return the servlet path */ @Deprecated @@ -2274,7 +2303,7 @@ public class Request if (session == null) { return null; } - + return session.getSession(); } @@ -2291,7 +2320,7 @@ public class Request if (session == null) { return null; } - + return session.getSession(); } @@ -2306,7 +2335,7 @@ public class Request if (requestedSessionId == null) { return false; } - + return requestedSessionCookie; } @@ -2321,7 +2350,7 @@ public class Request if (requestedSessionId == null) { return false; } - + return requestedSessionURL; } @@ -2350,23 +2379,23 @@ public class Request if (requestedSessionId == null) { return false; } - + if (context == null) { return false; } - + Manager manager = context.getManager(); if (manager == null) { return false; } - + Session session = null; try { session = manager.findSession(requestedSessionId); } catch (IOException e) { - // Can't find the session + // Can't find the session } - + if ((session == null) || !session.isValid()) { // Check for parallel deployment contexts if (getMappingData().contexts == null) { @@ -2401,16 +2430,19 @@ public class Request public boolean isUserInRole(String role) { // Have we got an authenticated principal at all? - if (userPrincipal == null) + if (userPrincipal == null) { return false; + } // Identify the Realm we will use for checking role assignments - if (context == null) + if (context == null) { return false; - + } + Realm realm = context.getRealm(); - if (realm == null) + if (realm == null) { return false; + } // Check for a role defined directly as a <security-role> return (realm.hasRole(wrapper, userPrincipal, role)); @@ -2452,7 +2484,7 @@ public class Request * are several things that may trigger an ID change. These include moving * between nodes in a cluster and session fixation prevention during the * authentication process. - * + * * @param newSessionId The session to change the session ID for */ public void changeSessionId(String newSessionId) { @@ -2461,12 +2493,13 @@ public class Request if (requestedSessionId != null && requestedSessionId.length() > 0) { requestedSessionId = newSessionId; } - + if (context != null && !context.getServletContext() .getEffectiveSessionTrackingModes().contains( - SessionTrackingMode.COOKIE)) + SessionTrackingMode.COOKIE)) { return; - + } + if (response != null) { Cookie newCookie = ApplicationSessionCookieConfig.createSessionCookie(context, @@ -2475,7 +2508,7 @@ public class Request } } - + /** * Return the session associated with this Request, creating one * if necessary and requested. @@ -2497,8 +2530,8 @@ public class Request } return event; } - - + + /** * Return true if the current request is handling Comet traffic. */ @@ -2506,7 +2539,7 @@ public class Request return comet; } - + /** * Set comet state. */ @@ -2519,8 +2552,8 @@ public class Request */ public boolean isParametersParsed() { return parametersParsed; - } - + } + /** * Return true if bytes are available. */ @@ -2537,16 +2570,16 @@ public class Request coyoteRequest.action(ActionCode.DISABLE_SWALLOW_INPUT, null); } } - + public void cometClose() { coyoteRequest.action(ActionCode.COMET_CLOSE,getEvent()); setComet(false); } - + public void setCometTimeout(long timeout) { coyoteRequest.action(ActionCode.COMET_SETTIMEOUT, Long.valueOf(timeout)); } - + /** * Not part of Servlet 3 spec but probably should be. * @return true if the requested session ID was obtained from the SSL session @@ -2555,7 +2588,7 @@ public class Request public boolean isRequestedSessionIdFromSSL() { return requestedSessionSSL; } - + /** * @throws IOException If an I/O error occurs * @throws IllegalStateException If the response has been committed @@ -2563,7 +2596,7 @@ public class Request * error and the container has NOT set the HTTP response code etc. */ @Override - public boolean authenticate(HttpServletResponse response) + public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { if (response.isCommitted()) { throw new IllegalStateException( @@ -2571,14 +2604,14 @@ public class Request } LoginConfig config = context.getLoginConfig(); - + if (config == null) { throw new ServletException( sm.getString("coyoteRequest.noLoginConfig")); } return context.getAuthenticator().authenticate(this, response, config); } - + /** * {@inheritDoc} */ @@ -2590,11 +2623,11 @@ public class Request throw new ServletException( sm.getString("coyoteRequest.alreadyAuthenticated")); } - + if (context.getAuthenticator() == null) { throw new ServletException("no authenticator"); } - + context.getAuthenticator().login(username, password, this); } @@ -2605,18 +2638,18 @@ public class Request public void logout() throws ServletException { context.getAuthenticator().logout(this); } - + /** * {@inheritDoc} */ @Override public Collection<Part> getParts() throws IOException, IllegalStateException, ServletException { - + parseParts(); - + if (partsParseException != null) { - if (partsParseException instanceof IOException) { + if (partsParseException instanceof IOException) { throw (IOException) partsParseException; } else if (partsParseException instanceof IllegalStateException) { throw (IllegalStateException) partsParseException; @@ -2624,15 +2657,16 @@ public class Request throw (ServletException) partsParseException; } } - + return parts; } private void parseParts() { // Return immediately if the parts have already been parsed - if (parts != null || partsParseException != null) + if (parts != null || partsParseException != null) { return; + } MultipartConfigElement mce = getWrapper().getMultipartConfigElement(); @@ -2647,7 +2681,7 @@ public class Request return; } } - + Parameters parameters = coyoteRequest.getParameters(); File location; @@ -2658,14 +2692,14 @@ public class Request } else { location = new File(locationStr); } - + if (!location.isAbsolute() || !location.isDirectory()) { partsParseException = new IOException( sm.getString("coyoteRequest.uploadLocationInvalid", location)); return; } - + // Create a new file upload handler DiskFileItemFactory factory = new DiskFileItemFactory(); try { @@ -2675,7 +2709,7 @@ public class Request return; } factory.setSizeThreshold(mce.getFileSizeThreshold()); - + ServletFileUpload upload = new ServletFileUpload(); upload.setFileItemFactory(factory); upload.setFileSizeMax(mce.getMaxFileSize()); @@ -2751,7 +2785,7 @@ public class Request checkSwallowInput(); partsParseException = e; } - + return; } @@ -2779,29 +2813,36 @@ public class Request protected Session doGetSession(boolean create) { // There cannot be a session if no context has been assigned yet - if (context == null) + if (context == null) { return (null); + } // Return the current session if it exists and is valid - if ((session != null) && !session.isValid()) + if ((session != null) && !session.isValid()) { session = null; - if (session != null) + } + if (session != null) { return (session); + } // Return the requested session if it exists and is valid Manager manager = null; - if (context != null) + if (context != null) { manager = context.getManager(); + } if (manager == null) + { return (null); // Sessions are not supported + } if (requestedSessionId != null) { try { session = manager.findSession(requestedSessionId); } catch (IOException e) { session = null; } - if ((session != null) && !session.isValid()) + if ((session != null) && !session.isValid()) { session = null; + } if (session != null) { session.access(); return (session); @@ -2809,8 +2850,9 @@ public class Request } // Create a new session if requested and the response is not committed - if (!create) + if (!create) { return (null); + } if ((context != null) && (response != null) && context.getServletContext().getEffectiveSessionTrackingModes(). contains(SessionTrackingMode.COOKIE) && @@ -2822,8 +2864,8 @@ public class Request // Attempt to reuse session id if one was submitted in a cookie // Do not reuse the session id if it is from a URL, to prevent possible // phishing attacks - // Use the SSL session ID if one is present. - if (("/".equals(context.getSessionCookiePath()) + // Use the SSL session ID if one is present. + if (("/".equals(context.getSessionCookiePath()) && isRequestedSessionIdFromCookie()) || requestedSessionSSL ) { session = manager.createSession(getRequestedSessionId()); } else { @@ -2838,27 +2880,35 @@ public class Request Cookie cookie = ApplicationSessionCookieConfig.createSessionCookie( context, session.getIdInternal(), isSecure()); - + response.addSessionCookieInternal(cookie); } if (session == null) { return null; } - + session.access(); return session; } protected String unescape(String s) { - if (s==null) return null; - if (s.indexOf('\\') == -1) return s; + if (s==null) { + return null; + } + if (s.indexOf('\\') == -1) { + return s; + } StringBuilder buf = new StringBuilder(); for (int i=0; i<s.length(); i++) { char c = s.charAt(i); - if (c!='\\') buf.append(c); - else { - if (++i >= s.length()) throw new IllegalArgumentException();//invalid escape, hence invalid cookie + if (c!='\\') { + buf.append(c); + } else { + if (++i >= s.length()) + { + throw new IllegalArgumentException();//invalid escape, hence invalid cookie + } c = s.charAt(i); buf.append(c); } @@ -2875,8 +2925,9 @@ public class Request Cookies serverCookies = coyoteRequest.getCookies(); int count = serverCookies.getCookieCount(); - if (count <= 0) + if (count <= 0) { return; + } cookies = new Cookie[count]; @@ -2893,7 +2944,10 @@ public class Request cookie.setValue(unescape(scookie.getValue().toString())); cookie.setPath(unescape(scookie.getPath().toString())); String domain = scookie.getDomain().toString(); - if (domain!=null) cookie.setDomain(unescape(domain));//avoid NPE + if (domain!=null) + { + cookie.setDomain(unescape(domain));//avoid NPE + } String comment = scookie.getComment().toString(); cookie.setComment(version==1?unescape(comment):null); cookies[idx++] = cookie; @@ -2941,29 +2995,33 @@ public class Request parameters.handleQueryParameters(); - if (usingInputStream || usingReader) + if (usingInputStream || usingReader) { return; + } - if( !getConnector().isParseBodyMethod(getMethod()) ) + if( !getConnector().isParseBodyMethod(getMethod()) ) { return; + } String contentType = getContentType(); - if (contentType == null) + if (contentType == null) { contentType = ""; + } int semicolon = contentType.indexOf(';'); if (semicolon >= 0) { contentType = contentType.substring(0, semicolon).trim(); } else { contentType = contentType.trim(); } - + if ("multipart/form-data".equals(contentType)) { parseParts(); return; } - - if (!("application/x-www-form-urlencoded".equals(contentType))) + + if (!("application/x-www-form-urlencoded".equals(contentType))) { return; + } int len = getContentLength(); @@ -2979,8 +3037,9 @@ public class Request } byte[] formData = null; if (len < CACHED_POST_LEN) { - if (postData == null) + if (postData == null) { postData = new byte[CACHED_POST_LEN]; + } formData = postData; } else { formData = new byte[len]; @@ -3043,9 +3102,9 @@ public class Request */ protected byte[] readChunkedPostBody() throws IOException { ByteChunk body = new ByteChunk(); - + byte[] buffer = new byte[CACHED_POST_LEN]; - + int len = 0; while (len > -1) { len = getStream().read(buffer, 0, CACHED_POST_LEN); @@ -3069,11 +3128,11 @@ public class Request System.arraycopy(body.getBuffer(), 0, result, 0, length); return result; } - + return body.getBuffer(); } - - + + /** * Parse request locales. */ @@ -3104,15 +3163,17 @@ public class Request // Preprocess the value to remove all whitespace int white = value.indexOf(' '); - if (white < 0) + if (white < 0) { white = value.indexOf('\t'); + } if (white >= 0) { StringBuilder sb = new StringBuilder(); int len = value.length(); for (int i = 0; i < len; i++) { char ch = value.charAt(i); - if ((ch != ' ') && (ch != '\t')) + if ((ch != ' ') && (ch != '\t')) { sb.append(ch); + } } parser.setString(sb.toString()); } else { @@ -3125,8 +3186,9 @@ public class Request // Extract the next comma-delimited entry int start = parser.getIndex(); - if (start >= length) + if (start >= length) { break; + } int end = parser.findChar(','); String entry = parser.extract(start, end).trim(); parser.advance(); // For the following entry @@ -3150,9 +3212,13 @@ public class Request // 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; @@ -3201,7 +3267,7 @@ public class Request } - + protected static final boolean isAlpha(String value) { for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org