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/10 15:14:59 UTC
[tomcat] branch 7.0.x updated: Polish & minor refactoring to better
align with 8.5.x
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
The following commit(s) were added to refs/heads/7.0.x by this push:
new 0ebe425 Polish & minor refactoring to better align with 8.5.x
0ebe425 is described below
commit 0ebe425cad26bdafcabfc1f85f383491739d6ae7
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jul 10 15:49:19 2019 +0100
Polish & minor refactoring to better align with 8.5.x
This is in preparation for looking at the larger refactoring for the
addition of error state.
---
java/org/apache/coyote/Response.java | 104 +++++++++++++++++++++++------------
1 file changed, 68 insertions(+), 36 deletions(-)
diff --git a/java/org/apache/coyote/Response.java b/java/org/apache/coyote/Response.java
index 1d38316..38e62b2 100644
--- a/java/org/apache/coyote/Response.java
+++ b/java/org/apache/coyote/Response.java
@@ -32,7 +32,7 @@ import org.apache.tomcat.util.http.parser.MediaType;
* @author Jason Hunter [jch@eng.sun.com]
* @author James Todd [gonzo@eng.sun.com]
* @author Harish Prabandham
- * @author Hans Bergsten <ha...@gefionsoftware.com>
+ * @author Hans Bergsten [hans@gefionsoftware.com]
* @author Remy Maucherat
*/
public final class Response {
@@ -42,7 +42,7 @@ public final class Response {
/**
* Default locale as mandated by the spec.
*/
- private static Locale DEFAULT_LOCALE = Locale.getDefault();
+ private static final Locale DEFAULT_LOCALE = Locale.getDefault();
// ----------------------------------------------------- Instance Variables
@@ -62,7 +62,7 @@ public final class Response {
/**
* Response headers.
*/
- MimeHeaders headers = new MimeHeaders();
+ final MimeHeaders headers = new MimeHeaders();
/**
@@ -74,19 +74,19 @@ public final class Response {
/**
* Notes.
*/
- Object notes[] = new Object[Constants.MAX_NOTES];
+ final Object notes[] = new Object[Constants.MAX_NOTES];
/**
* Committed flag.
*/
- boolean committed = false;
+ volatile boolean committed = false;
/**
* Action hook.
*/
- public ActionHook hook;
+ public volatile ActionHook hook;
/**
@@ -114,6 +114,7 @@ public final class Response {
Request req;
+
// ------------------------------------------------------------- Properties
public Request getRequest() {
@@ -151,7 +152,6 @@ public final class Response {
// -------------------- Per-Response "notes" --------------------
-
public final void setNote(int pos, Object value) {
notes[pos] = value;
}
@@ -164,35 +164,38 @@ public final class Response {
// -------------------- Actions --------------------
-
public void action(ActionCode actionCode, Object param) {
if (hook != null) {
- if( param==null )
+ if (param == null) {
hook.action(actionCode, this);
- else
+ } else {
hook.action(actionCode, param);
+ }
}
}
// -------------------- State --------------------
-
public int getStatus() {
return status;
}
/**
- * Set the response status
+ * Set the response status.
+ *
+ * @param status The status value to set
*/
- public void setStatus( int status ) {
+ public void setStatus(int status) {
this.status = status;
}
/**
* Get the status message.
+ *
+ * @return The message associated with the current status
*/
public String getMessage() {
return message;
@@ -201,6 +204,8 @@ public final class Response {
/**
* Set the status message.
+ *
+ * @param message The status message to set
*/
public void setMessage(String message) {
this.message = message;
@@ -230,10 +235,10 @@ public final class Response {
// -----------------Error State --------------------
-
/**
- * Set the error Exception that occurred during
- * request processing.
+ * Set the error Exception that occurred during request processing.
+ *
+ * @param ex The exception that occurred
*/
public void setErrorException(Exception ex) {
errorException = ex;
@@ -241,8 +246,9 @@ public final class Response {
/**
- * Get the Exception that occurred during request
- * processing.
+ * Get the Exception that occurred during request processing.
+ *
+ * @return The exception that occurred
*/
public Exception getErrorException() {
return errorException;
@@ -281,8 +287,14 @@ public final class Response {
// -------------------- Headers --------------------
/**
- * Warning: This method always returns <code>false<code> for Content-Type
+ * Does the response contain the given header.
+ * <br>
+ * Warning: This method always returns <code>false</code> for Content-Type
* and Content-Length.
+ *
+ * @param name The name of the header of interest
+ *
+ * @return {@code true} if the response contains the header.
*/
public boolean containsHeader(String name) {
return headers.getHeader(name) != null;
@@ -354,8 +366,10 @@ public final class Response {
}
/**
- * Called explicitly by user to set the Content-Language and
- * the default encoding
+ * Called explicitly by user to set the Content-Language and the default
+ * encoding.
+ *
+ * @param locale The locale to use for this response
*/
public void setLocale(Locale locale) {
@@ -382,33 +396,42 @@ public final class Response {
/**
* Return the content language.
+ *
+ * @return The language code for the language currently associated with this
+ * response
*/
public String getContentLanguage() {
return contentLanguage;
}
- /*
- * Overrides the name of the character encoding used in the body
- * of the response. This method must be called prior to writing output
- * using getWriter().
+
+ /**
+ * Overrides the character encoding used in the body of the response. This
+ * method must be called prior to writing output using getWriter().
*
- * @param charset String containing the name of the character encoding.
+ * @param characterEncoding The name of character encoding.
*/
- public void setCharacterEncoding(String charset) {
-
- if (isCommitted())
+ public void setCharacterEncoding(String characterEncoding) {
+ if (isCommitted()) {
return;
- if (charset == null)
+ }
+ if (characterEncoding == null) {
return;
+ }
- characterEncoding = charset;
- charsetSet=true;
+ this.characterEncoding = characterEncoding;
+ charsetSet = true;
}
+
+ /**
+ * @return The name of the current encoding
+ */
public String getCharacterEncoding() {
return characterEncoding;
}
+
/**
* Sets the content type.
*
@@ -459,9 +482,7 @@ public final class Response {
String ret = contentType;
- if (ret != null
- && characterEncoding != null
- && charsetSet) {
+ if (ret != null && characterEncoding != null && charsetSet) {
ret = ret + ";charset=" + characterEncoding;
}
@@ -489,13 +510,14 @@ public final class Response {
/**
* Write a chunk of bytes.
*/
- public void doWrite(ByteChunk chunk/*byte buffer[], int pos, int count*/)
+ public void doWrite(ByteChunk chunk)
throws IOException
{
outputBuffer.doWrite(chunk, this);
contentWritten+=chunk.getLength();
}
+
// --------------------
public void recycle() {
@@ -519,6 +541,10 @@ public final class Response {
/**
* Bytes written by application - i.e. before compression, chunking, etc.
+ *
+ * @return The total number of bytes written to the response by the
+ * application. This will not be the number of bytes written to the
+ * network which may be more or less than this value.
*/
public long getContentWritten() {
return contentWritten;
@@ -526,6 +552,12 @@ public final class Response {
/**
* Bytes written to socket - i.e. after compression, chunking, etc.
+ *
+ * @param flush Should any remaining bytes be flushed before returning the
+ * total? If {@code false} bytes remaining in the buffer will
+ * not be included in the returned value
+ *
+ * @return The total number of bytes written to the socket for this response
*/
public long getBytesWritten(boolean flush) {
if (flush) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org