You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/10/22 21:21:10 UTC
svn commit: r1187753 [2/4] - in /tomcat/trunk/java/org/apache:
catalina/connector/ tomcat/util/buf/ tomcat/util/http/
Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=1187753&r1=1187752&r2=1187753&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Sat Oct 22 19:21: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;
@@ -107,7 +105,7 @@ public class Request
implements HttpServletRequest {
private static final Log log = LogFactory.getLog(Request.class);
-
+
// ----------------------------------------------------------- Constructors
@@ -130,7 +128,7 @@ public class Request
/**
* Set the Coyote request.
- *
+ *
* @param coyoteRequest The Coyote request
*/
public void setCoyoteRequest(org.apache.coyote.Request coyoteRequest) {
@@ -201,7 +199,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>();
@@ -223,19 +221,19 @@ public class Request
*/
protected String authType = null;
-
+
/**
* Associated event.
*/
protected CometEventImpl event = null;
-
+
/**
* Comet state
*/
protected boolean comet = false;
-
-
+
+
/**
* The current dispatcher type.
*/
@@ -251,7 +249,7 @@ public class Request
/**
* ServletInputStream.
*/
- protected CoyoteInputStream inputStream =
+ protected CoyoteInputStream inputStream =
new CoyoteInputStream(inputBuffer);
@@ -302,7 +300,7 @@ public class Request
*/
protected boolean secure = false;
-
+
/**
* The Subject associated with the current AccessControllerContext
*/
@@ -326,14 +324,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.
*/
@@ -379,7 +377,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();
/**
@@ -398,31 +396,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
*/
@@ -430,7 +428,7 @@ public class Request
// --------------------------------------------------------- Public Methods
-
+
protected void addPathParameter(String name, String value) {
pathParameters.put(name, value);
}
@@ -460,7 +458,7 @@ public class Request
event.clear();
event = null;
}
-
+
authType = null;
inputBuffer.recycle();
usingInputStream = false;
@@ -523,9 +521,11 @@ public class Request
reader = null;
}
}
-
+
asyncSupported = null;
- if (asyncContext!=null) asyncContext.recycle();
+ if (asyncContext!=null) {
+ asyncContext.recycle();
+ }
asyncContext = null;
pathParameters.clear();
@@ -540,7 +540,7 @@ public class Request
public void clearEncoders() {
inputBuffer.clearEncoders();
}
-
+
/**
* Clear cached encoders (to save memory for Comet requests).
@@ -549,7 +549,7 @@ public class Request
throws IOException {
return (inputBuffer.realReadBytes(null, 0, 0) > 0);
}
-
+
// -------------------------------------------------------- Request Methods
@@ -616,7 +616,7 @@ public class Request
/**
* Set filter chain associated with the request.
- *
+ *
* @param filterChain new filter chain
*/
public void setFilterChain(FilterChain filterChain) {
@@ -685,7 +685,7 @@ public class Request
public HttpServletRequest getRequest() {
if (facade == null) {
facade = new RequestFacade(this);
- }
+ }
return facade;
}
@@ -735,7 +735,7 @@ public class Request
/**
* Set the URI converter.
- *
+ *
* @param URIConverter the new URI converter
*/
protected void setURIConverter(B2CConverter URIConverter) {
@@ -776,7 +776,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);
@@ -919,15 +919,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;
}
@@ -941,14 +941,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) {
@@ -1063,9 +1065,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) {
@@ -1085,8 +1088,9 @@ public class Request
@Override
public Locale getLocale() {
- if (!localesParsed)
+ if (!localesParsed) {
parseLocales();
+ }
if (locales.size() > 0) {
return locales.get(0);
@@ -1105,11 +1109,13 @@ public class Request
@Override
public Enumeration<Locale> getLocales() {
- if (!localesParsed)
+ if (!localesParsed) {
parseLocales();
+ }
- if (locales.size() > 0)
+ if (locales.size() > 0) {
return (new Enumerator<Locale>(locales));
+ }
ArrayList<Locale> results = new ArrayList<Locale>();
results.add(defaultLocale);
return new Enumerator<Locale>(results);
@@ -1127,8 +1133,9 @@ public class Request
@Override
public String getParameter(String name) {
- if (!parametersParsed)
+ if (!parametersParsed) {
parseParameters();
+ }
return coyoteRequest.getParameters().getParameter(name);
@@ -1148,8 +1155,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()) {
@@ -1171,8 +1179,9 @@ public class Request
@Override
public Enumeration<String> getParameterNames() {
- if (!parametersParsed)
+ if (!parametersParsed) {
parseParameters();
+ }
return coyoteRequest.getParameters().getParameterNames();
@@ -1188,8 +1197,9 @@ public class Request
@Override
public String[] getParameterValues(String name) {
- if (!parametersParsed)
+ if (!parametersParsed) {
parseParameters();
+ }
return coyoteRequest.getParameters().getParameterValues(name);
@@ -1217,9 +1227,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();
@@ -1243,8 +1254,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;
@@ -1292,7 +1304,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) {
@@ -1300,7 +1312,7 @@ public class Request
(ActionCode.REQ_REMOTEPORT_ATTRIBUTE, coyoteRequest);
remotePort = coyoteRequest.getRemotePort();
}
- return remotePort;
+ return remotePort;
}
/**
@@ -1320,7 +1332,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) {
@@ -1328,7 +1340,7 @@ public class Request
(ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE, coyoteRequest);
localAddr = coyoteRequest.localAddr().toString();
}
- return localAddr;
+ return localAddr;
}
@@ -1345,7 +1357,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.
@@ -1355,20 +1367,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();
@@ -1458,17 +1473,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 {
@@ -1493,9 +1510,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) {
@@ -1510,7 +1528,7 @@ public class Request
requestDispatcherPath = value;
return;
}
-
+
if (name.equals(Globals.ASYNC_SUPPORTED_ATTR)) {
this.asyncSupported = (Boolean)value;
}
@@ -1554,24 +1572,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 {
@@ -1606,16 +1627,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);
}
@@ -1637,15 +1659,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;
}
@@ -1654,7 +1676,7 @@ public class Request
if (asyncContext == null) {
return false;
}
-
+
return asyncContext.isStarted();
}
@@ -1680,7 +1702,7 @@ public class Request
@Override
public boolean isAsyncSupported() {
- if (this.asyncSupported == null) {
+ if (this.asyncSupported == null) {
return true;
}
@@ -1694,7 +1716,7 @@ public class Request
@Override
public DispatcherType getDispatcherType() {
- if (internalDispatcherType == null) {
+ if (internalDispatcherType == null) {
return DispatcherType.REQUEST;
}
@@ -1711,8 +1733,9 @@ public class Request
*/
public void addCookie(Cookie cookie) {
- if (!cookiesParsed)
+ if (!cookiesParsed) {
parseCookies();
+ }
int size = 0;
if (cookies != null) {
@@ -1886,7 +1909,7 @@ public class Request
/**
* Get the decoded request URI.
- *
+ *
* @return the URL decoded request URI
*/
public String getDecodedRequestURI() {
@@ -1896,7 +1919,7 @@ public class Request
/**
* Get the decoded request URI.
- *
+ *
* @return the URL decoded request URI
*/
public MessageBytes getDecodedRequestURIMB() {
@@ -1912,8 +1935,9 @@ public class Request
* @param path The servlet path
*/
public void setServletPath(String path) {
- if (path != null)
+ if (path != null) {
mappingData.wrapperPath.setString(path);
+ }
}
@@ -1928,18 +1952,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;
}
@@ -1969,7 +1993,7 @@ public class Request
/**
* Get the context path.
- *
+ *
* @return the context path
*/
public MessageBytes getContextPathMB() {
@@ -1983,8 +2007,9 @@ public class Request
@Override
public Cookie[] getCookies() {
- if (!cookiesParsed)
+ if (!cookiesParsed) {
parseCookies();
+ }
return cookies;
@@ -2014,8 +2039,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);
@@ -2101,7 +2127,7 @@ public class Request
/**
* Get the path info.
- *
+ *
* @return the path info
*/
public MessageBytes getPathInfoMB() {
@@ -2116,8 +2142,9 @@ public class Request
@Override
public String getPathTranslated() {
- if (context == null)
+ if (context == null) {
return null;
+ }
if (getPathInfo() == null) {
return null;
@@ -2146,14 +2173,14 @@ public class Request
if (userPrincipal == null) {
return null;
}
-
+
return userPrincipal.getName();
}
/**
* Get the request path.
- *
+ *
* @return the request path
*/
public MessageBytes getRequestPathMB() {
@@ -2202,7 +2229,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("://");
@@ -2230,7 +2259,7 @@ public class Request
/**
* Get the servlet path.
- *
+ *
* @return the servlet path
*/
public MessageBytes getServletPathMB() {
@@ -2248,7 +2277,7 @@ public class Request
if (session == null) {
return null;
}
-
+
return session.getSession();
}
@@ -2265,7 +2294,7 @@ public class Request
if (session == null) {
return null;
}
-
+
return session.getSession();
}
@@ -2280,7 +2309,7 @@ public class Request
if (requestedSessionId == null) {
return false;
}
-
+
return requestedSessionCookie;
}
@@ -2295,7 +2324,7 @@ public class Request
if (requestedSessionId == null) {
return false;
}
-
+
return requestedSessionURL;
}
@@ -2324,23 +2353,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) {
@@ -2375,16 +2404,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));
@@ -2426,7 +2458,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) {
@@ -2435,12 +2467,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,
@@ -2449,7 +2482,7 @@ public class Request
}
}
-
+
/**
* Return the session associated with this Request, creating one
* if necessary and requested.
@@ -2471,8 +2504,8 @@ public class Request
}
return event;
}
-
-
+
+
/**
* Return true if the current request is handling Comet traffic.
*/
@@ -2480,7 +2513,7 @@ public class Request
return comet;
}
-
+
/**
* Set comet state.
*/
@@ -2493,8 +2526,8 @@ public class Request
*/
public boolean isParametersParsed() {
return parametersParsed;
- }
-
+ }
+
/**
* Return true if bytes are available.
*/
@@ -2511,16 +2544,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
@@ -2528,7 +2561,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
@@ -2536,7 +2569,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(
@@ -2544,14 +2577,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}
*/
@@ -2563,11 +2596,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);
}
@@ -2578,18 +2611,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;
@@ -2597,15 +2630,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();
@@ -2620,7 +2654,7 @@ public class Request
return;
}
}
-
+
Parameters parameters = coyoteRequest.getParameters();
File location;
@@ -2631,14 +2665,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 {
@@ -2648,7 +2682,7 @@ public class Request
return;
}
factory.setSizeThreshold(mce.getFileSizeThreshold());
-
+
ServletFileUpload upload = new ServletFileUpload();
upload.setFileItemFactory(factory);
upload.setFileSizeMax(mce.getMaxFileSize());
@@ -2688,7 +2722,7 @@ public class Request
} catch (FileUploadException e) {
partsParseException = new IOException(e);
}
-
+
return;
}
@@ -2716,29 +2750,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);
@@ -2746,8 +2787,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) &&
@@ -2759,8 +2801,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 {
@@ -2775,27 +2817,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);
}
@@ -2812,8 +2862,9 @@ public class Request
Cookies serverCookies = coyoteRequest.getCookies();
int count = serverCookies.getCookieCount();
- if (count <= 0)
+ if (count <= 0) {
return;
+ }
cookies = new Cookie[count];
@@ -2830,7 +2881,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;
@@ -2876,29 +2930,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();
@@ -2914,8 +2972,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];
@@ -2978,9 +3037,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);
@@ -3004,11 +3063,11 @@ public class Request
System.arraycopy(body.getBuffer(), 0, result, 0, length);
return result;
}
-
+
return body.getBuffer();
}
-
-
+
+
/**
* Parse request locales.
*/
@@ -3039,15 +3098,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 {
@@ -3060,8 +3121,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
@@ -3085,9 +3147,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;
@@ -3136,7 +3202,7 @@ public class Request
}
-
+
protected static final boolean isAlpha(String value) {
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
Modified: tomcat/trunk/java/org/apache/catalina/connector/RequestFacade.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/RequestFacade.java?rev=1187753&r1=1187752&r2=1187753&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/RequestFacade.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/RequestFacade.java Sat Oct 22 19:21: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;
import java.io.BufferedReader;
@@ -46,7 +44,7 @@ import org.apache.catalina.security.Secu
import org.apache.tomcat.util.res.StringManager;
/**
- * Facade class that wraps a Coyote request object.
+ * Facade class that wraps a Coyote request object.
* All methods are delegated to the wrapped request.
*
* @author Craig R. McClanahan
@@ -57,46 +55,46 @@ import org.apache.tomcat.util.res.String
@SuppressWarnings("deprecation")
public class RequestFacade implements HttpServletRequest {
-
-
+
+
// ----------------------------------------------------------- DoPrivileged
-
+
private final class GetAttributePrivilegedAction
implements PrivilegedAction<Enumeration<String>> {
-
+
@Override
public Enumeration<String> run() {
return request.getAttributeNames();
- }
+ }
}
-
-
+
+
private final class GetParameterMapPrivilegedAction
implements PrivilegedAction<Map<String,String[]>> {
-
+
@Override
public Map<String,String[]> run() {
return request.getParameterMap();
- }
- }
-
-
+ }
+ }
+
+
private final class GetRequestDispatcherPrivilegedAction
implements PrivilegedAction<RequestDispatcher> {
- private String path;
+ private final String path;
public GetRequestDispatcherPrivilegedAction(String path){
this.path = path;
}
-
+
@Override
- public RequestDispatcher run() {
+ public RequestDispatcher run() {
return request.getRequestDispatcher(path);
- }
- }
-
-
+ }
+ }
+
+
private final class GetParameterPrivilegedAction
implements PrivilegedAction<String> {
@@ -107,22 +105,22 @@ public class RequestFacade implements Ht
}
@Override
- public String run() {
+ public String run() {
return request.getParameter(name);
- }
- }
-
-
+ }
+ }
+
+
private final class GetParameterNamesPrivilegedAction
implements PrivilegedAction<Enumeration<String>> {
-
+
@Override
- public Enumeration<String> run() {
+ public Enumeration<String> run() {
return request.getParameterNames();
- }
- }
-
-
+ }
+ }
+
+
private final class GetParameterValuePrivilegedAction
implements PrivilegedAction<String[]> {
@@ -133,90 +131,90 @@ public class RequestFacade implements Ht
}
@Override
- public String[] run() {
+ public String[] run() {
return request.getParameterValues(name);
- }
- }
-
-
+ }
+ }
+
+
private final class GetCookiesPrivilegedAction
implements PrivilegedAction<Cookie[]> {
-
+
@Override
- public Cookie[] run() {
+ public Cookie[] run() {
return request.getCookies();
- }
- }
-
-
+ }
+ }
+
+
private final class GetCharacterEncodingPrivilegedAction
implements PrivilegedAction<String> {
-
+
@Override
- public String run() {
+ public String run() {
return request.getCharacterEncoding();
- }
- }
-
-
+ }
+ }
+
+
private final class GetHeadersPrivilegedAction
implements PrivilegedAction<Enumeration<String>> {
- private String name;
+ private final String name;
public GetHeadersPrivilegedAction(String name){
this.name = name;
}
-
+
@Override
- public Enumeration<String> run() {
+ public Enumeration<String> run() {
return request.getHeaders(name);
- }
- }
-
-
+ }
+ }
+
+
private final class GetHeaderNamesPrivilegedAction
implements PrivilegedAction<Enumeration<String>> {
@Override
- public Enumeration<String> run() {
+ public Enumeration<String> run() {
return request.getHeaderNames();
- }
- }
-
-
+ }
+ }
+
+
private final class GetLocalePrivilegedAction
implements PrivilegedAction<Locale> {
@Override
- public Locale run() {
+ public Locale run() {
return request.getLocale();
- }
- }
-
-
+ }
+ }
+
+
private final class GetLocalesPrivilegedAction
implements PrivilegedAction<Enumeration<Locale>> {
@Override
- public Enumeration<Locale> run() {
+ public Enumeration<Locale> run() {
return request.getLocales();
- }
- }
-
+ }
+ }
+
private final class GetSessionPrivilegedAction
implements PrivilegedAction<HttpSession> {
- private boolean create;
-
+ private final boolean create;
+
public GetSessionPrivilegedAction(boolean create){
this.create = create;
}
-
+
@Override
- public HttpSession run() {
+ public HttpSession run() {
return request.getSession(create);
- }
+ }
}
// ----------------------------------------------------------- Constructors
@@ -260,7 +258,7 @@ public class RequestFacade implements Ht
request = null;
}
-
+
/**
* Prevent cloning the facade.
*/
@@ -296,7 +294,7 @@ public class RequestFacade implements Ht
if (Globals.IS_SECURITY_ENABLED){
return AccessController.doPrivileged(
- new GetAttributePrivilegedAction());
+ new GetAttributePrivilegedAction());
} else {
return request.getAttributeNames();
}
@@ -316,7 +314,7 @@ public class RequestFacade implements Ht
new GetCharacterEncodingPrivilegedAction());
} else {
return request.getCharacterEncoding();
- }
+ }
}
@@ -441,7 +439,7 @@ public class RequestFacade implements Ht
if (Globals.IS_SECURITY_ENABLED){
return AccessController.doPrivileged(
- new GetParameterMapPrivilegedAction());
+ new GetParameterMapPrivilegedAction());
} else {
return request.getParameterMap();
}
@@ -569,7 +567,7 @@ public class RequestFacade implements Ht
new GetLocalePrivilegedAction());
} else {
return request.getLocale();
- }
+ }
}
@@ -586,7 +584,7 @@ public class RequestFacade implements Ht
new GetLocalesPrivilegedAction());
} else {
return request.getLocales();
- }
+ }
}
@@ -707,7 +705,7 @@ public class RequestFacade implements Ht
new GetHeadersPrivilegedAction(name));
} else {
return request.getHeaders(name);
- }
+ }
}
@@ -724,7 +722,7 @@ public class RequestFacade implements Ht
new GetHeaderNamesPrivilegedAction());
} else {
return request.getHeaderNames();
- }
+ }
}
@@ -1043,7 +1041,7 @@ public class RequestFacade implements Ht
return request.isAsyncSupported();
}
-
+
@Override
public AsyncContext getAsyncContext() {
return request.getAsyncContext();
@@ -1053,7 +1051,7 @@ public class RequestFacade implements Ht
public DispatcherType getDispatcherType() {
return request.getDispatcherType();
}
-
+
@Override
public boolean authenticate(HttpServletResponse response)
throws IOException, ServletException {
@@ -1065,18 +1063,18 @@ public class RequestFacade implements Ht
throws ServletException {
request.login(username, password);
}
-
+
@Override
public void logout() throws ServletException {
request.logout();
}
-
+
@Override
public Collection<Part> getParts() throws IllegalStateException,
IOException, ServletException {
return request.getParts();
}
-
+
@Override
public Part getPart(String name) throws IllegalStateException, IOException,
ServletException {
@@ -1086,5 +1084,5 @@ public class RequestFacade implements Ht
public boolean getAllowTrace() {
return request.getConnector().getAllowTrace();
}
-
+
}
Modified: tomcat/trunk/java/org/apache/catalina/connector/Response.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Response.java?rev=1187753&r1=1187752&r2=1187753&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Response.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Response.java Sat Oct 22 19:21: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;
@@ -159,7 +157,7 @@ public class Response
/**
* Set the Coyote response.
- *
+ *
* @param coyoteResponse The Coyote response
*/
public void setCoyoteResponse(org.apache.coyote.Response coyoteResponse) {
@@ -224,12 +222,12 @@ public class Response
*/
protected boolean included = false;
-
+
/**
* The characterEncoding flag
*/
private boolean isCharacterEncodingSet = false;
-
+
/**
* The error flag.
*/
@@ -276,7 +274,7 @@ public class Response
included = false;
error = false;
isCharacterEncodingSet = false;
-
+
if (Globals.IS_SECURITY_ENABLED || Connector.RECYCLE_FACADES) {
if (facade != null) {
facade.clear();
@@ -303,7 +301,7 @@ public class Response
public void clearEncoders() {
outputBuffer.clearEncoders();
}
-
+
// ------------------------------------------------------- Response Methods
@@ -335,7 +333,7 @@ public class Response
/**
* Set the application commit flag.
- *
+ *
* @param appCommitted The new application committed flag value
*/
public void setAppCommitted(boolean appCommitted) {
@@ -348,7 +346,7 @@ public class Response
*/
public boolean isAppCommitted() {
return (this.appCommitted || isCommitted() || isSuspended()
- || ((getContentLength() > 0)
+ || ((getContentLength() > 0)
&& (getContentWritten() >= getContentLength())));
}
@@ -434,7 +432,7 @@ public class Response
/**
* Set the suspended flag.
- *
+ *
* @param suspended The new suspended flag value
*/
public void setSuspended(boolean suspended) {
@@ -480,7 +478,7 @@ public class Response
*
* @exception IOException if an input/output error occurs
*/
- public ServletOutputStream createOutputStream()
+ public ServletOutputStream createOutputStream()
throws IOException {
// Probably useless
if (outputStream == null) {
@@ -496,7 +494,7 @@ public class Response
*
* @exception IOException if an input/output error occurs
*/
- public void finishResponse()
+ public void finishResponse()
throws IOException {
// Writing leftover bytes
outputBuffer.close();
@@ -555,7 +553,7 @@ public class Response
* @exception IOException if an input/output error occurs
*/
@Override
- public void flushBuffer()
+ public void flushBuffer()
throws IOException {
outputBuffer.flush();
}
@@ -587,12 +585,13 @@ public class Response
* @exception IOException if an input/output error occurs
*/
@Override
- public ServletOutputStream getOutputStream()
+ public ServletOutputStream getOutputStream()
throws IOException {
- if (usingWriter)
+ if (usingWriter) {
throw new IllegalStateException
(sm.getString("coyoteResponse.getOutputStream.ise"));
+ }
usingOutputStream = true;
if (outputStream == null) {
@@ -620,12 +619,13 @@ public class Response
* @exception IOException if an input/output error occurs
*/
@Override
- public PrintWriter getWriter()
+ public PrintWriter getWriter()
throws IOException {
- if (usingOutputStream)
+ if (usingOutputStream) {
throw new IllegalStateException
(sm.getString("coyoteResponse.getWriter.ise"));
+ }
if (ENFORCE_ENCODING_IN_GET_WRITER) {
/*
@@ -672,7 +672,9 @@ public class Response
public void reset() {
if (included)
+ {
return; // Ignore any call from an included servlet
+ }
coyoteResponse.reset();
outputBuffer.reset();
@@ -693,7 +695,7 @@ public class Response
resetBuffer(false);
}
-
+
/**
* Reset the data buffer and the using Writer/Stream flags but not any
* status or header information.
@@ -701,18 +703,19 @@ public class Response
* @param resetWriterStreamFlags <code>true</code> if the internal
* <code>usingWriter</code>, <code>usingOutputStream</code>,
* <code>isCharacterEncodingSet</code> flags should also be reset
- *
+ *
* @exception IllegalStateException if the response has already
* been committed
*/
public void resetBuffer(boolean resetWriterStreamFlags) {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.resetBuffer.ise"));
+ }
outputBuffer.reset();
-
+
if(resetWriterStreamFlags) {
usingOutputStream = false;
usingWriter = false;
@@ -721,7 +724,7 @@ public class Response
}
-
+
/**
* Set the buffer size to be used for this Response.
*
@@ -733,9 +736,10 @@ public class Response
@Override
public void setBufferSize(int size) {
- if (isCommitted() || !outputBuffer.isNew())
+ if (isCommitted() || !outputBuffer.isNew()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.setBufferSize.ise"));
+ }
outputBuffer.setBufferSize(size);
@@ -750,13 +754,15 @@ public class Response
@Override
public void setContentLength(int length) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
+ if (included) {
return;
-
+ }
+
coyoteResponse.setContentLength(length);
}
@@ -771,12 +777,14 @@ public class Response
@SuppressWarnings("deprecation") // isSpace (deprecated) cannot be replaced by isWhiteSpace
public void setContentType(String type) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
+ if (included) {
return;
+ }
// Ignore charset if getWriter() has already been called
if (usingWriter) {
@@ -826,17 +834,20 @@ public class Response
@Override
public void setCharacterEncoding(String charset) {
- if (isCommitted())
+ if (isCommitted()) {
return;
-
+ }
+
// Ignore any call from an included servlet
- if (included)
- return;
-
+ if (included) {
+ return;
+ }
+
// Ignore any call made after the getWriter has been invoked
// The default should be used
- if (usingWriter)
+ if (usingWriter) {
return;
+ }
coyoteResponse.setCharacterEncoding(charset);
isCharacterEncodingSet = true;
@@ -852,19 +863,22 @@ public class Response
@Override
public void setLocale(Locale locale) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
+ if (included) {
return;
+ }
coyoteResponse.setLocale(locale);
// Ignore any call made after the getWriter has been invoked.
// The default should be used
- if (usingWriter)
+ if (usingWriter) {
return;
+ }
if (isCharacterEncodingSet) {
return;
@@ -976,8 +990,9 @@ public class Response
public void addCookie(final Cookie cookie) {
// Ignore any call from an included servlet
- if (included || isCommitted())
+ if (included || isCommitted()) {
return;
+ }
final StringBuffer sb = generateCookieString(cookie);
//if we reached here, no exception, cookie is valid
@@ -988,14 +1003,15 @@ public class Response
}
/**
- * Special method for adding a session cookie as we should be overriding
- * any previous
+ * Special method for adding a session cookie as we should be overriding
+ * any previous
* @param cookie
*/
public void addSessionCookieInternal(final Cookie cookie) {
- if (isCommitted())
+ if (isCommitted()) {
return;
-
+ }
+
String name = cookie.getName();
final String headername = "Set-Cookie";
final String startsWith = name + "=";
@@ -1014,22 +1030,22 @@ public class Response
if (!set) {
addHeader(headername, sb.toString());
}
-
-
+
+
}
public StringBuffer generateCookieString(final Cookie cookie) {
final StringBuffer sb = new StringBuffer();
- //web application code can receive a IllegalArgumentException
+ //web application code can receive a IllegalArgumentException
//from the appendCookieValue invocation
if (SecurityUtil.isPackageProtectionEnabled()) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run(){
ServerCookie.appendCookieValue
- (sb, cookie.getVersion(), cookie.getName(),
- cookie.getValue(), cookie.getPath(),
- cookie.getDomain(), cookie.getComment(),
+ (sb, cookie.getVersion(), cookie.getName(),
+ cookie.getValue(), cookie.getPath(),
+ cookie.getDomain(), cookie.getComment(),
cookie.getMaxAge(), cookie.getSecure(),
cookie.isHttpOnly());
return null;
@@ -1038,7 +1054,7 @@ public class Response
} else {
ServerCookie.appendCookieValue
(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
- cookie.getPath(), cookie.getDomain(), cookie.getComment(),
+ cookie.getPath(), cookie.getDomain(), cookie.getComment(),
cookie.getMaxAge(), cookie.getSecure(),
cookie.isHttpOnly());
}
@@ -1059,8 +1075,9 @@ public class Response
return;
}
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
if (included) {
@@ -1091,12 +1108,14 @@ public class Response
return;
}
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
+ if (included) {
return;
+ }
coyoteResponse.addHeader(name, value);
@@ -1116,12 +1135,14 @@ public class Response
return;
}
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
+ if (included) {
return;
+ }
addHeader(name, "" + value);
@@ -1195,10 +1216,10 @@ public class Response
*/
@Override
public String encodeURL(String url) {
-
+
String absolute = toAbsolute(url);
if (isEncodeable(absolute)) {
- // W3c spec clearly said
+ // W3c spec clearly said
if (url.equalsIgnoreCase("")) {
url = absolute;
} else if (url.equals(absolute) && !hasPath(url)) {
@@ -1230,18 +1251,20 @@ public class Response
/**
* Send an acknowledgment of a request.
- *
+ *
* @exception IOException if an input/output error occurs
*/
public void sendAcknowledgement()
throws IOException {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
- return;
+ if (included) {
+ return;
+ }
coyoteResponse.acknowledge();
@@ -1259,7 +1282,7 @@ public class Response
* @exception IOException if an input/output error occurs
*/
@Override
- public void sendError(int status)
+ public void sendError(int status)
throws IOException {
sendError(status, null);
}
@@ -1276,21 +1299,23 @@ public class Response
* @exception IOException if an input/output error occurs
*/
@Override
- public void sendError(int status, String message)
+ public void sendError(int status, String message)
throws IOException {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.sendError.ise"));
+ }
// Ignore any call from an included servlet
- if (included)
- return;
+ if (included) {
+ return;
+ }
Wrapper wrapper = getRequest().getWrapper();
if (wrapper != null) {
wrapper.incrementErrorCount();
- }
+ }
setError();
@@ -1316,16 +1341,18 @@ public class Response
* @exception IOException if an input/output error occurs
*/
@Override
- public void sendRedirect(String location)
+ public void sendRedirect(String location)
throws IOException {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.sendRedirect.ise"));
+ }
// Ignore any call from an included servlet
- if (included)
- return;
+ if (included) {
+ return;
+ }
// Clear any data content that has been buffered
resetBuffer(true);
@@ -1364,8 +1391,9 @@ public class Response
return;
}
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
if (included) {
@@ -1396,12 +1424,14 @@ public class Response
return;
}
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
+ if (included) {
return;
+ }
coyoteResponse.setHeader(name, value);
@@ -1421,12 +1451,14 @@ public class Response
return;
}
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
+ if (included) {
return;
+ }
setHeader(name, "" + value);
@@ -1458,12 +1490,14 @@ public class Response
@Deprecated
public void setStatus(int status, String message) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
// Ignore any call from an included servlet
- if (included)
+ if (included) {
return;
+ }
coyoteResponse.setStatus(status);
coyoteResponse.setMessage(message);
@@ -1489,25 +1523,30 @@ public class Response
*/
protected boolean isEncodeable(final String location) {
- if (location == null)
+ if (location == null) {
return (false);
+ }
// Is this an intra-document reference?
- if (location.startsWith("#"))
+ if (location.startsWith("#")) {
return (false);
+ }
// Are we in a valid session that is not using cookies?
final Request hreq = request;
final Session session = hreq.getSessionInternal(false);
- if (session == null)
+ if (session == null) {
return (false);
- if (hreq.isRequestedSessionIdFromCookie())
+ }
+ if (hreq.isRequestedSessionIdFromCookie()) {
return (false);
-
+ }
+
// Is URL encoding permitted
if (!hreq.getServletContext().getEffectiveSessionTrackingModes().
- contains(SessionTrackingMode.URL))
+ contains(SessionTrackingMode.URL)) {
return false;
+ }
if (SecurityUtil.isPackageProtectionEnabled()) {
return (
@@ -1523,7 +1562,7 @@ public class Response
}
}
- private boolean doIsEncodeable(Request hreq, Session session,
+ private boolean doIsEncodeable(Request hreq, Session session,
String location) {
// Is this a valid absolute URL?
URL url = null;
@@ -1534,38 +1573,45 @@ public class Response
}
// Does this URL match down to (and including) the context path?
- if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol()))
+ if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol())) {
return (false);
- if (!hreq.getServerName().equalsIgnoreCase(url.getHost()))
+ }
+ if (!hreq.getServerName().equalsIgnoreCase(url.getHost())) {
return (false);
+ }
int serverPort = hreq.getServerPort();
if (serverPort == -1) {
- if ("https".equals(hreq.getScheme()))
+ if ("https".equals(hreq.getScheme())) {
serverPort = 443;
- else
+ } else {
serverPort = 80;
+ }
}
int urlPort = url.getPort();
if (urlPort == -1) {
- if ("https".equals(url.getProtocol()))
+ if ("https".equals(url.getProtocol())) {
urlPort = 443;
- else
+ } else {
urlPort = 80;
+ }
}
- if (serverPort != urlPort)
+ if (serverPort != urlPort) {
return (false);
+ }
String contextPath = getContext().getPath();
if (contextPath != null) {
String file = url.getFile();
- if ((file == null) || !file.startsWith(contextPath))
+ if ((file == null) || !file.startsWith(contextPath)) {
return (false);
+ }
String tok = ";" +
ApplicationSessionCookieConfig.getSessionUriParamName(
request.getContext()) +
"=" + session.getIdInternal();
- if( file.indexOf(tok, contextPath.length()) >= 0 )
+ if( file.indexOf(tok, contextPath.length()) >= 0 ) {
return (false);
+ }
}
// This URL belongs to our web application, so it is encodeable
@@ -1586,8 +1632,9 @@ public class Response
*/
protected String toAbsolute(String location) {
- if (location == null)
+ if (location == null) {
return (location);
+ }
boolean leadingSlash = location.startsWith("/");
@@ -1630,18 +1677,18 @@ public class Response
String relativePath = request.getDecodedRequestURI();
int pos = relativePath.lastIndexOf('/');
relativePath = relativePath.substring(0, pos);
-
+
String encodedURI = null;
final String frelativePath = relativePath;
if (SecurityUtil.isPackageProtectionEnabled() ){
try{
- encodedURI = AccessController.doPrivileged(
- new PrivilegedExceptionAction<String>(){
+ encodedURI = AccessController.doPrivileged(
+ new PrivilegedExceptionAction<String>(){
@Override
public String run() throws IOException{
return urlEncoder.encodeURL(frelativePath);
}
- });
+ });
} catch (PrivilegedActionException pae){
IllegalArgumentException iae =
new IllegalArgumentException(location);
@@ -1713,8 +1760,9 @@ public class Response
*/
protected String toEncoded(String url, String sessionId) {
- if ((url == null) || (sessionId == null))
+ if ((url == null) || (sessionId == null)) {
return (url);
+ }
String path = url;
String query = "";
Modified: tomcat/trunk/java/org/apache/catalina/connector/ResponseFacade.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/ResponseFacade.java?rev=1187753&r1=1187752&r2=1187753&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/ResponseFacade.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/ResponseFacade.java Sat Oct 22 19:21: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;
import java.io.IOException;
@@ -36,7 +34,7 @@ import org.apache.catalina.security.Secu
import org.apache.tomcat.util.res.StringManager;
/**
- * Facade class that wraps a Coyote response object.
+ * Facade class that wraps a Coyote response object.
* All methods are delegated to the wrapped response.
*
* @author Remy Maucherat
@@ -44,34 +42,34 @@ import org.apache.tomcat.util.res.String
* @version $Id$
*/
@SuppressWarnings("deprecation")
-public class ResponseFacade
+public class ResponseFacade
implements HttpServletResponse {
// ----------------------------------------------------------- DoPrivileged
-
+
private final class SetContentTypePrivilegedAction
implements PrivilegedAction<Void> {
- private String contentType;
+ private final String contentType;
public SetContentTypePrivilegedAction(String contentType){
this.contentType = contentType;
}
-
+
@Override
public Void run() {
response.setContentType(contentType);
return null;
- }
+ }
}
private final class DateHeaderPrivilegedAction
implements PrivilegedAction<Void> {
- private String name;
- private long value;
- private boolean add;
+ private final String name;
+ private final long value;
+ private final boolean add;
DateHeaderPrivilegedAction(String name, long value, boolean add) {
this.name = name;
@@ -89,7 +87,7 @@ public class ResponseFacade
return null;
}
}
-
+
// ----------------------------------------------------------- Constructors
@@ -197,8 +195,9 @@ public class ResponseFacade
// (/*sm.getString("responseFacade.finished")*/);
ServletOutputStream sos = response.getOutputStream();
- if (isFinished())
+ if (isFinished()) {
response.setSuspended(true);
+ }
return (sos);
}
@@ -213,8 +212,9 @@ public class ResponseFacade
// (/*sm.getString("responseFacade.finished")*/);
PrintWriter writer = response.getWriter();
- if (isFinished())
+ if (isFinished()) {
response.setSuspended(true);
+ }
return (writer);
}
@@ -223,8 +223,9 @@ public class ResponseFacade
@Override
public void setContentLength(int len) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.setContentLength(len);
@@ -234,13 +235,14 @@ public class ResponseFacade
@Override
public void setContentType(String type) {
- if (isCommitted())
+ if (isCommitted()) {
return;
-
+ }
+
if (SecurityUtil.isPackageProtectionEnabled()){
AccessController.doPrivileged(new SetContentTypePrivilegedAction(type));
} else {
- response.setContentType(type);
+ response.setContentType(type);
}
}
@@ -248,9 +250,10 @@ public class ResponseFacade
@Override
public void setBufferSize(int size) {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.setBufferSize.ise"));
+ }
response.setBufferSize(size);
@@ -273,10 +276,11 @@ public class ResponseFacade
public void flushBuffer()
throws IOException {
- if (isFinished())
+ if (isFinished()) {
// throw new IllegalStateException
// (/*sm.getString("responseFacade.finished")*/);
return;
+ }
if (SecurityUtil.isPackageProtectionEnabled()){
try{
@@ -300,7 +304,7 @@ public class ResponseFacade
} else {
response.setAppCommitted(true);
- response.flushBuffer();
+ response.flushBuffer();
}
}
@@ -309,9 +313,10 @@ public class ResponseFacade
@Override
public void resetBuffer() {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.resetBuffer.ise"));
+ }
response.resetBuffer();
@@ -333,9 +338,10 @@ public class ResponseFacade
@Override
public void reset() {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.reset.ise"));
+ }
response.reset();
@@ -345,8 +351,9 @@ public class ResponseFacade
@Override
public void setLocale(Locale loc) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.setLocale(loc);
}
@@ -367,8 +374,9 @@ public class ResponseFacade
@Override
public void addCookie(Cookie cookie) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.addCookie(cookie);
@@ -439,9 +447,10 @@ public class ResponseFacade
public void sendError(int sc, String msg)
throws IOException {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.sendError.ise"));
+ }
response.setAppCommitted(true);
@@ -454,9 +463,10 @@ public class ResponseFacade
public void sendError(int sc)
throws IOException {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.sendError.ise"));
+ }
response.setAppCommitted(true);
@@ -469,9 +479,10 @@ public class ResponseFacade
public void sendRedirect(String location)
throws IOException {
- if (isCommitted())
+ if (isCommitted()) {
throw new IllegalStateException
(sm.getString("coyoteResponse.sendRedirect.ise"));
+ }
response.setAppCommitted(true);
@@ -483,8 +494,9 @@ public class ResponseFacade
@Override
public void setDateHeader(String name, long date) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
if(Globals.IS_SECURITY_ENABLED) {
AccessController.doPrivileged(new DateHeaderPrivilegedAction
@@ -499,8 +511,9 @@ public class ResponseFacade
@Override
public void addDateHeader(String name, long date) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
if(Globals.IS_SECURITY_ENABLED) {
AccessController.doPrivileged(new DateHeaderPrivilegedAction
@@ -515,8 +528,9 @@ public class ResponseFacade
@Override
public void setHeader(String name, String value) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.setHeader(name, value);
@@ -526,8 +540,9 @@ public class ResponseFacade
@Override
public void addHeader(String name, String value) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.addHeader(name, value);
@@ -537,8 +552,9 @@ public class ResponseFacade
@Override
public void setIntHeader(String name, int value) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.setIntHeader(name, value);
@@ -548,8 +564,9 @@ public class ResponseFacade
@Override
public void addIntHeader(String name, int value) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.addIntHeader(name, value);
@@ -559,8 +576,9 @@ public class ResponseFacade
@Override
public void setStatus(int sc) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.setStatus(sc);
@@ -570,8 +588,9 @@ public class ResponseFacade
@Override
public void setStatus(int sc, String sm) {
- if (isCommitted())
+ if (isCommitted()) {
return;
+ }
response.setStatus(sc, sm);
}
@@ -604,17 +623,17 @@ public class ResponseFacade
public int getStatus() {
return response.getStatus();
}
-
+
@Override
public String getHeader(String name) {
return response.getHeader(name);
}
-
+
@Override
public Collection<String> getHeaderNames() {
return response.getHeaderNames();
}
-
+
@Override
public Collection<String> getHeaders(String name) {
return response.getHeaders(name);
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/Ascii.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/Ascii.java?rev=1187753&r1=1187752&r2=1187753&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/Ascii.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/Ascii.java Sat Oct 22 19:21:08 2011
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.tomcat.util.buf;
/**
@@ -197,7 +196,7 @@ public final class Ascii {
long n = c - '0';
long m;
-
+
while (--len > 0) {
if (!isDigit(c = b[off++])) {
throw new NumberFormatException();
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java?rev=1187753&r1=1187752&r2=1187753&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java Sat Oct 22 19:21:08 2011
@@ -14,8 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.tomcat.util.buf;
import java.io.IOException;
@@ -30,7 +28,7 @@ import java.util.Map;
import org.apache.tomcat.util.res.StringManager;
/** Efficient conversion of bytes to character .
- *
+ *
* This uses the standard JDK mechanism - a reader - but provides mechanisms
* to recycle all the objects that are used. It is compatible with JDK1.1
* and up,
@@ -41,11 +39,11 @@ import org.apache.tomcat.util.res.String
* be used in a later version or after the remaining optimizations.
*/
public class B2CConverter {
-
-
+
+
private static final org.apache.juli.logging.Log log=
org.apache.juli.logging.LogFactory.getLog( B2CConverter.class );
-
+
private static final StringManager sm =
StringManager.getManager(Constants.Package);
@@ -70,7 +68,7 @@ public class B2CConverter {
String lowerCaseEnc = enc.toLowerCase(Locale.US);
Charset charset = encodingToCharsetCache.get(lowerCaseEnc);
-
+
if (charset == null) {
// Pre-population of the cache means this must be invalid
throw new UnsupportedEncodingException(
@@ -78,14 +76,14 @@ public class B2CConverter {
}
return charset;
}
-
+
private IntermediateInputStream iis;
private ReadConvertor conv;
private String encoding;
protected B2CConverter() {
}
-
+
/** Create a converter, with bytes going to a byte buffer
*/
public B2CConverter(String encoding)
@@ -95,7 +93,7 @@ public class B2CConverter {
reset();
}
-
+
/** Reset the internal state, empty the buffers.
* The encoding remain in effect, the internal buffers remain allocated.
*/
@@ -106,7 +104,7 @@ public class B2CConverter {
static final int BUFFER_SIZE=8192;
char result[]=new char[BUFFER_SIZE];
- public void convert( ByteChunk bb, CharChunk cb, int limit)
+ public void convert( ByteChunk bb, CharChunk cb, int limit)
throws IOException
{
iis.setByteChunk( bb );
@@ -119,19 +117,22 @@ public class B2CConverter {
int cnt=conv.read( result, 0, size );
if( cnt <= 0 ) {
// End of stream ! - we may be in a bad state
- if(log.isDebugEnabled())
+ if(log.isDebugEnabled()) {
log.debug("B2CConverter: EOF");
+ }
return;
}
- if(log.isDebugEnabled())
+ if(log.isDebugEnabled()) {
log.debug("B2CConverter: Converted: " +
new String(result, 0, cnt));
+ }
cb.append( result, 0, cnt );
limit = limit - (bbLengthBeforeRead - bb.getLength());
}
} catch( IOException ex) {
- if(log.isDebugEnabled())
+ if(log.isDebugEnabled()) {
log.debug("B2CConverter: Reseting the converter " + ex.toString());
+ }
reset();
throw ex;
}
@@ -153,16 +154,16 @@ public class B2CConverter {
/**
- *
+ *
*/
final class ReadConvertor extends InputStreamReader {
-
+
/** Create a converter.
*/
public ReadConvertor(IntermediateInputStream in, Charset charset) {
super(in, charset);
}
-
+
/** Overridden - will do nothing but reset internal state.
*/
@Override
@@ -170,7 +171,7 @@ final class ReadConvertor extends Input
// NOTHING
// Calling super.close() would reset out and cb.
}
-
+
@Override
public final int read(char cbuf[], int off, int len)
throws IOException
@@ -178,7 +179,7 @@ final class ReadConvertor extends Input
// will do the conversion and call write on the output stream
return super.read( cbuf, off, len );
}
-
+
/** Reset the buffer
*/
public final void recycle() {
@@ -196,27 +197,27 @@ final class ReadConvertor extends Input
/** Special output stream where close() is overridden, so super.close()
is never called.
-
+
This allows recycling. It can also be disabled, so callbacks will
not be called if recycling the converter and if data was not flushed.
*/
final class IntermediateInputStream extends InputStream {
ByteChunk bc = null;
-
+
public IntermediateInputStream() {
}
-
+
@Override
public final void close() throws IOException {
// shouldn't be called - we filter it out in writer
throw new IOException("close() called - shouldn't happen ");
}
-
+
@Override
public final int read(byte cbuf[], int off, int len) throws IOException {
return bc.substract(cbuf, off, len);
}
-
+
@Override
public final int read() throws IOException {
return bc.substract();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org