Class Response
java.lang.Object
org.apache.coyote.Response
Response object.
- Author:
- James Duncan Davidson [duncan@eng.sun.com], Jason Hunter [jch@eng.sun.com], James Todd [gonzo@eng.sun.com], Harish Prabandham, Hans Bergsten [hans@gefionsoftware.com], Remy Maucherat
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaction(ActionCode actionCode, Object param) voidvoidbooleanvoidcommit()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.longReturn the time the response was committed (based on System.currentTimeMillis).Return the content language.intlonglongBytes written by application - i.e. before compression, chunking, etc.Get the Exception that occurred during the writing of the response.Get the status message.getNote(int pos) intbooleanbooleanisError()Error flag accessor.booleanbooleanbooleanisReady()voidvoidrecycle()voidreset()voidvoidDeprecated.Unused.voidsetCharacterEncoding(String characterEncoding) Overrides the character encoding used in the body of the response.voidsetCommitted(boolean v) voidsetContentLength(long contentLength) voidsetContentType(String type) Sets the content type.voidbooleansetError()Deprecated.This method will be changed to return void in Tomcat 11 onwardsvoidSet the error Exception that occurred during the writing of the response processing.booleanvoidvoidCalled explicitly by user to set the Content-Language and the default encoding.voidsetMessage(String message) Set the status message.voidvoidsetOutputBuffer(OutputBuffer outputBuffer) voidsetRequest(Request req) voidsetStatus(int status) Set the response status.voidsetTrailerFields(Supplier<Map<String, String>> supplier) voidsetWriteListener(WriteListener listener)
-
Constructor Details
-
Response
public Response()
-
-
Method Details
-
getRequest
-
setRequest
-
setOutputBuffer
-
getMimeHeaders
-
setNote
-
getNote
-
action
-
getStatus
public int getStatus() -
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() -
setCommitted
public void setCommitted(boolean v) -
getCommitTime
public long getCommitTime()Return the time the response was committed (based on System.currentTimeMillis).- 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() -
setError
Deprecated.This method will be changed to return void in Tomcat 11 onwardsSet the error flag.- Returns:
falseif the error flag was already set
-
isError
public boolean isError()Error flag accessor.- Returns:
trueif the response has encountered an error
-
isErrorReportRequired
public boolean isErrorReportRequired() -
setErrorReported
public boolean setErrorReported() -
resetError
public void resetError() -
reset
- Throws:
IllegalStateException
-
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
-
sendHeaders
Deprecated.Unused. Will be removed in Tomcat 11 onwards. Usecommit().Signal that we're done with the headers, and body will follow. -
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
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
-
getCharacterEncoding
- Returns:
- The name of the current encoding
-
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
-
getContentType
-
setContentLength
public void setContentLength(long contentLength) -
getContentLength
public int getContentLength() -
getContentLengthLong
public long getContentLengthLong() -
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() -
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
-
isReady
public boolean isReady() -
checkRegisterForWrite
public boolean checkRegisterForWrite() -
onWritePossible
- Throws:
IOException
-