Class Response
java.lang.Object
org.apache.coyote.Response
Response object.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaction(ActionCode actionCode, Object param) Perform an action on this response.voidAdd a response header with the given name and value.voidAdd a response header with the given name, value, and charset.booleanCheck and register for write interest.voidcommit()Signal that we're done with the headers, and body will follow.booleancontainsHeader(String name) Does the response contain the given header.voiddoWrite(ByteBuffer chunk) Write a chunk of bytes.longgetBytesWritten(boolean flush) Bytes written to socket - i.e. after compression, chunking, etc.Deprecated.Unused.Deprecated.Unused.Get the charset holder.longReturn the time the response was committed (based on System.currentTimeMillis).longReturn the time the response was committed (based on System.nanoTime).Return the content language.intGet the content length as an int.longGet the content length as a long.Get the content type.longBytes written by application - i.e. before compression, chunking, etc.Get the Exception that occurred during the writing of the response.Get the locale for this response.Get the status message.Get the response headers.getNote(int pos) Get the note at the given position.Get the associated request.intGet the response status code.Get the trailer fields supplier.Get the write listener.booleanCheck if the response has been committed.booleanisError()Error flag accessor.booleanCheck if error report is required.booleanCheck if an exception has occurred during response writing.booleanisReady()Check if the response is ready for writing.voidCalled when writing is possible.voidrecycle()Recycle this response.voidreset()Reset the response to its initial state.voidReset the error state.voidsetCharacterEncoding(String characterEncoding) Deprecated.Unused.voidsetCharsetHolder(CharsetHolder charsetHolder) Set the charset holder.voidsetCommitted(boolean v) Set the committed flag.voidsetContentLength(long contentLength) Set the content length.voidsetContentType(String type) Sets the content type.voidSet the content type without charset.voidsetError()Set the error flag if not already set.voidSet the error Exception that occurred during the writing of the response processing.booleanSet the error as reported.voidSet a response header.voidCalled explicitly by user to set the Content-Language and the default encoding.voidsetMessage(String message) Set the status message.voidSet a note at the given position.voidsetOutputBuffer(OutputBuffer outputBuffer) Set the output buffer.voidsetRequest(Request req) Set the associated request.voidsetStatus(int status) Set the response status.voidsetTrailerFields(Supplier<Map<String, String>> supplier) Set the trailer fields supplier.voidsetWriteListener(WriteListener listener) Set the write listener.
-
Constructor Details
-
Response
public Response()Default constructor.
-
-
Method Details
-
getRequest
-
setRequest
Set the associated request.- Parameters:
req- The associated request
-
setOutputBuffer
Set the output buffer.- Parameters:
outputBuffer- The output buffer
-
getMimeHeaders
-
setNote
Set a note at the given position.- Parameters:
pos- The positionvalue- The value to set
-
getNote
Get the note at the given position.- Parameters:
pos- The position- Returns:
- The note value
-
action
Perform an action on this response.- Parameters:
actionCode- The action codeparam- The action parameter
-
getStatus
public int getStatus()Get the response status code.- Returns:
- The response status code
-
setStatus
public void setStatus(int status) Set the response status.- Parameters:
status- The status value to set
-
getMessage
Get the status message.- Returns:
- The message associated with the current status
-
setMessage
Set the status message.- Parameters:
message- The status message to set
-
isCommitted
public boolean isCommitted()Check if the response has been committed.- Returns:
trueif the response has been committed
-
setCommitted
public void setCommitted(boolean v) Set the committed flag.- Parameters:
v- The committed flag value
-
getCommitTime
public long getCommitTime()Return the time the response was committed (based on System.currentTimeMillis).- Returns:
- the time the response was committed
-
getCommitTimeNanos
public long getCommitTimeNanos()Return the time the response was committed (based on System.nanoTime).- Returns:
- the time the response was committed
-
setErrorException
Set the error Exception that occurred during the writing of the response processing.- Parameters:
ex- The exception that occurred
-
getErrorException
Get the Exception that occurred during the writing of the response.- Returns:
- The exception that occurred
-
isExceptionPresent
public boolean isExceptionPresent()Check if an exception has occurred during response writing.- Returns:
trueif an exception has occurred
-
setError
public void setError()Set the error flag if not already set. -
isError
public boolean isError()Error flag accessor.- Returns:
trueif the response has encountered an error
-
isErrorReportRequired
public boolean isErrorReportRequired()Check if error report is required.- Returns:
trueif error report is required
-
setErrorReported
public boolean setErrorReported()Set the error as reported.- Returns:
trueif the error state was successfully transitioned to reported
-
resetError
public void resetError()Reset the error state. -
reset
Reset the response to its initial state.- Throws:
IllegalStateException- if the response has already been committed
-
containsHeader
Does the response contain the given header.
Warning: This method always returnsfalsefor Content-Type and Content-Length.- Parameters:
name- The name of the header of interest- Returns:
trueif the response contains the header.
-
setHeader
-
addHeader
-
addHeader
-
setTrailerFields
-
getTrailerFields
-
commit
public void commit()Signal that we're done with the headers, and body will follow. -
getLocale
-
setLocale
Called explicitly by user to set the Content-Language and the default encoding.- Parameters:
locale- The locale to use for this response
-
getContentLanguage
Return the content language.- Returns:
- The language code for the language currently associated with this response
-
setCharacterEncoding
@Deprecated public void setCharacterEncoding(String characterEncoding) throws UnsupportedEncodingException Deprecated.Unused. Will be removed in Tomcat 12.Overrides the character encoding used in the body of the response. This method must be called prior to writing output using getWriter().- Parameters:
characterEncoding- The name of character encoding.- Throws:
UnsupportedEncodingException- If the specified name is not recognised
-
getCharset
Deprecated.Unused. Will be removed in Tomcat 12.Returns the current character set.- Returns:
- The current character set
-
getCharacterEncoding
Deprecated.Unused. Will be removed in Tomcat 12.Returns the name of the current encoding.- Returns:
- The name of the current encoding
-
getCharsetHolder
-
setCharsetHolder
Set the charset holder.- Parameters:
charsetHolder- The charset holder
-
setContentType
Sets the content type. This method must preserve any response charset that may already have been set via a call to response.setContentType(), response.setLocale(), or response.setCharacterEncoding().- Parameters:
type- the content type
-
setContentTypeNoCharset
Set the content type without charset.- Parameters:
type- The content type
-
getContentType
Get the content type.- Returns:
- The content type, including charset if set
-
setContentLength
public void setContentLength(long contentLength) Set the content length.- Parameters:
contentLength- The content length
-
getContentLength
public int getContentLength()Get the content length as an int.- Returns:
- The content length as an int, or -1 if the length exceeds Integer.MAX_VALUE
-
getContentLengthLong
public long getContentLengthLong()Get the content length as a long.- Returns:
- The content length
-
doWrite
Write a chunk of bytes.- Parameters:
chunk- The ByteBuffer to write- Throws:
IOException- If an I/O error occurs during the write
-
recycle
public void recycle()Recycle this response. -
getContentWritten
public long getContentWritten()Bytes written by application - i.e. before compression, chunking, etc.- Returns:
- 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.
-
getBytesWritten
public long getBytesWritten(boolean flush) Bytes written to socket - i.e. after compression, chunking, etc.- Parameters:
flush- Should any remaining bytes be flushed before returning the total? Iffalsebytes remaining in the buffer will not be included in the returned value- Returns:
- The total number of bytes written to the socket for this response
-
getWriteListener
-
setWriteListener
Set the write listener.- Parameters:
listener- The write listener
-
isReady
public boolean isReady()Check if the response is ready for writing.- Returns:
trueif ready for writing
-
checkRegisterForWrite
public boolean checkRegisterForWrite()Check and register for write interest.- Returns:
trueif ready for write
-
onWritePossible
Called when writing is possible.- Throws:
IOException- If an I/O error occurs
-