366774: Request.java code format

This commit is contained in:
Thomas Becker 2012-01-06 14:52:22 +01:00 committed by Greg Wilkins
parent 58c57a9ea0
commit bbaef55bd6
1 changed files with 535 additions and 530 deletions

View File

@ -72,41 +72,34 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/* ------------------------------------------------------------ */
/** Jetty Request.
/**
* Jetty Request.
* <p>
* Implements {@link javax.servlet.http.HttpServletRequest} from the <code>javax.servlet.http</code> package.
* </p>
* <p>
* The standard interface of mostly getters,
* is extended with setters so that the request is mutable by the handlers that it is
* passed to. This allows the request object to be as lightweight as possible and not
* actually implement any significant behavior. For example<ul>
* The standard interface of mostly getters, is extended with setters so that the request is mutable by the handlers that it is passed to. This allows the
* request object to be as lightweight as possible and not actually implement any significant behavior. For example
* <ul>
*
* <li>The {@link Request#getContextPath()} method will return null, until the request has been
* passed to a {@link ContextHandler} which matches the {@link Request#getPathInfo()} with a context
* path and calls {@link Request#setContextPath(String)} as a result.</li>
* <li>The {@link Request#getContextPath()} method will return null, until the request has been passed to a {@link ContextHandler} which matches the
* {@link Request#getPathInfo()} with a context path and calls {@link Request#setContextPath(String)} as a result.</li>
*
* <li>the HTTP session methods
* will all return null sessions until such time as a request has been passed to
* a {@link org.eclipse.jetty.server.session.SessionHandler} which checks for session cookies
* and enables the ability to create new sessions.</li>
* <li>the HTTP session methods will all return null sessions until such time as a request has been passed to a
* {@link org.eclipse.jetty.server.session.SessionHandler} which checks for session cookies and enables the ability to create new sessions.</li>
*
* <li>The {@link Request#getServletPath()} method will return null until the request has been
* passed to a <code>org.eclipse.jetty.servlet.ServletHandler</code> and the pathInfo matched
* against the servlet URL patterns and {@link Request#setServletPath(String)} called as a result.</li>
* <li>The {@link Request#getServletPath()} method will return null until the request has been passed to a <code>org.eclipse.jetty.servlet.ServletHandler</code>
* and the pathInfo matched against the servlet URL patterns and {@link Request#setServletPath(String)} called as a result.</li>
* </ul>
*
* A request instance is created for each {@link AbstractHttpConnection} accepted by the server
* and recycled for each HTTP request received via that connection. An effort is made
* to avoid reparsing headers and cookies that are likely to be the same for
* requests from the same connection.
* A request instance is created for each {@link AbstractHttpConnection} accepted by the server and recycled for each HTTP request received via that connection.
* An effort is made to avoid reparsing headers and cookies that are likely to be the same for requests from the same connection.
*
* <p>
* The form content that a request can process is limited to protect from Denial of Service
* attacks. The size in bytes is limited by {@link ContextHandler#getMaxFormContentSize()} or if there is no
* context then the "org.eclipse.jetty.server.Request.maxFormContentSize" {@link Server} attribute.
* The number of parameters keys is limited by {@link ContextHandler#getMaxFormKeys()} or if there is no
* context then the "org.eclipse.jetty.server.Request.maxFormKeys" {@link Server} attribute.
* The form content that a request can process is limited to protect from Denial of Service attacks. The size in bytes is limited by
* {@link ContextHandler#getMaxFormContentSize()} or if there is no context then the "org.eclipse.jetty.server.Request.maxFormContentSize" {@link Server}
* attribute. The number of parameters keys is limited by {@link ContextHandler#getMaxFormKeys()} or if there is no context then the
* "org.eclipse.jetty.server.Request.maxFormKeys" {@link Server} attribute.
*
*
*/
@ -240,8 +233,8 @@ public class Request implements HttpServletRequest
{
content_type = HttpFields.valueParameters(content_type,null);
if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) && _inputState==__NONE &&
(HttpMethods.POST.equals(getMethod()) || HttpMethods.PUT.equals(getMethod())))
if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) && _inputState == __NONE
&& (HttpMethods.POST.equals(getMethod()) || HttpMethods.PUT.equals(getMethod())))
{
int content_length = getContentLength();
if (content_length != 0)
@ -258,7 +251,8 @@ public class Request implements HttpServletRequest
}
else
{
Number size = (Number)_connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
Number size = (Number)_connection.getConnector().getServer()
.getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
maxFormContentSize = size == null?200000:size.intValue();
Number keys = (Number)_connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
maxFormKeys = keys == null?1000:keys.intValue();
@ -308,7 +302,6 @@ public class Request implements HttpServletRequest
}
}
/* ------------------------------------------------------------ */
public AsyncContext getAsyncContext()
{
@ -361,7 +354,9 @@ public class Request implements HttpServletRequest
}
/* ------------------------------------------------------------ */
/** Get the authentication.
/**
* Get the authentication.
*
* @return the authentication
*/
public Authentication getAuthentication()
@ -429,8 +424,7 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @return The current {@link Context context} used for this request, or <code>null</code> if {@link #setContext} has not yet
* been called.
* @return The current {@link Context context} used for this request, or <code>null</code> if {@link #setContext} has not yet been called.
*/
public Context getContext()
{
@ -612,8 +606,7 @@ public class Request implements HttpServletRequest
List acceptLanguage = HttpFields.qualityList(enm);
if (acceptLanguage.size() == 0)
return
Collections.enumeration(__defaultLocale);
return Collections.enumeration(__defaultLocale);
Object langs = null;
int size = acceptLanguage.size();
@ -729,7 +722,7 @@ public class Request implements HttpServletRequest
List<Object> vals = _parameters.getValues(name);
if (vals == null)
return null;
return (String[])vals.toArray(new String[vals.size()]);
return vals.toArray(new String[vals.size()]);
}
/* ------------------------------------------------------------ */
@ -935,9 +928,7 @@ public class Request implements HttpServletRequest
url.append(scheme);
url.append("://");
url.append(getServerName());
if (_port>0 &&
((scheme.equalsIgnoreCase(URIUtil.HTTP) && port != 80) ||
(scheme.equalsIgnoreCase(URIUtil.HTTPS) && port != 443)))
if (_port > 0 && ((scheme.equalsIgnoreCase(URIUtil.HTTP) && port != 80) || (scheme.equalsIgnoreCase(URIUtil.HTTPS) && port != 443)))
{
url.append(':');
url.append(_port);
@ -956,11 +947,10 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* Reconstructs the URL the client used to make the request. The returned URL contains a
* protocol, server name, port number, and, but it does not include a path.
* Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a
* path.
* <p>
* Because this method returns a <code>StringBuffer</code>, not a string, you can modify the
* URL easily, for example, to append path and query parameters.
* Because this method returns a <code>StringBuffer</code>, not a string, you can modify the URL easily, for example, to append path and query parameters.
*
* This method is useful for creating redirect messages and for reporting errors.
*
@ -1016,8 +1006,7 @@ public class Request implements HttpServletRequest
Buffer hostPort = _connection.getRequestFields().get(HttpHeaders.HOST_BUFFER);
if (hostPort != null)
{
loop:
for (int i=hostPort.putIndex();i-->hostPort.getIndex();)
loop: for (int i = hostPort.putIndex(); i-- > hostPort.getIndex();)
{
char ch = (char)(0xff & hostPort.peek(i));
switch (ch)
@ -1160,7 +1149,6 @@ public class Request implements HttpServletRequest
return _session;
}
/* ------------------------------------------------------------ */
/**
* @return Returns the sessionManager.
@ -1216,9 +1204,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @return The resolved user Identity, which may be null if the
* {@link Authentication} is not {@link Authentication.User}
* (eg. {@link Authentication.Deferred}).
* @return The resolved user Identity, which may be null if the {@link Authentication} is not {@link Authentication.User} (eg.
* {@link Authentication.Deferred}).
*/
public UserIdentity getResolvedUserIdentity()
{
@ -1251,7 +1238,8 @@ public class Request implements HttpServletRequest
}
/* ------------------------------------------------------------ */
/** Get timestamp of the request dispatch
/**
* Get timestamp of the request dispatch
*
* @return timestamp
*/
@ -1418,8 +1406,7 @@ public class Request implements HttpServletRequest
{
if (_requestAttributeListeners != null)
{
final ServletRequestAttributeEvent event =
new ServletRequestAttributeEvent(_context,this,name, old_value);
final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context,this,name,old_value);
final int size = LazyList.size(_requestAttributeListeners);
for (int i = 0; i < size; i++)
{
@ -1439,6 +1426,7 @@ public class Request implements HttpServletRequest
{
_requestAttributeListeners = LazyList.remove(_requestAttributeListeners,listener);
}
/* ------------------------------------------------------------ */
public void saveNewSession(Object key, HttpSession session)
{
@ -1446,6 +1434,7 @@ public class Request implements HttpServletRequest
_savedNewSessions = new HashMap<Object, HttpSession>();
_savedNewSessions.put(key,session);
}
/* ------------------------------------------------------------ */
public void setAsyncSupported(boolean supported)
{
@ -1454,15 +1443,11 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/*
* Set a request attribute.
* if the attribute name is "org.eclipse.jetty.server.server.Request.queryEncoding" then
* the value is also passed in a call to {@link #setQueryEncoding}.
* <p>
* if the attribute name is "org.eclipse.jetty.server.server.ResponseBuffer", then
* the response buffer is flushed with @{link #flushResponseBuffer}
* <p>
* if the attribute name is "org.eclipse.jetty.io.EndPoint.maxIdleTime", then the
* value is passed to the associated {@link EndPoint#setMaxIdleTime}.
* Set a request attribute. if the attribute name is "org.eclipse.jetty.server.server.Request.queryEncoding" then the value is also passed in a call to
* {@link #setQueryEncoding}. <p> if the attribute name is "org.eclipse.jetty.server.server.ResponseBuffer", then the response buffer is flushed with @{link
* #flushResponseBuffer} <p> if the attribute name is "org.eclipse.jetty.io.EndPoint.maxIdleTime", then the value is passed to the associated {@link
* EndPoint#setMaxIdleTime}.
*
* @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
*/
public void setAttribute(String name, Object value)
@ -1491,9 +1476,7 @@ public class Request implements HttpServletRequest
final ByteBuffer byteBuffer = (ByteBuffer)value;
synchronized (byteBuffer)
{
NIOBuffer buffer = byteBuffer.isDirect()
?new DirectNIOBuffer(byteBuffer,true)
:new IndirectNIOBuffer(byteBuffer,true);
NIOBuffer buffer = byteBuffer.isDirect()?new DirectNIOBuffer(byteBuffer,true):new IndirectNIOBuffer(byteBuffer,true);
((AbstractHttpConnection.Output)getServletResponse().getOutputStream()).sendResponse(buffer);
}
}
@ -1521,8 +1504,7 @@ public class Request implements HttpServletRequest
if (_requestAttributeListeners != null)
{
final ServletRequestAttributeEvent event =
new ServletRequestAttributeEvent(_context,this,name, old_value==null?value:old_value);
final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context,this,name,old_value == null?value:old_value);
final int size = LazyList.size(_requestAttributeListeners);
for (int i = 0; i < size; i++)
{
@ -1552,10 +1534,12 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/** Set the authentication.
* @param authentication the authentication to set
/**
* Set the authentication.
*
* @param authentication
* the authentication to set
*/
public void setAuthentication(Authentication authentication)
{
@ -1612,7 +1596,8 @@ public class Request implements HttpServletRequest
/**
* Set request context
*
* @param context context object
* @param context
* context object
*/
public void setContext(Context context)
{
@ -1622,8 +1607,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @return True if this is the first call of {@link #takeNewContext()}
* since the last {@link #setContext(org.eclipse.jetty.server.handler.ContextHandler.Context)} call.
* @return True if this is the first call of {@link #takeNewContext()} since the last
* {@link #setContext(org.eclipse.jetty.server.handler.ContextHandler.Context)} call.
*/
public boolean takeNewContext()
{
@ -1635,6 +1620,7 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* Sets the "context path" for this request
*
* @see HttpServletRequest#getContextPath()
*/
public void setContextPath(String contextPath)
@ -1644,7 +1630,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param cookies The cookies to set.
* @param cookies
* The cookies to set.
*/
public void setCookies(Cookie[] cookies)
{
@ -1667,7 +1654,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param method The method to set.
* @param method
* The method to set.
*/
public void setMethod(String method)
{
@ -1676,7 +1664,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param parameters The parameters to set.
* @param parameters
* The parameters to set.
*/
public void setParameters(MultiMap<String> parameters)
{
@ -1687,7 +1676,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param pathInfo The pathInfo to set.
* @param pathInfo
* The pathInfo to set.
*/
public void setPathInfo(String pathInfo)
{
@ -1696,7 +1686,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param protocol The protocol to set.
* @param protocol
* The protocol to set.
*/
public void setProtocol(String protocol)
{
@ -1704,12 +1695,11 @@ public class Request implements HttpServletRequest
}
/* ------------------------------------------------------------ */
/** Set the character encoding used for the query string.
* This call will effect the return of getQueryString and getParamaters.
* It must be called before any geParameter methods.
/**
* Set the character encoding used for the query string. This call will effect the return of getQueryString and getParamaters. It must be called before any
* geParameter methods.
*
* The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding"
* may be set as an alternate method of calling setQueryEncoding.
* The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.
*
* @param queryEncoding
*/
@ -1721,7 +1711,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param queryString The queryString to set.
* @param queryString
* The queryString to set.
*/
public void setQueryString(String queryString)
{
@ -1730,7 +1721,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param addr The address to set.
* @param addr
* The address to set.
*/
public void setRemoteAddr(String addr)
{
@ -1739,7 +1731,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param host The host to set.
* @param host
* The host to set.
*/
public void setRemoteHost(String host)
{
@ -1748,7 +1741,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param requestedSessionId The requestedSessionId to set.
* @param requestedSessionId
* The requestedSessionId to set.
*/
public void setRequestedSessionId(String requestedSessionId)
{
@ -1757,7 +1751,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param requestedSessionIdCookie The requestedSessionIdCookie to set.
* @param requestedSessionIdCookie
* The requestedSessionIdCookie to set.
*/
public void setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie)
{
@ -1766,7 +1761,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param requestURI The requestURI to set.
* @param requestURI
* The requestURI to set.
*/
public void setRequestURI(String requestURI)
{
@ -1775,7 +1771,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param scheme The scheme to set.
* @param scheme
* The scheme to set.
*/
public void setScheme(String scheme)
{
@ -1784,7 +1781,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param host The host to set.
* @param host
* The host to set.
*/
public void setServerName(String host)
{
@ -1793,7 +1791,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param port The port to set.
* @param port
* The port to set.
*/
public void setServerPort(int port)
{
@ -1802,7 +1801,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param servletPath The servletPath to set.
* @param servletPath
* The servletPath to set.
*/
public void setServletPath(String servletPath)
{
@ -1811,7 +1811,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param session The session to set.
* @param session
* The session to set.
*/
public void setSession(HttpSession session)
{
@ -1820,7 +1821,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param sessionManager The sessionManager to set.
* @param sessionManager
* The sessionManager to set.
*/
public void setSessionManager(SessionManager sessionManager)
{
@ -1835,7 +1837,8 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* @param uri The uri to set.
* @param uri
* The uri to set.
*/
public void setUri(HttpURI uri)
{
@ -1849,9 +1852,11 @@ public class Request implements HttpServletRequest
}
/* ------------------------------------------------------------ */
/** Set timetstamp of request dispatch
/**
* Set timetstamp of request dispatch
*
* @param value timestamp
* @param value
* timestamp
*/
public void setDispatchTime(long value)
{
@ -1883,12 +1888,13 @@ public class Request implements HttpServletRequest
return (_handled?"[":"(") + getMethod() + " " + _uri + (_handled?"]@":")@") + hashCode() + " " + super.toString();
}
/* ------------------------------------------------------------ */
/** Merge in a new query string.
* The query string is merged with the existing parameters and {@link #setParameters(MultiMap)} and {@link #setQueryString(String)} are called with the result.
* The merge is according to the rules of the servlet dispatch forward method.
* @param query The query string to merge into the request.
/**
* Merge in a new query string. The query string is merged with the existing parameters and {@link #setParameters(MultiMap)} and
* {@link #setQueryString(String)} are called with the result. The merge is according to the rules of the servlet dispatch forward method.
*
* @param query
* The query string to merge into the request.
*/
public void mergeQueryString(String query)
{
@ -1961,4 +1967,3 @@ public class Request implements HttpServletRequest
setQueryString(query);
}
}