FileDocCategorySizeDatePackage
Response.javaAPI DocApache Tomcat 6.0.1444972Fri Jul 20 04:20:30 BST 2007org.apache.catalina.connector

Response

public class Response extends Object implements HttpServletResponse
Wrapper object for the Coyote response.
author
Remy Maucherat
author
Craig R. McClanahan
version
$Revision: 555304 $ $Date: 2007-07-11 17:28:52 +0200 (mer., 11 juil. 2007) $

Fields Summary
protected static final String
info
Descriptive information about this Response implementation.
protected static org.apache.catalina.util.StringManager
sm
The string manager for this package.
protected SimpleDateFormat
format
The date format we will use for creating date headers.
protected Connector
connector
Associated Catalina connector.
protected org.apache.coyote.Response
coyoteResponse
Coyote response.
protected OutputBuffer
outputBuffer
The associated output buffer.
protected CoyoteOutputStream
outputStream
The associated output stream.
protected CoyoteWriter
writer
The associated writer.
protected boolean
appCommitted
The application commit flag.
protected boolean
included
The included flag.
private boolean
isCharacterEncodingSet
The characterEncoding flag
protected boolean
error
The error flag.
protected ArrayList
cookies
The set of Cookies associated with this Response.
protected boolean
usingOutputStream
Using output stream flag.
protected boolean
usingWriter
Using writer flag.
protected org.apache.tomcat.util.buf.UEncoder
urlEncoder
URL encoder.
protected org.apache.tomcat.util.buf.CharChunk
redirectURLCC
Recyclable buffer to hold the redirect URL.
protected Request
request
The request with which this response is associated.
protected ResponseFacade
facade
The facade associated with this response.
Constructors Summary
public Response()

        // Ensure that URL is loaded for SM
        URL.isSchemeChar('c");
    
        urlEncoder.addSafeCharacter('/");
    
Methods Summary
public voidaddCookie(javax.servlet.http.Cookie cookie)
Add the specified Cookie to those that will be included with this Response.

param
cookie Cookie to be added


        // Ignore any call from an included servlet
        if (included)
            return;

        addCookieInternal(cookie);

    
public voidaddCookieInternal(javax.servlet.http.Cookie cookie)
Add the specified Cookie to those that will be included with this Response.

param
cookie Cookie to be added


        if (isCommitted())
            return;

        cookies.add(cookie);

        final StringBuffer sb = new StringBuffer();
        if (SecurityUtil.isPackageProtectionEnabled()) {
            AccessController.doPrivileged(new PrivilegedAction() {
                public Object run(){
                    ServerCookie.appendCookieValue
                        (sb, cookie.getVersion(), cookie.getName(), 
                         cookie.getValue(), cookie.getPath(), 
                         cookie.getDomain(), cookie.getComment(), 
                         cookie.getMaxAge(), cookie.getSecure());
                    return null;
                }
            });
        } else {
            ServerCookie.appendCookieValue
                (sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
                     cookie.getPath(), cookie.getDomain(), cookie.getComment(), 
                     cookie.getMaxAge(), cookie.getSecure());
        }

        // the header name is Set-Cookie for both "old" and v.1 ( RFC2109 )
        // RFC2965 is not supported by browsers and the Servlet spec
        // asks for 2109.
        addHeader("Set-Cookie", sb.toString());

    
public voidaddDateHeader(java.lang.String name, long value)
Add the specified date header to the specified value.

param
name Name of the header to set
param
value Date value to be set


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included) {
            return;
        }

        if (format == null) {
            format = new SimpleDateFormat(DateTool.HTTP_RESPONSE_DATE_HEADER,
                                          Locale.US);
            format.setTimeZone(TimeZone.getTimeZone("GMT"));
        }

        addHeader(name, FastHttpDateFormat.formatDate(value, format));

    
public voidaddHeader(java.lang.String name, java.lang.String value)
Add the specified header to the specified value.

param
name Name of the header to set
param
value Value to be set


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return;

        coyoteResponse.addHeader(name, value);

    
public voidaddIntHeader(java.lang.String name, int value)
Add the specified integer header to the specified value.

param
name Name of the header to set
param
value Integer value to be set


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return;

        addHeader(name, "" + value);

    
public voidclearEncoders()
Clear cached encoders (to save memory for Comet requests).

        outputBuffer.clearEncoders();
    
public booleancontainsHeader(java.lang.String name)
Has the specified header been set already in this response?

param
name Name of the header to check

        // Need special handling for Content-Type and Content-Length due to
        // special handling of these in coyoteResponse
        char cc=name.charAt(0);
        if(cc=='C" || cc=='c") {
            if(name.equalsIgnoreCase("Content-Type")) {
                // Will return null if this has not been set
                return (coyoteResponse.getContentType() != null);
            }
            if(name.equalsIgnoreCase("Content-Length")) {
                // -1 means not known and is not sent to client
                return (coyoteResponse.getContentLengthLong() != -1);
            }
        }

        return coyoteResponse.containsHeader(name);
    
public javax.servlet.ServletOutputStreamcreateOutputStream()
Create and return a ServletOutputStream to write the content associated with this Response.

exception
IOException if an input/output error occurs

        // Probably useless
        if (outputStream == null) {
            outputStream = new CoyoteOutputStream(outputBuffer);
        }
        return outputStream;
    
private booleandoIsEncodeable(Request hreq, org.apache.catalina.Session session, java.lang.String location)

        // Is this a valid absolute URL?
        URL url = null;
        try {
            url = new URL(location);
        } catch (MalformedURLException e) {
            return (false);
        }

        // Does this URL match down to (and including) the context path?
        if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol()))
            return (false);
        if (!hreq.getServerName().equalsIgnoreCase(url.getHost()))
            return (false);
        int serverPort = hreq.getServerPort();
        if (serverPort == -1) {
            if ("https".equals(hreq.getScheme()))
                serverPort = 443;
            else
                serverPort = 80;
        }
        int urlPort = url.getPort();
        if (urlPort == -1) {
            if ("https".equals(url.getProtocol()))
                urlPort = 443;
            else
                urlPort = 80;
        }
        if (serverPort != urlPort)
            return (false);

        String contextPath = getContext().getPath();
        if (contextPath != null) {
            String file = url.getFile();
            if ((file == null) || !file.startsWith(contextPath))
                return (false);
            String tok = ";" + Globals.SESSION_PARAMETER_NAME + "=" + session.getIdInternal();
            if( file.indexOf(tok, contextPath.length()) >= 0 )
                return (false);
        }

        // This URL belongs to our web application, so it is encodeable
        return (true);

    
