| Method from org.apache.catalina.connector.Response Detail: |
public void addCookie(Cookie cookie) {
// Ignore any call from an included servlet
if (included)
return;
addCookieInternal(cookie);
}
Add the specified Cookie to those that will be included with
this Response. |
public void addCookieInternal(Cookie cookie) {
if (isCommitted())
return;
final StringBuffer sb = new StringBuffer();
//web application code can receive a IllegalArgumentException
//from the appendCookieValue invokation
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());
}
//if we reached here, no exception, cookie is valid
// 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());
cookies.add(cookie);
}
Add the specified Cookie to those that will be included with
this Response. |
public void addDateHeader(String name,
long 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));
}
Add the specified date header to the specified value. |
public void addHeader(String name,
String value) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.addHeader(name, value);
}
Add the specified header to the specified value. |
public void addIntHeader(String name,
int value) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
addHeader(name, "" + value);
}
Add the specified integer header to the specified value. |
public void clearEncoders() {
outputBuffer.clearEncoders();
}
Clear cached encoders (to save memory for Comet requests). |
public boolean containsHeader(String name) {
// 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);
}
Has the specified header been set already in this response? |
public ServletOutputStream createOutputStream() throws IOException {
// Probably useless
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
}
Create and return a ServletOutputStream to write the content
associated with this Response. |
public String encodeRedirectURL(String url) {
if (isEncodeable(toAbsolute(url))) {
return (toEncoded(url, request.getSessionInternal().getIdInternal()));
} else {
return (url);
}
}
Encode the session identifier associated with this response
into the specified redirect URL, if necessary. |
public String encodeRedirectUrl(String url) {
return (encodeRedirectURL(url));
} Deprecated! As - of Version 2.1 of the Java Servlet API, use
encodeRedirectURL() instead.
Encode the session identifier associated with this response
into the specified redirect URL, if necessary. |
public String encodeURL(String url) {
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);
}
}
Encode the session identifier associated with this response
into the specified URL, if necessary. |
public String encodeUrl(String url) {
return (encodeURL(url));
} Deprecated! As - of Version 2.1 of the Java Servlet API, use
encodeURL() instead.
Encode the session identifier associated with this response
into the specified URL, if necessary. |
public void finishResponse() throws IOException {
// Writing leftover bytes
outputBuffer.close();
}
Perform whatever actions are required to flush and close the output
stream or writer, in a single operation. |
public void flushBuffer() throws IOException {
outputBuffer.flush();
}
Flush the buffer and commit this response. |
public int getBufferSize() {
return outputBuffer.getBufferSize();
}
Return the actual buffer size used for this Response. |
public String getCharacterEncoding() {
return (coyoteResponse.getCharacterEncoding());
}
Return the character encoding used for this Response. |
public Connector getConnector() {
return (this.connector);
}
Return the Connector through which this Request was received. |
public int getContentCount() {
return outputBuffer.getContentWritten();
}
Return the number of bytes actually written to the output stream. |
public long getContentCountLong() {
return outputBuffer.getContentWrittenLong();
}
Return the number of bytes actually written to the output stream. |
public int getContentLength() {
return (coyoteResponse.getContentLength());
}
Return the content length that was set or calculated for this Response. |
public String getContentType() {
return (coyoteResponse.getContentType());
}
Return the content type that was set or calculated for this response,
or null if no content type was set. |
public Context getContext() {
return (request.getContext());
}
Return the Context within which this Request is being processed. |
public Cookie[] getCookies() {
return ((Cookie[]) cookies.toArray(new Cookie[cookies.size()]));
}
Return an array of all cookies set for this response, or
a zero-length array if no cookies have been set. |
public Response getCoyoteResponse() {
return (coyoteResponse);
}
|
public String getHeader(String name) {
return coyoteResponse.getMimeHeaders().getHeader(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. |
public String[] getHeaderNames() {
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;
}
Return an array of all the header names set for this response, or
a zero-length array if no headers have been set. |
public String[] getHeaderValues(String name) {
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;
}
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. |
public boolean getIncluded() {
return included;
}
Return the "processing inside an include" flag. |
public String getInfo() {
return (info);
}
Return descriptive information about this Response implementation and
the corresponding version number, in the format
<description>/<version>. |
public Locale getLocale() {
return (coyoteResponse.getLocale());
}
Return the Locale assigned to this response. |
public String getMessage() {
return coyoteResponse.getMessage();
}
Return the error message that was set with sendError()
for this Response. |
public ServletOutputStream getOutputStream() throws IOException {
if (usingWriter)
throw new IllegalStateException
(sm.getString("coyoteResponse.getOutputStream.ise"));
usingOutputStream = true;
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
}
Return the servlet output stream associated with this Response. |
public PrintWriter getReporter() throws IOException {
if (outputBuffer.isNew()) {
outputBuffer.checkConverter();
if (writer == null) {
writer = new CoyoteWriter(outputBuffer);
}
return writer;
} else {
return null;
}
}
Return a PrintWriter that can be used to render error messages,
regardless of whether a stream or writer has already been acquired. |
public Request getRequest() {
return (this.request);
}
Return the Request with which this Response is associated. |
public HttpServletResponse getResponse() {
if (facade == null) {
facade = new ResponseFacade(this);
}
return (facade);
}
Return the ServletResponse for which this object
is the facade. |
public int getStatus() {
return coyoteResponse.getStatus();
}
Return the HTTP status code associated with this Response. |
public OutputStream getStream() {
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
}
Return the output stream associated with this Response. |
public PrintWriter getWriter() throws IOException {
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;
}
Return the writer associated with this Response. |
public boolean isAppCommitted() {
return (this.appCommitted || isCommitted() || isSuspended()
|| ((getContentLength() > 0)
&& (getContentCount() >= getContentLength())));
}
Application commit flag accessor. |
public boolean isClosed() {
return outputBuffer.isClosed();
}
|
public boolean isCommitted() {
return (coyoteResponse.isCommitted());
}
Has the output of this response already been committed? |
protected boolean isEncodeable(String location) {
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);
}
}
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
|
public boolean isError() {
return error;
}
|
public boolean isSuspended() {
return outputBuffer.isSuspended();
}
|
public void recycle() {
// --------------------------------------------------------- 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();
}
}
Release all object references, and initialize instance variables, in
preparation for reuse of this object. |
public void reset() {
if (included)
return; // Ignore any call from an included servlet
coyoteResponse.reset();
outputBuffer.reset();
usingOutputStream = false;
usingWriter = false;
isCharacterEncodingSet = false;
}
Clear any content written to the buffer. |
public void reset(int status,
String message) {
reset();
setStatus(status, message);
}
Reset this response, and specify the values for the HTTP status code
and corresponding message. |
public void resetBuffer() {
if (isCommitted())
throw new IllegalStateException
(sm.getString("coyoteResponse.resetBuffer.ise"));
outputBuffer.reset();
}
Reset the data buffer but not any status or header information. |
public void sendAcknowledgement() throws IOException {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.acknowledge();
}
Send an acknowledgment of a request. |
public void sendError(int status) throws IOException {
sendError(status, null);
}
Send an error response with the specified status and a
default message. |
public void sendError(int status,
String message) throws IOException {
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);
}
Send an error response with the specified status and message. |
public void sendRedirect(String location) throws IOException {
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);
}
Send a temporary redirect to the specified redirect location URL. |
public void setAppCommitted(boolean appCommitted) {
this.appCommitted = appCommitted;
}
Set the application commit flag. |
public void setBufferSize(int size) {
if (isCommitted() || !outputBuffer.isNew())
throw new IllegalStateException
(sm.getString("coyoteResponse.setBufferSize.ise"));
outputBuffer.setBufferSize(size);
}
Set the buffer size to be used for this Response. |
public void setCharacterEncoding(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) {
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);
}
Set the Connector through which this Request was received. |
public void setContentLength(int length) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
if (usingWriter)
return;
coyoteResponse.setContentLength(length);
}
Set the content length (in bytes) for this Response. |
public void setContentType(String 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;
}
}
}
}
Set the content type for this Response. |
public void setContext(Context context) {
request.setContext(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. |
public void setCoyoteResponse(Response coyoteResponse) {
this.coyoteResponse = coyoteResponse;
outputBuffer.setResponse(coyoteResponse);
}
|
public void setDateHeader(String name,
long 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));
}
Set the specified date header to the specified value. |
public void setError() {
error = true;
}
|
public void setHeader(String name,
String value) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.setHeader(name, value);
}
Set the specified header to the specified value. |
public void setIncluded(boolean included) {
this.included = included;
}
Set the "processing inside an include" flag. |
public void setIntHeader(String name,
int value) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
setHeader(name, "" + value);
}
Set the specified integer header to the specified value. |
public void setLocale(Locale 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);
}
}
Set the Locale that is appropriate for this response, including
setting the appropriate character encoding. |
public void setRequest(Request request) {
this.request = (Request) request;
}
Set the Request with which this Response is associated. |
public void setStatus(int status) {
setStatus(status, null);
}
Set the HTTP status to be returned with this response. |
public void setStatus(int status,
String message) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.setStatus(status);
coyoteResponse.setMessage(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.
Set the HTTP status and message to be returned with this response. |
public void setStream(OutputStream stream) {
// This method is evil
}
Set the output stream associated with this Response. |
public void setSuspended(boolean suspended) {
outputBuffer.setSuspended(suspended);
}
|
protected String toEncoded(String url,
String sessionId) {
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());
}
Return the specified URL with the specified session identifier
suitably encoded. |