org.apache.tomcat.core
Class ResponseImpl

java.lang.Object
  |
  +--org.apache.tomcat.core.ResponseImpl

public class ResponseImpl
extends java.lang.Object
implements Response

Author:
James Duncan Davidson [duncan@eng.sun.com], Jason Hunter [jch@eng.sun.com], James Todd [gonzo@eng.sun.com], Harish Prabandham, Hans Bergsten

Field Summary
protected  org.apache.tomcat.util.ByteBuffer bBuffer
           
protected  java.lang.String characterEncoding
           
protected  boolean commited
           
protected  java.lang.String contentLanguage
           
protected  int contentLength
           
protected  java.lang.String contentType
           
protected  org.apache.tomcat.util.MimeHeaders headers
           
protected  BufferedServletOutputStream out
           
protected  Request request
           
protected  javax.servlet.http.HttpServletResponse responseFacade
           
protected  java.lang.String sessionId
           
protected static org.apache.tomcat.util.StringManager sm
           
protected  boolean started
           
protected  int status
           
protected  java.util.Vector userCookies
           
protected  boolean usingStream
           
protected  boolean usingWriter
           
protected  java.io.PrintWriter writer
           
 
Constructor Summary
ResponseImpl()
           
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
           
 void addHeader(java.lang.String name, java.lang.String value)
           
 boolean containsHeader(java.lang.String name)
           
 void doWrite(byte[] buffer, int pos, int count)
          Write a chunk of bytes.
 void endHeaders()
          Signal that we're done with the headers, and body will follow.
 void finish()
          Signal that we're done with a particular request, the server can go on and read more requests or close the socket
 void flushBuffer()
          Any implementation needs to notify ContextManger
 java.lang.StringBuffer getBody()
           
 BufferedServletOutputStream getBufferedOutputStream()
          Either implement ServletOutputStream or return BufferedServletOutputStream(this) and implement doWrite();
 int getBufferSize()
           
 java.lang.String getCharacterEncoding()
          translate locale into encoding.
 int getContentLength()
           
 java.lang.String getContentType()
           
 java.io.Writer getConverter(javax.servlet.ServletOutputStream outs)
           
 java.util.Enumeration getCookies()
           
 javax.servlet.http.HttpServletResponse getFacade()
          One-to-one with Facade.
 java.util.Locale getLocale()
           
static java.lang.String getMessage(int status)
           
 org.apache.tomcat.util.MimeHeaders getMimeHeaders()
           
 org.apache.tomcat.util.ByteBuffer getOutputBuffer()
           
 javax.servlet.ServletOutputStream getOutputStream()
          Deprecated.  
 Request getRequest()
           
 java.lang.String getSessionId()
           
 int getStatus()
           
 java.io.PrintWriter getWriter()
           
 java.io.PrintWriter getWriter(javax.servlet.ServletOutputStream outs)
           
 boolean isBufferCommitted()
           
 boolean isIncluded()
          True if we are in an included servlet
 boolean isStarted()
          True if getOutputStream or getWriter was called.
 boolean isUsingStream()
          True if getOutputStream was called.
 boolean isUsingWriter()
          Stream/Writer control
 void notifyEndHeaders()
          Signal that we're done with the headers, and body will follow.
 void recycle()
          Response objects will be pool-able
 void reset()
           
 void resetBuffer()
           
 void setBufferCommitted(boolean v)
           
 void setBufferSize(int size)
           
 void setContentLength(int contentLength)
           
 void setContentType(java.lang.String contentType)
          Set content type - this might also set encoding, if specified
 void setHeader(java.lang.String name, java.lang.String value)
           
 void setIncluded(boolean incl)
          The response will not set any header or the status line - it can only write to the output stream or flush.
 void setLocale(java.util.Locale locale)
           
 void setOutputBuffer(org.apache.tomcat.util.ByteBuffer buf)
           
 void setRequest(Request request)
          One-to-one relation with Request
 void setSessionId(java.lang.String id)
          Will set the session id.
 void setStatus(int status)
          Set the response status
 void setUsingStream(boolean stream)
          The output stream is used.
 void setUsingWriter(boolean writer)
          Stream/Writer control
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sm

protected static org.apache.tomcat.util.StringManager sm

request

protected Request request

responseFacade

protected javax.servlet.http.HttpServletResponse responseFacade

userCookies

protected java.util.Vector userCookies

contentType

protected java.lang.String contentType

contentLanguage

protected java.lang.String contentLanguage

characterEncoding

protected java.lang.String characterEncoding

sessionId

protected java.lang.String sessionId

contentLength

protected int contentLength

status

protected int status

headers

protected org.apache.tomcat.util.MimeHeaders headers

out

protected BufferedServletOutputStream out

writer

protected java.io.PrintWriter writer

bBuffer

protected org.apache.tomcat.util.ByteBuffer bBuffer

usingStream

protected boolean usingStream

usingWriter

protected boolean usingWriter

started

protected boolean started

commited

protected boolean commited
Constructor Detail

ResponseImpl

public ResponseImpl()
Method Detail

getFacade

public javax.servlet.http.HttpServletResponse getFacade()
Description copied from interface: Response
One-to-one with Facade. You can use HttpResponseFacade.
Specified by:
getFacade in interface Response

setRequest

public void setRequest(Request request)
Description copied from interface: Response
One-to-one relation with Request
Specified by:
setRequest in interface Response

getRequest

public Request getRequest()
Specified by:
getRequest in interface Response

isIncluded

public boolean isIncluded()
Description copied from interface: Response
True if we are in an included servlet
Specified by:
isIncluded in interface Response

setIncluded