public java.lang.StringencodeRedirectURL(java.lang.String url)
Encode the session identifier associated with this response into the specified redirect URL, if necessary.

param
url URL to be encoded


        if (isEncodeable(toAbsolute(url))) {
            return (toEncoded(url, request.getSessionInternal().getIdInternal()));
        } else {
            return (url);
        }

    
public java.lang.StringencodeRedirectUrl(java.lang.String url)
Encode the session identifier associated with this response into the specified redirect URL, if necessary.

param
url URL to be encoded
deprecated
As of Version 2.1 of the Java Servlet API, use encodeRedirectURL() instead.

        return (encodeRedirectURL(url));
    
public java.lang.StringencodeURL(java.lang.String url)
Encode the session identifier associated with this response into the specified URL, if necessary.

param
url URL to be encoded

        
        String absolute = toAbsolute(url);
        if (isEncodeable(absolute)) {
            // W3c spec clearly said 
            if (url.equalsIgnoreCase("")){
                url = absolute;
            }
            return (toEncoded(url, request.getSessionInternal().getIdInternal()));
        } else {
            return (url);
        }

    
public java.lang.StringencodeUrl(java.lang.String url)
Encode the session identifier associated with this response into the specified URL, if necessary.

param
url URL to be encoded
deprecated
As of Version 2.1 of the Java Servlet API, use encodeURL() instead.

        return (encodeURL(url));
    
public voidfinishResponse()
Perform whatever actions are required to flush and close the output stream or writer, in a single operation.

exception
IOException if an input/output error occurs

        // Writing leftover bytes
        outputBuffer.close();
    
