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 2019/07/30 13:08:50 UTC
[tomcat] 03/06: Align with master. Spacing, Javadoc,
remove unnecessary (...)
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 24ebf35f082e0198a5c3b6bc83e1c1becc305588
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jul 29 20:53:41 2019 +0100
Align with master. Spacing, Javadoc, remove unnecessary (...)
---
java/org/apache/catalina/connector/Request.java | 14 +-
java/org/apache/catalina/connector/Response.java | 157 +++++++++++++----------
2 files changed, 91 insertions(+), 80 deletions(-)
diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java
index 71e381e..11c64bb 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -16,7 +16,6 @@
*/
package org.apache.catalina.connector;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -113,16 +112,13 @@ import org.ietf.jgss.GSSException;
* @author Remy Maucherat
* @author Craig R. McClanahan
*/
-public class Request
-implements HttpServletRequest {
+public class Request implements HttpServletRequest {
private static final Log log = LogFactory.getLog(Request.class);
// ----------------------------------------------------------- Constructors
-
public Request() {
-
formats[0].setTimeZone(GMT_ZONE);
formats[1].setTimeZone(GMT_ZONE);
formats[2].setTimeZone(GMT_ZONE);
@@ -160,7 +156,6 @@ implements HttpServletRequest {
// ----------------------------------------------------- Variables
-
protected static final TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
@@ -2775,10 +2770,7 @@ implements HttpServletRequest {
}
/**
- * @throws IOException If an I/O error occurs
- * @throws IllegalStateException If the response has been committed
- * @throws ServletException If the caller is responsible for handling the
- * error and the container has NOT set the HTTP response code etc.
+ * {@inheritDoc}
*/
@Override
public boolean authenticate(HttpServletResponse response)
@@ -2949,7 +2941,7 @@ implements HttpServletRequest {
try {
value = part.getString(Parameters.DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
- // Should not be possible
+ // Not possible
}
}
if (maxPostSize >= 0) {
diff --git a/java/org/apache/catalina/connector/Response.java b/java/org/apache/catalina/connector/Response.java
index 539fe6b..1d45bf7 100644
--- a/java/org/apache/catalina/connector/Response.java
+++ b/java/org/apache/catalina/connector/Response.java
@@ -32,7 +32,6 @@ import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
-import java.util.Vector;
import javax.servlet.ServletOutputStream;
import javax.servlet.SessionTrackingMode;
@@ -155,18 +154,18 @@ public class Response implements HttpServletResponse {
}
/**
- * Get the Coyote response.
+ * @return the Coyote response.
*/
public org.apache.coyote.Response getCoyoteResponse() {
- return (coyoteResponse);
+ return this.coyoteResponse;
}
/**
- * Return the Context within which this Request is being processed.
+ * @return the Context within which this Request is being processed.
*/
public Context getContext() {
- return (request.getContext());
+ return request.getContext();
}
/**
@@ -245,7 +244,6 @@ public class Response implements HttpServletResponse {
// --------------------------------------------------------- Public Methods
-
/**
* Release all object references, and initialize instance variables, in
* preparation for reuse of this object.
@@ -289,9 +287,8 @@ public class Response implements HttpServletResponse {
// ------------------------------------------------------- Response Methods
-
/**
- * Return the number of bytes the application has actually written to the
+ * @return the number of bytes the application has actually written to the
* output stream. This excludes chunking, compression, etc. as well as
* headers.
*/
@@ -301,8 +298,9 @@ public class Response implements HttpServletResponse {
/**
- * Return the number of bytes the actually written to the socket. This
+ * @return the number of bytes the actually written to the socket. This
* includes chunking, compression, etc. but excludes headers.
+ * @param flush if <code>true</code> will perform a buffer flush first
*/
public long getBytesWritten(boolean flush) {
if (flush) {
@@ -327,11 +325,13 @@ public class Response implements HttpServletResponse {
/**
* Application commit flag accessor.
+ *
+ * @return <code>true</code> if the application has committed the response
*/
public boolean isAppCommitted() {
- return (this.appCommitted || isCommitted() || isSuspended()
+ return this.appCommitted || isCommitted() || isSuspended()
|| ((getContentLength() > 0)
- && (getContentWritten() >= getContentLength())));
+ && (getContentWritten() >= getContentLength()));
}
@@ -372,10 +372,10 @@ public class Response implements HttpServletResponse {
protected Request request = null;
/**
- * Return the Request with which this Response is associated.
+ * @return the Request with which this Response is associated.
*/
public org.apache.catalina.connector.Request getRequest() {
- return (this.request);
+ return this.request;
}
/**
@@ -393,15 +393,16 @@ public class Response implements HttpServletResponse {
*/
protected ResponseFacade facade = null;
+
/**
- * Return the <code>ServletResponse</code> for which this object
+ * @return the <code>ServletResponse</code> for which this object
* is the facade.
*/
public HttpServletResponse getResponse() {
if (facade == null) {
facade = new ResponseFacade(this);
}
- return (facade);
+ return facade;
}
@@ -429,6 +430,8 @@ public class Response implements HttpServletResponse {
/**
* Suspended flag accessor.
+ *
+ * @return <code>true</code> if the response is suspended
*/
public boolean isSuspended() {
return outputBuffer.isSuspended();
@@ -437,6 +440,8 @@ public class Response implements HttpServletResponse {
/**
* Closed flag accessor.
+ *
+ * @return <code>true</code> if the response has been closed
*/
public boolean isClosed() {
return outputBuffer.isClosed();
@@ -445,6 +450,8 @@ public class Response implements HttpServletResponse {
/**
* Set the error flag.
+ *
+ * @return <code>false</code> if the error flag was already set
*/
public boolean setError() {
boolean result = getCoyoteResponse().setError();
@@ -460,6 +467,8 @@ public class Response implements HttpServletResponse {
/**
* Error flag accessor.
+ *
+ * @return <code>true</code> if the response has encountered an error
*/
public boolean isError() {
return getCoyoteResponse().isError();
@@ -506,7 +515,7 @@ public class Response implements HttpServletResponse {
/**
- * Return the content length that was set or calculated for this Response.
+ * @return the content length that was set or calculated for this Response.
*/
public int getContentLength() {
return getCoyoteResponse().getContentLength();
@@ -514,7 +523,7 @@ public class Response implements HttpServletResponse {
/**
- * Return the content type that was set or calculated for this response,
+ * @return the content type that was set or calculated for this response,
* or <code>null</code> if no content type was set.
*/
@Override
@@ -563,7 +572,7 @@ public class Response implements HttpServletResponse {
/**
- * Return the actual buffer size used for this Response.
+ * @return the actual buffer size used for this Response.
*/
@Override
public int getBufferSize() {
@@ -572,16 +581,16 @@ public class Response implements HttpServletResponse {
/**
- * Return the character encoding used for this Response.
+ * @return the character encoding used for this Response.
*/
@Override
public String getCharacterEncoding() {
- return (getCoyoteResponse().getCharacterEncoding());
+ return getCoyoteResponse().getCharacterEncoding();
}
/**
- * Return the servlet output stream associated with this Response.
+ * @return the servlet output stream associated with this Response.
*
* @exception IllegalStateException if <code>getWriter</code> has
* already been called for this response
@@ -606,16 +615,16 @@ public class Response implements HttpServletResponse {
/**
- * Return the Locale assigned to this response.
+ * @return the Locale assigned to this response.
*/
@Override
public Locale getLocale() {
- return (getCoyoteResponse().getLocale());
+ return getCoyoteResponse().getLocale();
}
/**
- * Return the writer associated with this Response.
+ * @return the writer associated with this Response.
*
* @exception IllegalStateException if <code>getOutputStream</code> has
* already been called for this response
@@ -657,6 +666,8 @@ public class Response implements HttpServletResponse {
/**
* Has the output of this response already been committed?
+ *
+ * @return <code>true</code> if the response has been committed
*/
@Override
public boolean isCommitted() {
@@ -765,7 +776,6 @@ public class Response implements HttpServletResponse {
}
getCoyoteResponse().setContentLength(length);
-
}
@@ -811,7 +821,7 @@ public class Response implements HttpServletResponse {
}
- /*
+ /**
* Overrides the name of the character encoding used in the body
* of the request. This method must be called prior to reading
* request parameters or reading input using getReader().
@@ -889,7 +899,6 @@ public class Response implements HttpServletResponse {
@Override
public Collection<String> getHeaderNames() {
-
MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
int n = headers.size();
List<String> result = new ArrayList<String>(n);
@@ -903,19 +912,18 @@ public class Response implements HttpServletResponse {
@Override
public Collection<String> getHeaders(String name) {
-
Enumeration<String> enumeration =
getCoyoteResponse().getMimeHeaders().values(name);
- Vector<String> result = new Vector<String>();
+ List<String> result = new ArrayList<String>();
while (enumeration.hasMoreElements()) {
- result.addElement(enumeration.nextElement());
+ result.add(enumeration.nextElement());
}
return result;
}
/**
- * Return the error message that was set with <code>sendError()</code>
+ * @return the error message that was set with <code>sendError()</code>
* for this Response.
*/
public String getMessage() {
@@ -945,7 +953,6 @@ public class Response implements HttpServletResponse {
// -------------------------------------------- HttpServletResponse Methods
-
/**
* Add the specified Cookie to those that will be included with
* this Response.
@@ -970,8 +977,9 @@ public class Response implements HttpServletResponse {
/**
* Special method for adding a session cookie as we should be overriding
- * any previous
- * @param cookie
+ * any previous.
+ *
+ * @param cookie The new session cookie to add the response
*/
public void addSessionCookieInternal(final Cookie cookie) {
if (isCommitted()) {
@@ -1100,7 +1108,7 @@ public class Response implements HttpServletResponse {
* visible to {@link org.apache.coyote.Response}
*
* Called from set/addHeader.
- * Return true if the header is special, no need to set the header.
+ * @return <code>true</code> if the header is special, no need to set the header.
*/
private boolean checkSpecialHeader(String name, String value) {
if (name.equalsIgnoreCase("Content-Type")) {
@@ -1142,6 +1150,7 @@ public class Response implements HttpServletResponse {
* Has the specified header been set already in this response?
*
* @param name Name of the header to check
+ * @return <code>true</code> if the header has been set
*/
@Override
public boolean containsHeader(String name) {
@@ -1168,16 +1177,15 @@ public class Response implements HttpServletResponse {
* into the specified redirect URL, if necessary.
*
* @param url URL to be encoded
+ * @return <code>true</code> if the URL was encoded
*/
@Override
public String encodeRedirectURL(String url) {
-
if (isEncodeable(toAbsolute(url))) {
- return (toEncoded(url, request.getSessionInternal().getIdInternal()));
+ return toEncoded(url, request.getSessionInternal().getIdInternal());
} else {
- return (url);
+ return url;
}
-
}
@@ -1186,6 +1194,7 @@ public class Response implements HttpServletResponse {
* into the specified redirect URL, if necessary.
*
* @param url URL to be encoded
+ * @return <code>true</code> if the URL was encoded
*
* @deprecated As of Version 2.1 of the Java Servlet API, use
* <code>encodeRedirectURL()</code> instead.
@@ -1193,7 +1202,7 @@ public class Response implements HttpServletResponse {
@Override
@Deprecated
public String encodeRedirectUrl(String url) {
- return (encodeRedirectURL(url));
+ return encodeRedirectURL(url);
}
@@ -1202,6 +1211,7 @@ public class Response implements HttpServletResponse {
* into the specified URL, if necessary.
*
* @param url URL to be encoded
+ * @return <code>true</code> if the URL was encoded
*/
@Override
public String encodeURL(String url) {
@@ -1221,9 +1231,9 @@ public class Response implements HttpServletResponse {
} else if (url.equals(absolute) && !hasPath(url)) {
url += '/';
}
- return (toEncoded(url, request.getSessionInternal().getIdInternal()));
+ return toEncoded(url, request.getSessionInternal().getIdInternal());
} else {
- return (url);
+ return url;
}
}
@@ -1234,6 +1244,7 @@ public class Response implements HttpServletResponse {
* into the specified URL, if necessary.
*
* @param url URL to be encoded
+ * @return <code>true</code> if the URL was encoded
*
* @deprecated As of Version 2.1 of the Java Servlet API, use
* <code>encodeURL()</code> instead.
@@ -1241,12 +1252,12 @@ public class Response implements HttpServletResponse {
@Override
@Deprecated
public String encodeUrl(String url) {
- return (encodeURL(url));
+ return encodeURL(url);
}
/**
- * Send an acknowledgment of a request.
+ * Send an acknowledgement of a request.
*
* @exception IOException if an input/output error occurs
*/
@@ -1337,6 +1348,10 @@ public class Response implements HttpServletResponse {
* Internal method that allows a redirect to be sent with a status other
* than {@link HttpServletResponse#SC_FOUND} (302). No attempt is made to
* validate the status code.
+ *
+ * @param location Location URL to redirect to
+ * @param status HTTP status code that will be sent
+ * @throws IOException an IO exception occurred
*/
public void sendRedirect(String location, int status) throws IOException {
if (isCommitted()) {
@@ -1435,8 +1450,9 @@ public class Response implements HttpServletResponse {
char cc=name.charAt(0);
if (cc=='C' || cc=='c') {
- if (checkSpecialHeader(name, value))
- return;
+ if (checkSpecialHeader(name, value)) {
+ return;
+ }
}
getCoyoteResponse().setHeader(name, value);
@@ -1512,7 +1528,6 @@ public class Response implements HttpServletResponse {
// ------------------------------------------------------ Protected Methods
-
/**
* Return <code>true</code> if the specified URL should be encoded with
* a session identifier. This will be true if all of the following
@@ -1525,26 +1540,27 @@ public class Response implements HttpServletResponse {
* </ul>
*
* @param location Absolute URL to be validated
+ * @return <code>true</code> if the URL should be encoded
*/
protected boolean isEncodeable(final String location) {
if (location == null) {
- return (false);
+ return false;
}
// Is this an intra-document reference?
if (location.startsWith("#")) {
- return (false);
+ 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) {
- return (false);
+ return false;
}
if (hreq.isRequestedSessionIdFromCookie()) {
- return (false);
+ return false;
}
// Is URL encoding permitted
@@ -1574,15 +1590,15 @@ public class Response implements HttpServletResponse {
try {
url = new URL(location);
} catch (MalformedURLException e) {
- return (false);
+ return false;
}
// Does this URL match down to (and including) the context path?
if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol())) {
- return (false);
+ return false;
}
if (!hreq.getServerName().equalsIgnoreCase(url.getHost())) {
- return (false);
+ return false;
}
int serverPort = hreq.getServerPort();
if (serverPort == -1) {
@@ -1601,25 +1617,25 @@ public class Response implements HttpServletResponse {
}
}
if (serverPort != urlPort) {
- return (false);
+ return false;
}
String contextPath = getContext().getPath();
if (contextPath != null) {
String file = url.getFile();
if (!file.startsWith(contextPath)) {
- return (false);
+ return false;
}
String tok = ";" +
SessionConfig.getSessionUriParamName(request.getContext()) +
"=" + session.getIdInternal();
if( file.indexOf(tok, contextPath.length()) >= 0 ) {
- return (false);
+ return false;
}
}
// This URL belongs to our web application, so it is encodeable
- return (true);
+ return true;
}
@@ -1630,6 +1646,7 @@ public class Response implements HttpServletResponse {
* already absolute, return it unchanged.
*
* @param location URL to be (possibly) converted and then returned
+ * @return the encoded URL
*
* @exception IllegalArgumentException if a MalformedURLException is
* thrown when converting the relative URL to an absolute one
@@ -1637,7 +1654,7 @@ public class Response implements HttpServletResponse {
protected String toAbsolute(String location) {
if (location == null) {
- return (location);
+ return location;
}
boolean leadingSlash = location.startsWith("/");
@@ -1719,15 +1736,17 @@ public class Response implements HttpServletResponse {
} else {
- return (location);
+ return location;
}
}
- /*
+ /**
* Removes /./ and /../ sequences from absolute URLs.
* Code borrowed heavily from CoyoteAdapter.normalize()
+ *
+ * @param cc the char chunk containing the chars to normalize
*/
private void normalize(CharChunk cc) {
// Strip query string and/or fragment first as doing it this way makes
@@ -1813,14 +1832,15 @@ public class Response implements HttpServletResponse {
}
private void copyChars(char[] c, int dest, int src, int len) {
- for (int pos = 0; pos < len; pos++) {
- c[pos + dest] = c[pos + src];
- }
+ System.arraycopy(c, src, c, dest, len);
}
/**
- * Determine if an absolute URL has a path component
+ * Determine if an absolute URL has a path component.
+ *
+ * @param uri the URL that will be checked
+ * @return <code>true</code> if the URL has a path
*/
private boolean hasPath(String uri) {
int pos = uri.indexOf("://");
@@ -1856,11 +1876,11 @@ public class Response implements HttpServletResponse {
*
* @param url URL to be encoded with the session id
* @param sessionId Session id to be included in the encoded URL
+ * @return the encoded URL
*/
protected String toEncoded(String url, String sessionId) {
-
if ((url == null) || (sessionId == null)) {
- return (url);
+ return url;
}
String path = url;
@@ -1886,7 +1906,6 @@ public class Response implements HttpServletResponse {
}
sb.append(anchor);
sb.append(query);
- return (sb.toString());
-
+ return sb.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org