Methods Summary |
---|
public void | addCookie(javax.servlet.http.Cookie cookie)Add the specified Cookie to those that will be included with
this Response.
// Ignore any call from an included servlet
if (included)
return;
addCookieInternal(cookie);
|
public void | addCookieInternal(javax.servlet.http.Cookie cookie)Add the specified Cookie to those that will be included with
this Response.
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 void | addDateHeader(java.lang.String name, long value)Add the specified date header to the specified value.
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 void | addHeader(java.lang.String name, java.lang.String value)Add the specified header to the specified value.
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.addHeader(name, value);
|
public void | addIntHeader(java.lang.String name, int value)Add the specified integer header to the specified value.
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
addHeader(name, "" + value);
|
public void | clearEncoders()Clear cached encoders (to save memory for Comet requests).
outputBuffer.clearEncoders();
|
public boolean | containsHeader(java.lang.String name)Has the specified header been set already in this response?
// 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.ServletOutputStream | createOutputStream()Create and return a ServletOutputStream to write the content
associated with this Response.
// Probably useless
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
|
private boolean | doIsEncodeable(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.String | encodeRedirectURL(java.lang.String url)Encode the session identifier associated with this response
into the specified redirect URL, if necessary.
if (isEncodeable(toAbsolute(url))) {
return (toEncoded(url, request.getSessionInternal().getIdInternal()));
} else {
return (url);
}
|
public java.lang.String | encodeRedirectUrl(java.lang.String url)Encode the session identifier associated with this response
into the specified redirect URL, if necessary.
return (encodeRedirectURL(url));
|
public java.lang.String | encodeURL(java.lang.String url)Encode the session identifier associated with this response
into the specified URL, if necessary.
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.String | encodeUrl(java.lang.String url)Encode the session identifier associated with this response
into the specified URL, if necessary.
return (encodeURL(url));
|
public void | finishResponse()Perform whatever actions are required to flush and close the output
stream or writer, in a single operation.
// Writing leftover bytes
outputBuffer.close();
|
public void | flushBuffer()Flush the buffer and commit this response.
outputBuffer.flush();
|
public int | getBufferSize()Return the actual buffer size used for this Response.
return outputBuffer.getBufferSize();
|
public java.lang.String | getCharacterEncoding()Return the character encoding used for this Response.
return (coyoteResponse.getCharacterEncoding());
|
public Connector | getConnector()Return the Connector through which this Request was received.
return (this.connector);
|
public int | getContentCount()Return the number of bytes actually written to the output stream.
return outputBuffer.getContentWritten();
|
public int | getContentLength()Return the content length that was set or calculated for this Response.
return (coyoteResponse.getContentLength());
|
public java.lang.String | getContentType()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.Context | getContext()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.Response | getCoyoteResponse()Get the Coyote response.
return (coyoteResponse);
|
public java.lang.String | getHeader(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.
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.
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 boolean | getIncluded()Return the "processing inside an include" flag.
return included;
|
public java.lang.String | getInfo()Return descriptive information about this Response implementation and
the corresponding version number, in the format
<description>/<version> .
return (info);
|
public java.util.Locale | getLocale()Return the Locale assigned to this response.
return (coyoteResponse.getLocale());
|
public java.lang.String | getMessage()Return the error message that was set with sendError()
for this Response.
return coyoteResponse.getMessage();
|
public javax.servlet.ServletOutputStream | getOutputStream()Return the servlet output stream associated with this Response.
if (usingWriter)
throw new IllegalStateException
(sm.getString("coyoteResponse.getOutputStream.ise"));
usingOutputStream = true;
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
|
public java.io.PrintWriter | getReporter()Return a PrintWriter that can be used to render error messages,
regardless of whether a stream or writer has already been acquired.
if (outputBuffer.isNew()) {
outputBuffer.checkConverter();
if (writer == null) {
writer = new CoyoteWriter(outputBuffer);
}
return writer;
} else {
return null;
}
|
public org.apache.catalina.connector.Request | getRequest()Return the Request with which this Response is associated.
return (this.request);
|
public javax.servlet.http.HttpServletResponse | getResponse()Return the ServletResponse for which this object
is the facade.
if (facade == null) {
facade = new ResponseFacade(this);
}
return (facade);
|
public int | getStatus()Return the HTTP status code associated with this Response.
return coyoteResponse.getStatus();
|
public java.io.OutputStream | getStream()Return the output stream associated with this Response.
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
|
public java.io.PrintWriter | getWriter()Return the writer associated with this Response.
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 boolean | hasScheme(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 boolean | isAppCommitted()Application commit flag accessor.
return (this.appCommitted || isCommitted() || isSuspended()
|| ((getContentLength() > 0)
&& (getContentCount() >= getContentLength())));
|
public boolean | isClosed()Closed flag accessor.
return outputBuffer.isClosed();
|
public boolean | isCommitted()Has the output of this response already been committed?
return (coyoteResponse.isCommitted());
|
protected boolean | isEncodeable(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
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 boolean | isError()Error flag accessor.
return error;
|
public boolean | isSuspended()Suspended flag accessor.
return outputBuffer.isSuspended();
|
public void | recycle()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 void | reset()Clear any content written to the buffer.
if (included)
return; // Ignore any call from an included servlet
coyoteResponse.reset();
outputBuffer.reset();
|
public void | reset(int status, java.lang.String message)Reset this response, and specify the values for the HTTP status code
and corresponding message.
reset();
setStatus(status, message);
|
public void | resetBuffer()Reset the data buffer but not any status or header information.
if (isCommitted())
throw new IllegalStateException
(sm.getString("coyoteResponse.resetBuffer.ise"));
outputBuffer.reset();
|
public void | sendAcknowledgement()Send an acknowledgment of a request.
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.acknowledge();
|
public void | sendError(int status)Send an error response with the specified status and a
default message.
sendError(status, null);
|
public void | sendError(int status, java.lang.String message)Send an error response with the specified status and message.
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 void | sendRedirect(java.lang.String location)Send a temporary redirect to the specified redirect location URL.
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 void | setAppCommitted(boolean appCommitted)Set the application commit flag.
this.appCommitted = appCommitted;
|
public void | setBufferSize(int size)Set the buffer size to be used for this Response.
if (isCommitted() || !outputBuffer.isNew())
throw new IllegalStateException
(sm.getString("coyoteResponse.setBufferSize.ise"));
outputBuffer.setBufferSize(size);
|
public void | setCharacterEncoding(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 void | setConnector(Connector connector)Set the Connector through which this Request was received.
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 void | setContentLength(int length)Set the content length (in bytes) for this Response.
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
if (usingWriter)
return;
coyoteResponse.setContentLength(length);
|
public void | setContentType(java.lang.String type)Set the content type for this Response.
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 void | setContext(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.
request.setContext(context);
|
public void | setCoyoteResponse(org.apache.coyote.Response coyoteResponse)Set the Coyote response.
this.coyoteResponse = coyoteResponse;
outputBuffer.setResponse(coyoteResponse);
|
public void | setDateHeader(java.lang.String name, long value)Set the specified date header to the specified value.
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 void | setError()Set the error flag.
error = true;
|
public void | setHeader(java.lang.String name, java.lang.String value)Set the specified header to the specified value.
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.setHeader(name, value);
|
public void | setIncluded(boolean included)Set the "processing inside an include" flag.
this.included = included;
|
public void | setIntHeader(java.lang.String name, int value)Set the specified integer header to the specified value.
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
setHeader(name, "" + value);
|
public void | setLocale(java.util.Locale locale)Set the Locale that is appropriate for this response, including
setting the appropriate character encoding.
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 void | setRequest(org.apache.catalina.connector.Request request)Set the Request with which this Response is associated.
this.request = (Request) request;
|
public void | setStatus(int status)Set the HTTP status to be returned with this response.
setStatus(status, null);
|
public void | setStatus(int status, java.lang.String message)Set the HTTP status and message to be returned with this response.
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.setStatus(status);
coyoteResponse.setMessage(message);
|
public void | setStream(java.io.OutputStream stream)Set the output stream associated with this Response.
// This method is evil
|
public void | setSuspended(boolean suspended)Set the suspended flag.
outputBuffer.setSuspended(suspended);
|
private java.lang.String | toAbsolute(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.
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.String | toEncoded(java.lang.String url, java.lang.String sessionId)Return the specified URL with the specified session identifier
suitably encoded.
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());
|