public voidflushBuffer()
Flush the buffer and commit this response.

exception
IOException if an input/output error occurs

        outputBuffer.flush();
    
public intgetBufferSize()
Return the actual buffer size used for this Response.

        return outputBuffer.getBufferSize();
    
public java.lang.StringgetCharacterEncoding()
Return the character encoding used for this Response.

        return (coyoteResponse.getCharacterEncoding());
    
public ConnectorgetConnector()
Return the Connector through which this Request was received.


                  
       
        return (this.connector);
    
public intgetContentCount()
Return the number of bytes actually written to the output stream.

        return outputBuffer.getContentWritten();
    
public intgetContentLength()
Return the content length that was set or calculated for this Response.

        return (coyoteResponse.getContentLength());
    
public java.lang.StringgetContentType()
Return the content type that was set or calculated for this response, or null if no content type was set.

        return (coyoteResponse.getContentType());
    
public org.apache.catalina.ContextgetContext()
Return the Context within which this Request is being processed.

        return (request.getContext());
    
public javax.servlet.http.Cookie[]getCookies()
Return an array of all cookies set for this response, or a zero-length array if no cookies have been set.

        return ((Cookie[]) cookies.toArray(new Cookie[cookies.size()]));
    
public org.apache.coyote.ResponsegetCoyoteResponse()
Get the Coyote response.

        return (coyoteResponse);
    
public java.lang.StringgetHeader(java.lang.String name)
Return the value for the specified header, or null if this header has not been set. If more than one value was added for this name, only the first is returned; use getHeaderValues() to retrieve all of them.

param
name Header name to look up

        return coyoteResponse.getMimeHeaders().getHeader(name);
    
public java.lang.String[]getHeaderNames()
Return an array of all the header names set for this response, or a zero-length array if no headers have been set.


        MimeHeaders headers = coyoteResponse.getMimeHeaders();
        int n = headers.size();
        String[] result = new String[n];
        for (int i = 0; i < n; i++) {
            result[i] = headers.getName(i).toString();
        }
        return result;

    
public java.lang.String[]getHeaderValues(java.lang.String name)
Return an array of all the header values associated with the specified header name, or an zero-length array if there are no such header values.

param
name Header name to look up


        Enumeration enumeration = coyoteResponse.getMimeHeaders().values(name);
        Vector result = new Vector();
        while (enumeration.hasMoreElements()) {
            result.addElement(enumeration.nextElement());
        }
        String[] resultArray = new String[result.size()];
        result.copyInto(resultArray);
        return resultArray;

    
public booleangetIncluded()
Return the "processing inside an include" flag.

        return included;
    
public java.lang.StringgetInfo()
Return descriptive information about this Response implementation and the corresponding version number, in the format <description>/<version>.

        return (info);
    
public java.util.LocalegetLocale()
Return the Locale assigned to this response.

        return (coyoteResponse.getLocale());
    
public java.lang.StringgetMessage()
Return the error message that was set with sendError() for this Response.

        return coyoteResponse.getMessage();
    
public javax.servlet.ServletOutputStreamgetOutputStream()
Return the servlet output stream associated with this Response.

exception
IllegalStateException if getWriter has already been called for this response
exception
IOException if an input/output error occurs


        if (usingWriter)
            throw new IllegalStateException
                (sm.getString("coyoteResponse.getOutputStream.ise"));

        usingOutputStream = true;
        if (outputStream == null) {
            outputStream = new CoyoteOutputStream(outputBuffer);
        }
        return outputStream;

    
public java.io.PrintWritergetReporter()
Return a PrintWriter that can be used to render error messages, regardless of whether a stream or writer has already been acquired.

return
Writer which can be used for error reports. If the response is not an error report returned using sendError or triggered by an unexpected exception thrown during the servlet processing (and only in that case), null will be returned if the response stream has already been used.
exception
IOException if an input/output error occurs

        if (outputBuffer.isNew()) {
            outputBuffer.checkConverter();
            if (writer == null) {
                writer = new CoyoteWriter(outputBuffer);
            }
            return writer;
        } else {
            return null;
        }
    
