FileDocCategorySizeDatePackage
CoyoteResponse.javaAPI DocGlassfish v2 API50083Fri May 04 22:32:44 BST 2007org.apache.coyote.tomcat5

CoyoteResponse

public class CoyoteResponse extends Object implements org.apache.catalina.HttpResponse, HttpServletResponse
Wrapper object for the Coyote response.
author
Remy Maucherat
author
Craig R. McClanahan
version
$Revision: 1.22 $ $Date: 2007/05/05 05:32:43 $

Fields Summary
private static boolean
enforceScope
Whether or not to enforce scope checking of this object.
private String
detailErrorMsg
protected SimpleDateFormat
format
The date format we will use for creating date headers.
protected static final String
info
Descriptive information about this Response implementation.
protected static final org.apache.catalina.util.StringManager
sm
The string manager for this package.
protected org.apache.catalina.Context
context
Associated context.
protected org.apache.catalina.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
private boolean
isContentTypeSet
The contextType 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 CoyoteRequest
request
The request with which this response is associated.
protected CoyoteResponseFacade
facade
The facade associated with this response.
Constructors Summary
public CoyoteResponse()



    // ----------------------------------------------------------- Constructors

      
        // START OF SJSAS 6231069
        outputBuffer = new OutputBuffer();
        outputStream = new CoyoteOutputStream(outputBuffer);
        writer = new CoyoteWriter(outputBuffer);
        // END OF SJSAS 6231069
        urlEncoder.addSafeCharacter('/");
    
public CoyoteResponse(boolean chunkingDisabled)

        outputBuffer = new OutputBuffer(chunkingDisabled);
        outputStream = new CoyoteOutputStream(outputBuffer);
        writer = new CoyoteWriter(outputBuffer);
        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


        if (isCommitted())
            return;

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

        cookies.add(cookie);

        /* GlassFish 898
        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());
        }
        */
        // START GlassFish 898
        String cookieValue = getCookieString(cookie);
        // END GlassFish 898

        // 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.
        /* GlassFish 898
        addHeader("Set-Cookie", sb.toString());
        */
        // START GlassFish 898
        addHeader("Set-Cookie", cookieValue);
        // END GlassFish 898
    
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 booleancontainsHeader(java.lang.String name)
Has the specified header been set already in this response?

param
name Name of the header to check

        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(CoyoteRequest 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);
            if( file.indexOf(";jsessionid=" + session.getIdInternal()) >= 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))) {
            String sessionVersion = null;
            HashMap<String, String> sessionVersions = (HashMap<String, String>)
                request.getAttribute(Globals.SESSION_VERSIONS_REQUEST_ATTRIBUTE);
            if (sessionVersions != null) {
                sessionVersion = RequestUtil.makeSessionVersionString(sessionVersions);
            }
            return (toEncoded(url,
                              request.getSessionInternal().getIdInternal(),
                              sessionVersion));
        } 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;
            }
            String sessionVersion = null;
            HashMap<String, String> sessionVersions = (HashMap<String, String>)
                request.getAttribute(Globals.SESSION_VERSIONS_REQUEST_ATTRIBUTE);
            if (sessionVersions != null) {
                sessionVersion = RequestUtil.makeSessionVersionString(sessionVersions);
            }
            return (toEncoded(url,
                              request.getSessionInternal().getIdInternal(),
                              sessionVersion));
        } 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
        try {
            outputBuffer.close();
        } catch(IOException e) {
	    ;
        } catch(Throwable t) {
	    t.printStackTrace();
        }
    
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 org.apache.catalina.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.

        /*
         * Ideally, we would call CoyoteResponse.setContext() from
         * CoyoteAdapter (the same way we call it for CoyoteRequest), and
         * have getContext() return this context. However, for backwards
         * compatibility with WS 7.0's NSAPIProcessor, which does not call
         * CoyoteResponse.setContext(), we must delegate to the getContext()
         * method of the linked request object.
         */
        return request.getContext();
    
protected java.lang.StringgetCookieString(javax.servlet.http.Cookie cookie)
Gets the string representation of the given cookie.

param
cookie The cookie whose string representation to get
return
The cookie's string representation

        return getCookieString(cookie, false);
    
