Package org.apache.coyote
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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaction(ActionCode actionCode, Object param) voidvoidbooleanbooleancontainsHeader(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).longReturn the time the response was committed (based on System.nanoTime).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()voidSignal that we're done with the headers, and body will follow.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.booleanvoidprotected voidsetHook(ActionHook hook) voidCalled 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- 
Responsepublic Response()
 
- 
- 
Method Details- 
getRequest
- 
setRequest
- 
setOutputBuffer
- 
getMimeHeaders
- 
setHook
- 
setNote
- 
getNote
- 
action
- 
getStatuspublic int getStatus()
- 
setStatuspublic void setStatus(int status) Set the response status.- Parameters:
- status- The status value to set
 
- 
getMessageGet the status message.- Returns:
- The message associated with the current status
 
- 
setMessageSet the status message.- Parameters:
- message- The status message to set
 
- 
isCommittedpublic boolean isCommitted()
- 
setCommittedpublic void setCommitted(boolean v) 
- 
getCommitTimepublic long getCommitTime()Return the time the response was committed (based on System.currentTimeMillis).- Returns:
- the time the response was committed
 
- 
getCommitTimeNanospublic long getCommitTimeNanos()Return the time the response was committed (based on System.nanoTime).- Returns:
- the time the response was committed
 
- 
setErrorExceptionSet the error Exception that occurred during the writing of the response processing.- Parameters:
- ex- The exception that occurred
 
- 
getErrorExceptionGet the Exception that occurred during the writing of the response.- Returns:
- The exception that occurred
 
- 
isExceptionPresentpublic boolean isExceptionPresent()
- 
setErrorDeprecated.This method will be changed to return void in Tomcat 11 onwardsSet the error flag.- Returns:
- falseif the error flag was already set
 
- 
isErrorpublic boolean isError()Error flag accessor.- Returns:
- trueif the response has encountered an error
 
- 
isErrorReportRequiredpublic boolean isErrorReportRequired()
- 
setErrorReportedpublic boolean setErrorReported()
- 
reset- Throws:
- IllegalStateException
 
- 
containsHeaderDoes 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
- 
sendHeaderspublic void sendHeaders()Signal that we're done with the headers, and body will follow. Any implementation needs to notify ContextManager, to allow interceptors to fix headers.
- 
getLocale
- 
setLocaleCalled explicitly by user to set the Content-Language and the default encoding.- Parameters:
- locale- The locale to use for this response
 
- 
getContentLanguageReturn the content language.- Returns:
- The language code for the language currently associated with this response
 
- 
setCharacterEncodingOverrides 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
 
- 
setContentTypeSets 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
- 
setContentLengthpublic void setContentLength(long contentLength) 
- 
getContentLengthpublic int getContentLength()
- 
getContentLengthLongpublic long getContentLengthLong()
- 
doWriteWrite a chunk of bytes.- Parameters:
- chunk- The ByteBuffer to write
- Throws:
- IOException- If an I/O error occurs during the write
 
- 
recyclepublic void recycle()
- 
getContentWrittenpublic 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.
 
- 
getBytesWrittenpublic 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? If- falsebytes 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
- 
isReadypublic boolean isReady()
- 
checkRegisterForWritepublic boolean checkRegisterForWrite()
- 
onWritePossible- Throws:
- IOException
 
 
-