public org.apache.catalina.connector.RequestgetRequest()
Return the Request with which this Response is associated.


                  
       
        return (this.request);
    
public javax.servlet.http.HttpServletResponsegetResponse()
Return the ServletResponse for which this object is the facade.


                   
       
        if (facade == null) {
            facade = new ResponseFacade(this);
        }
        return (facade);
    
public intgetStatus()
Return the HTTP status code associated with this Response.

        return coyoteResponse.getStatus();
    
public java.io.OutputStreamgetStream()
Return the output stream associated with this Response.

        if (outputStream == null) {
            outputStream = new CoyoteOutputStream(outputBuffer);
        }
        return outputStream;
    
public java.io.PrintWritergetWriter()
Return the writer associated with this Response.

exception
IllegalStateException if getOutputStream has already been called for this response
exception
IOException if an input/output error occurs


        if (usingOutputStream)
            throw new IllegalStateException
                (sm.getString("coyoteResponse.getWriter.ise"));

        if (Globals.STRICT_SERVLET_COMPLIANCE) {
            /*
             * If the response's character encoding has not been specified as
             * described in <code>getCharacterEncoding</code> (i.e., the method
             * just returns the default value <code>ISO-8859-1</code>),
             * <code>getWriter</code> updates it to <code>ISO-8859-1</code>
             * (with the effect that a subsequent call to getContentType() will
             * include a charset=ISO-8859-1 component which will also be
             * reflected in the Content-Type response header, thereby satisfying
             * the Servlet spec requirement that containers must communicate the
             * character encoding used for the servlet response's writer to the
             * client).
             */
            setCharacterEncoding(getCharacterEncoding());
        }

        usingWriter = true;
        outputBuffer.checkConverter();
        if (writer == null) {
            writer = new CoyoteWriter(outputBuffer);
        }
        return writer;

    
private booleanhasScheme(java.lang.String uri)
Determine if a URI string has a scheme component.

        int len = uri.length();
        for(int i=0; i < len ; i++) {
            char c = uri.charAt(i);
            if(c == ':") {
                return i > 0;
            } else if(!URL.isSchemeChar(c)) {
                return false;
            }
        }
        return false;
    
public booleanisAppCommitted()
Application commit flag accessor.

        return (this.appCommitted || isCommitted() || isSuspended()
                || ((getContentLength() > 0) 
                    && (getContentCount() >= getContentLength())));
    
public booleanisClosed()
Closed flag accessor.

        return outputBuffer.isClosed();
    
public booleanisCommitted()
Has the output of this response already been committed?

        return (coyoteResponse.isCommitted());
    
protected booleanisEncodeable(java.lang.String location)
Return true if the specified URL should be encoded with a session identifier. This will be true if all of the following conditions are met:
  • The request we are responding to asked for a valid session
  • The requested session ID was not received via a cookie
  • The specified URL points back to somewhere within the web application that is responding to this request

param
location Absolute URL to be validated


        if (location == null)
            return (false);

        // Is this an intra-document reference?
        if (location.startsWith("#"))
            return (false);

        // Are we in a valid session that is not using cookies?
        final Request hreq = request;
        final Session session = hreq.getSessionInternal(false);
        if (session == null)
            return (false);
        if (hreq.isRequestedSessionIdFromCookie())
            return (false);
        
        if (SecurityUtil.isPackageProtectionEnabled()) {
            return ((Boolean)
                AccessController.doPrivileged(new PrivilegedAction() {

                public Object run(){
                    return new Boolean(doIsEncodeable(hreq, session, location));
                }
            })).booleanValue();
        } else {
            return doIsEncodeable(hreq, session, location);
        }
    
public booleanisError()
Error flag accessor.

        return error;
    
public booleanisSuspended()
Suspended flag accessor.

        return outputBuffer.isSuspended();
    