public void setIncluded(boolean incl)
Description copied from interface: Response
The response will not set any header or the status line - it can only write to the output stream or flush. This is used to implement RD.include() and can be used for HTTP/0.9
Specified by:
setIncluded in interface Response

isStarted

public boolean isStarted()
Description copied from interface: Response
True if getOutputStream or getWriter was called. XXX change it to "if any output was writen" Used by RD.forward() and ServletWrapper.error()
Specified by:
isStarted in interface Response

recycle

public void recycle()
Description copied from interface: Response
Response objects will be pool-able
Specified by:
recycle in interface Response

finish

public void finish()
            throws java.io.IOException
Description copied from interface: Response
Signal that we're done with a particular request, the server can go on and read more requests or close the socket
Specified by:
finish in interface Response

containsHeader

public boolean containsHeader(java.lang.String name)
Specified by:
containsHeader in interface Response

isUsingStream

public boolean isUsingStream()
Description copied from interface: Response
True if getOutputStream was called. Used to avoid the ugly try getWriter() catch getOutputStream.
Specified by:
isUsingStream in interface Response

setUsingStream

public void setUsingStream(boolean stream)
Description copied from interface: Response
The output stream is used.
Specified by:
setUsingStream in interface Response

isUsingWriter

public boolean isUsingWriter()
Description copied from interface: Response
Stream/Writer control
Specified by:
isUsingWriter in interface Response

setUsingWriter

public void setUsingWriter(boolean writer)
Description copied from interface: Response
Stream/Writer control
Specified by:
setUsingWriter in interface Response

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Specified by:
getWriter in interface Response

getWriter

public java.io.PrintWriter getWriter(javax.servlet.ServletOutputStream outs)
                              throws java.io.IOException

getConverter

public java.io.Writer getConverter(javax.servlet.ServletOutputStream outs)
                            throws java.io.IOException

getOutputBuffer

public org.apache.tomcat.util.ByteBuffer getOutputBuffer()
Specified by:
getOutputBuffer in interface Response

setOutputBuffer

public void setOutputBuffer(org.apache.tomcat.util.ByteBuffer buf)
Specified by:
setOutputBuffer in interface Response

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
Deprecated.  

Either implement ServletOutputStream or return BufferedServletOutputStream(this) and implement doWrite();
Specified by:
getOutputStream in interface Response

getBufferedOutputStream

public BufferedServletOutputStream getBufferedOutputStream()
Either implement ServletOutputStream or return BufferedServletOutputStream(this) and implement doWrite();

getMimeHeaders

public org.apache.tomcat.util.MimeHeaders getMimeHeaders()
Specified by:
getMimeHeaders in interface Response

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
Specified by:
setHeader in interface Response

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
Specified by:
addHeader in interface Response

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface Response

setBufferSize

public void setBufferSize(int size)
                   throws java.lang.IllegalStateException
Specified by:
setBufferSize in interface Response

isBufferCommitted

public boolean isBufferCommitted()
Specified by:
isBufferCommitted in interface Response

setBufferCommitted

public void setBufferCommitted(boolean v)

reset

public void reset()
           throws java.lang.IllegalStateException
Specified by:
reset in interface Response

resetBuffer

public void resetBuffer()
                 throws java.lang.IllegalStateException
Specified by:
resetBuffer in interface Response

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Description copied from interface: Response
Any implementation needs to notify ContextManger
Specified by:
flushBuffer in interface Response

endHeaders

public void endHeaders()
                throws java.io.IOException
Signal that we're done with the headers, and body will follow. Any implementation needs to notify ContextManager, to allow interceptors to fix headers.
Specified by:
endHeaders in interface Response

notifyEndHeaders

public void notifyEndHeaders()
                      throws java.io.IOException
Signal that we're done with the headers, and body will follow. Any implementation needs to notify ContextManager, to allow interceptors to fix headers.

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Specified by:
addCookie in interface Response

getCookies

public java.util.Enumeration getCookies()
Specified by:
getCookies in interface Response

setSessionId

public void setSessionId(java.lang.String id)
Description copied from interface: Response
Will set the session id. The session interceptor might process it and add a Cookie header, and it can be used to rewrite URLs. This replace "system cookies" ( it was the only use for them )
Specified by:
setSessionId in interface Response

getSessionId

public java.lang.String getSessionId()
Specified by:
getSessionId in interface Response

getLocale

public java.util.Locale getLocale()
Specified by:
getLocale in interface Response

setLocale

public void setLocale(java.util.Locale locale)
Specified by:
setLocale in interface Response

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Description copied from interface: Response
translate locale into encoding.
Specified by:
getCharacterEncoding in interface Response

setContentType

public void setContentType(java.lang.String contentType)
Description copied from interface: Response
Set content type - this might also set encoding, if specified
Specified by:
setContentType in interface Response

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface Response

setContentLength

public void setContentLength(int contentLength)
Specified by:
setContentLength in interface Response

getContentLength

public int getContentLength()
Specified by:
getContentLength in interface Response

getStatus

public int getStatus()
Specified by:
getStatus in interface Response

setStatus

public void setStatus(int status)
Set the response status
Specified by:
setStatus in interface Response

doWrite

public void doWrite(byte[] buffer,
                    int pos,
                    int count)
             throws java.io.IOException
Write a chunk of bytes. Should be called only from ServletOutputStream implementations, No need to implement it if your adapter implements ServletOutputStream. Headers and status will be written before this method is exceuted.
Specified by:
doWrite in interface Response

getBody

public java.lang.StringBuffer getBody()

getMessage

public static java.lang.String getMessage(int status)


Copyright © 2000 Apache Software Foundation. All Rights Reserved.