protected java.lang.StringgetCookieString(javax.servlet.http.Cookie cookie, boolean encode)
Gets the string representation of the given cookie.

param
cookie The cookie whose string representation to get
param
encode true for URL encoding to take place, false otherwise
return
The cookie's string representation


        String cookieValue = null;
        final StringBuffer sb = new StringBuffer();

        if (SecurityUtil.isPackageProtectionEnabled()) {
            cookieValue = (String) 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(),
                             encode);
                        return sb.toString();
                    }
                });
        } else {
            ServerCookie.appendCookieValue
                (sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
                 cookie.getPath(), cookie.getDomain(), cookie.getComment(), 
                 cookie.getMaxAge(), cookie.getSecure(), encode);
            cookieValue = sb.toString();
        }

        return cookieValue;
    
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.StringgetDetailMessage()
Gets detail error message.

return
the detail error message

        return this.detailErrorMsg;
    
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 e = coyoteResponse.getMimeHeaders().values(name);
        Vector result = new Vector();
        while (e.hasMoreElements()) {
            result.addElement(e.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.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 CoyoteResponseFacade(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 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;

    
public booleanisAppCommitted()
Application commit flag accessor.

        return (this.appCommitted || isCommitted() || isSuspended()
                || ((getContentLength() > 0) 
                    && (getContentCount() >= getContentLength())));
    
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 CoyoteRequest 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 Boolean.valueOf(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


                        
       

        context = null;
        outputBuffer.recycle();
        usingOutputStream = false;
        usingWriter = false;
        appCommitted = false;
        included = false;
        error = false;
        isContentTypeSet = false;
        isCharacterEncodingSet = false;
        detailErrorMsg = null;

        cookies.clear();

        if (enforceScope) {
            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 voidremoveSessionCookies()
Removes any Set-Cookie response headers whose value contains the string JSESSIONID

        coyoteResponse.removeSessionCookies();        
    
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 {
            /* RIMOD 4642650
            String absolute = toAbsolute(location);
            */
            // START RIMOD 4642650
            String absolute;
            if (getContext().getAllowRelativeRedirect())
                absolute = location;
            else
                absolute = toAbsolute(location);
            // END RIMOD 4642650   
            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(org.apache.catalina.Connector connector)
Set the Connector through which this Request was received.

param
connector The new connector

        this.connector = connector;
    
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;
                }
            }
        }

        isContentTypeSet = 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

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

param
response The Coyote response

        this.coyoteResponse = coyoteResponse;
        outputBuffer.setCoyoteResponse(this);
    
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 voidsetDetailMessage(java.lang.String message)
Sets detail error message.

param
message detail error message

        this.detailErrorMsg = message;
    
public static voidsetEnforceScope(boolean enforce)
Set whether or not to enforce scope checking of this object.



    // ------------------------------------------------------------- Properties


                    
         

        enforceScope = enforce;

    
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.Request request)
Set the Request with which this Response is associated.

param
request The new associated request

        this.request = (CoyoteRequest) 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);
    
protected 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 
            || (!leadingSlash && (location.indexOf("://") == -1))) {

            redirectURLCC.recycle();

            String scheme = request.getScheme();

            // START S1AS 6170450
            if (getConnector() != null
                    && getConnector().getAuthPassthroughEnabled()) {
                ProxyHandler proxyHandler = getConnector().getProxyHandler();
                if (proxyHandler != null
                        && proxyHandler.getSSLKeysize(request) > 0) {
                    scheme = "https";
                }
            }
            // END S1AS 6170450

            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.getCause());
                            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

        return toEncoded(url, sessionId, null);
    
private java.lang.StringtoEncoded(java.lang.String url, java.lang.String sessionId, java.lang.String sessionVersion)
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
param
sessionVersion Session version 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(";jsessionid=");
            sb.append(sessionId);

            // START SJSAS 6337561
            String jrouteId = request.getHeader(Constants.PROXY_JROUTE);
            if (jrouteId != null) {
                sb.append(":");
                sb.append(jrouteId);
            }
            // END SJSAS 6337561

            if (sessionVersion != null) {
                sb.append(Globals.SESSION_VERSION_PARAMETER);
                sb.append(sessionVersion);
            }
        }

        sb.append(anchor);
        sb.append(query);
        return (sb.toString());