public voidrecycle()
Release all object references, and initialize instance variables, in preparation for reuse of this object.



    // --------------------------------------------------------- Public Methods


                        
       

        outputBuffer.recycle();
        usingOutputStream = false;
        usingWriter = false;
        appCommitted = false;
        included = false;
        error = false;
        isCharacterEncodingSet = false;
        
        cookies.clear();

        if (Globals.IS_SECURITY_ENABLED || Connector.RECYCLE_FACADES) {
            if (facade != null) {
                facade.clear();
                facade = null;
            }
            if (outputStream != null) {
                outputStream.clear();
                outputStream = null;
            }
            if (writer != null) {
                writer.clear();
                writer = null;
            }
        } else {
            writer.recycle();
        }

    
public voidreset()
Clear any content written to the buffer.

exception
IllegalStateException if this response has already been committed


        if (included)
            return;     // Ignore any call from an included servlet

        coyoteResponse.reset();
        outputBuffer.reset();
    
public voidreset(int status, java.lang.String message)
Reset this response, and specify the values for the HTTP status code and corresponding message.

exception
IllegalStateException if this response has already been committed

        reset();
        setStatus(status, message);
    
public voidresetBuffer()
Reset the data buffer but not any status or header information.

exception
IllegalStateException if the response has already been committed


        if (isCommitted())
            throw new IllegalStateException
                (sm.getString("coyoteResponse.resetBuffer.ise"));

        outputBuffer.reset();

    
public voidsendAcknowledgement()
Send an acknowledgment of a request.

exception
IOException if an input/output error occurs


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return; 

        coyoteResponse.acknowledge();

    
public voidsendError(int status)
Send an error response with the specified status and a default message.

param
status HTTP status code to send
exception
IllegalStateException if this response has already been committed
exception
IOException if an input/output error occurs

        sendError(status, null);
    
public voidsendError(int status, java.lang.String message)
Send an error response with the specified status and message.

param
status HTTP status code to send
param
message Corresponding message to send
exception
IllegalStateException if this response has already been committed
exception
IOException if an input/output error occurs


        if (isCommitted())
            throw new IllegalStateException
                (sm.getString("coyoteResponse.sendError.ise"));

        // Ignore any call from an included servlet
        if (included)
            return; 

        Wrapper wrapper = getRequest().getWrapper();
        if (wrapper != null) {
            wrapper.incrementErrorCount();
        } 

        setError();

        coyoteResponse.setStatus(status);
        coyoteResponse.setMessage(message);

        // Clear any data content that has been buffered
        resetBuffer();

        // Cause the response to be finished (from the application perspective)
        setSuspended(true);

    
public voidsendRedirect(java.lang.String location)
Send a temporary redirect to the specified redirect location URL.

param
location Location URL to redirect to
exception
IllegalStateException if this response has already been committed
exception
IOException if an input/output error occurs


        if (isCommitted())
            throw new IllegalStateException
                (sm.getString("coyoteResponse.sendRedirect.ise"));

        // Ignore any call from an included servlet
        if (included)
            return; 

        // Clear any data content that has been buffered
        resetBuffer();

        // Generate a temporary redirect to the specified location
        try {
            String absolute = toAbsolute(location);
            setStatus(SC_FOUND);
            setHeader("Location", absolute);
        } catch (IllegalArgumentException e) {
            setStatus(SC_NOT_FOUND);
        }

        // Cause the response to be finished (from the application perspective)
        setSuspended(true);

    
public voidsetAppCommitted(boolean appCommitted)
Set the application commit flag.

param
appCommitted The new application committed flag value

        this.appCommitted = appCommitted;
    
public voidsetBufferSize(int size)
Set the buffer size to be used for this Response.

param
size The new buffer size
exception
IllegalStateException if this method is called after output has been committed for this response


        if (isCommitted() || !outputBuffer.isNew())
            throw new IllegalStateException
                (sm.getString("coyoteResponse.setBufferSize.ise"));

        outputBuffer.setBufferSize(size);

    
public voidsetCharacterEncoding(java.lang.String charset)


        if (isCommitted())
            return;
        
        // Ignore any call from an included servlet
        if (included)
            return;     
        
        // Ignore any call made after the getWriter has been invoked
        // The default should be used
        if (usingWriter)
            return;

        coyoteResponse.setCharacterEncoding(charset);
        isCharacterEncodingSet = true;
    
public voidsetConnector(Connector connector)
Set the Connector through which this Request was received.

param
connector The new connector

        this.connector = connector;
        if("AJP/1.3".equals(connector.getProtocol())) {
            // default size to size of one ajp-packet
            outputBuffer = new OutputBuffer(8184);
        } else {
            outputBuffer = new OutputBuffer();
        }
        outputStream = new CoyoteOutputStream(outputBuffer);
        writer = new CoyoteWriter(outputBuffer);
    
public voidsetContentLength(int length)
Set the content length (in bytes) for this Response.

param
length The new content length


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return;
        
        if (usingWriter)
            return;
        
        coyoteResponse.setContentLength(length);

    
public voidsetContentType(java.lang.String type)
Set the content type for this Response.

param
type The new content type


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return;

        // Ignore charset if getWriter() has already been called
        if (usingWriter) {
            if (type != null) {
                int index = type.indexOf(";");
                if (index != -1) {
                    type = type.substring(0, index);
                }
            }
        }

        coyoteResponse.setContentType(type);

        // Check to see if content type contains charset
        if (type != null) {
            int index = type.indexOf(";");
            if (index != -1) {
                int len = type.length();
                index++;
                while (index < len && Character.isSpace(type.charAt(index))) {
                    index++;
                }
                if (index+7 < len
                        && type.charAt(index) == 'c"
                        && type.charAt(index+1) == 'h"
                        && type.charAt(index+2) == 'a"
                        && type.charAt(index+3) == 'r"
                        && type.charAt(index+4) == 's"
                        && type.charAt(index+5) == 'e"
                        && type.charAt(index+6) == 't"
                        && type.charAt(index+7) == '=") {
                    isCharacterEncodingSet = true;
                }
            }
        }
    
public voidsetContext(org.apache.catalina.Context context)
Set the Context within which this Request is being processed. This must be called as soon as the appropriate Context is identified, because it identifies the value to be returned by getContextPath(), and thus enables parsing of the request URI.

param
context The newly associated Context

        request.setContext(context);
    
public voidsetCoyoteResponse(org.apache.coyote.Response coyoteResponse)
Set the Coyote response.

param
coyoteResponse The Coyote response

        this.coyoteResponse = coyoteResponse;
        outputBuffer.setResponse(coyoteResponse);
    
public voidsetDateHeader(java.lang.String name, long value)
Set the specified date header to the specified value.

param
name Name of the header to set
param
value Date value to be set


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included) {
            return;
        }

        if (format == null) {
            format = new SimpleDateFormat(DateTool.HTTP_RESPONSE_DATE_HEADER,
                                          Locale.US);
            format.setTimeZone(TimeZone.getTimeZone("GMT"));
        }

        setHeader(name, FastHttpDateFormat.formatDate(value, format));

    
public voidsetError()
Set the error flag.

        error = true;
    
public voidsetHeader(java.lang.String name, java.lang.String value)
Set the specified header to the specified value.

param
name Name of the header to set
param
value Value to be set


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return;

        coyoteResponse.setHeader(name, value);

    
public voidsetIncluded(boolean included)
Set the "processing inside an include" flag.

param
included true if we are currently inside a RequestDispatcher.include(), else false

        this.included = included;
    
public voidsetIntHeader(java.lang.String name, int value)
Set the specified integer header to the specified value.

param
name Name of the header to set
param
value Integer value to be set


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return;

        setHeader(name, "" + value);

    
public voidsetLocale(java.util.Locale locale)
Set the Locale that is appropriate for this response, including setting the appropriate character encoding.

param
locale The new locale


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return;

        coyoteResponse.setLocale(locale);

        // Ignore any call made after the getWriter has been invoked.
        // The default should be used
        if (usingWriter)
            return;

        if (isCharacterEncodingSet) {
            return;
        }

        CharsetMapper cm = getContext().getCharsetMapper();
        String charset = cm.getCharset( locale );
        if ( charset != null ){
            coyoteResponse.setCharacterEncoding(charset);
        }

    
public voidsetRequest(org.apache.catalina.connector.Request request)
Set the Request with which this Response is associated.

param
request The new associated request

        this.request = (Request) request;
    
public voidsetStatus(int status)
Set the HTTP status to be returned with this response.

param
status The new HTTP status

        setStatus(status, null);
    
public voidsetStatus(int status, java.lang.String message)
Set the HTTP status and message to be returned with this response.

param
status The new HTTP status
param
message The associated text message
deprecated
As of Version 2.1 of the Java Servlet API, this method has been deprecated due to the ambiguous meaning of the message parameter.


        if (isCommitted())
            return;

        // Ignore any call from an included servlet
        if (included)
            return;

        coyoteResponse.setStatus(status);
        coyoteResponse.setMessage(message);

    
public voidsetStream(java.io.OutputStream stream)
Set the output stream associated with this Response.

param
stream The new output stream

        // This method is evil
    
public voidsetSuspended(boolean suspended)
Set the suspended flag.

param
suspended The new suspended flag value

        outputBuffer.setSuspended(suspended);
    
private java.lang.StringtoAbsolute(java.lang.String location)
Convert (if necessary) and return the absolute URL that represents the resource referenced by this possibly relative URL. If this URL is already absolute, return it unchanged.

param
location URL to be (possibly) converted and then returned
exception
IllegalArgumentException if a MalformedURLException is thrown when converting the relative URL to an absolute one


        if (location == null)
            return (location);

        boolean leadingSlash = location.startsWith("/");

        if (leadingSlash || !hasScheme(location)) {

            redirectURLCC.recycle();

            String scheme = request.getScheme();
            String name = request.getServerName();
            int port = request.getServerPort();

            try {
                redirectURLCC.append(scheme, 0, scheme.length());
                redirectURLCC.append("://", 0, 3);
                redirectURLCC.append(name, 0, name.length());
                if ((scheme.equals("http") && port != 80)
                    || (scheme.equals("https") && port != 443)) {
                    redirectURLCC.append(':");
                    String portS = port + "";
                    redirectURLCC.append(portS, 0, portS.length());
                }
                if (!leadingSlash) {
                    String relativePath = request.getDecodedRequestURI();
                    int pos = relativePath.lastIndexOf('/");
                    relativePath = relativePath.substring(0, pos);
                    
                    String encodedURI = null;
                    final String frelativePath = relativePath;
                    if (SecurityUtil.isPackageProtectionEnabled() ){
                        try{
                            encodedURI = (String)AccessController.doPrivileged( 
                                new PrivilegedExceptionAction(){                                
                                    public Object run() throws IOException{
                                        return urlEncoder.encodeURL(frelativePath);
                                    }
                           });   
                        } catch (PrivilegedActionException pae){
                            IllegalArgumentException iae =
                                new IllegalArgumentException(location);
                            iae.initCause(pae.getException());
                            throw iae;
                        }
                    } else {
                        encodedURI = urlEncoder.encodeURL(relativePath);
                    }
                    redirectURLCC.append(encodedURI, 0, encodedURI.length());
                    redirectURLCC.append('/");
                }
                redirectURLCC.append(location, 0, location.length());
            } catch (IOException e) {
                IllegalArgumentException iae =
                    new IllegalArgumentException(location);
                iae.initCause(e);
                throw iae;
            }

            return redirectURLCC.toString();

        } else {

            return (location);

        }

    
protected java.lang.StringtoEncoded(java.lang.String url, java.lang.String sessionId)
Return the specified URL with the specified session identifier suitably encoded.

param
url URL to be encoded with the session id
param
sessionId Session id to be included in the encoded URL


        if ((url == null) || (sessionId == null))
            return (url);

        String path = url;
        String query = "";
        String anchor = "";
        int question = url.indexOf('?");
        if (question >= 0) {
            path = url.substring(0, question);
            query = url.substring(question);
        }
        int pound = path.indexOf('#");
        if (pound >= 0) {
            anchor = path.substring(pound);
            path = path.substring(0, pound);
        }
        StringBuffer sb = new StringBuffer(path);
        if( sb.length() > 0 ) { // jsessionid can't be first.
            sb.append(";");
            sb.append(Globals.SESSION_PARAMETER_NAME);
            sb.append("=");
            sb.append(sessionId);
        }
        sb.append(anchor);
        sb.append(query);
        return (sb.toString());