You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/08/10 23:29:51 UTC
cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector HttpRequestWrapper.java HttpResponseWrapper.java RequestWrapper.java ResponseWrapper.java
craigmcc 00/08/10 14:29:51
Added: proposals/catalina/src/share/org/apache/tomcat/connector
HttpRequestWrapper.java HttpResponseWrapper.java
RequestWrapper.java ResponseWrapper.java
Log:
Add abstract wrapper classes for each flavor of request and response.
By default, all methods are delegated to the request or response object
that is being wrapped. These wrappers provide a convenient base class
for use by Valves that wish to wrap a request or response, overriding
some functionality but delegating the rest of it.
Revision Changes Path
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestWrapper.java
Index: HttpRequestWrapper.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestWrapper.java,v 1.1 2000/08/10 21:29:50 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/08/10 21:29:50 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.connector;
import java.security.Principal;
import java.util.Locale;
import javax.servlet.http.Cookie;
import org.apache.tomcat.HttpRequest;
/**
* Abstract convenience class that wraps a Tomcat-internal <b>HttpRequest</b>
* object. By default, all methods are delegated to the wrapped request,
* but subclasses can override individual methods as required to provide the
* functionality that they require.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/08/10 21:29:50 $
*/
public abstract class HttpRequestWrapper
extends RequestWrapper
implements HttpRequest {
// ----------------------------------------------------------- Constructors
/**
* Construct a wrapper for the specified request.
*
* @param request The request to be wrapped
*/
public HttpRequestWrapper(HttpRequest request) {
super(request);
}
// --------------------------------------------------------- Public Methods
/**
* Add a Cookie to the set of Cookies associated with this Request.
*
* @param cookie The new cookie
*/
public void addCookie(Cookie cookie) {
((HttpRequest) request).addCookie(cookie);
}
/**
* Add a Header to the set of Headers associated with this Request.
*
* @param name The new header name
* @param value The new header value
*/
public void addHeader(String name, String value) {
((HttpRequest) request).addHeader(name, value);
}
/**
* Add a Locale to the set of preferred Locales for this Request. The
* first added Locale will be the first one returned by getLocales().
*
* @param locale The new preferred Locale
*/
public void addLocale(Locale locale) {
((HttpRequest) request).addLocale(locale);
}
/**
* Clear the collection of Cookies associated with this Request.
*/
public void clearCookies() {
((HttpRequest) request).clearCookies();
}
/**
* Clear the collection of Headers associated with this Request.
*/
public void clearHeaders() {
((HttpRequest) request).clearHeaders();
}
/**
* Clear the collection of Locales associated with this Request.
*/
public void clearLocales() {
((HttpRequest) request).clearLocales();
}
/**
* Set the authentication type used for this request, if any; otherwise
* set the type to <code>null</code>. Typical values are "BASIC",
* "DIGEST", or "SSL".
*
* @param type The authentication type used
*/
public void setAuthType(String type) {
((HttpRequest) request).setAuthType(type);
}
/**
* Set the context path for this Request. This will normally be called
* when the associated Context is mapping the Request to a particular
* Wrapper.
*
* @param path The context path
*/
public void setContextPath(String path) {
((HttpRequest) request).setContextPath(path);
}
/**
* Set the HTTP request method used for this Request.
*
* @param method The request method
*/
public void setMethod(String method) {
((HttpRequest) request).setMethod(method);
}
/**
* Set the query string for this Request. This will normally be called
* by the HTTP Connector, when it parses the request headers.
*
* @param query The query string
*/
public void setQueryString(String query) {
((HttpRequest) request).setQueryString(query);
}
/**
* Set the path information for this Request. This will normally be called
* when the associated Context is mapping the Request to a particular
* Wrapper.
*
* @param path The path information
*/
public void setPathInfo(String path) {
((HttpRequest) request).setPathInfo(path);
}
/**
* Set a flag indicating whether or not the requested session ID for this
* request came in through a cookie. This is normally called by the
* HTTP Connector, when it parses the request headers.
*
* @param flag The new flag
*/
public void setRequestedSessionCookie(boolean flag) {
((HttpRequest) request).setRequestedSessionCookie(flag);
}
/**
* Set the requested session ID for this request. This is normally called
* by the HTTP Connector, when it parses the request headers.
*
* @param id The new session id
*/
public void setRequestedSessionId(String id) {
((HttpRequest) request).setRequestedSessionId(id);
}
/**
* Set a flag indicating whether or not the requested session ID for this
* request came in through a URL. This is normally called by the
* HTTP Connector, when it parses the request headers.
*
* @param flag The new flag
*/
public void setRequestedSessionURL(boolean flag) {
((HttpRequest) request).setRequestedSessionURL(flag);
}
/**
* Set the unparsed request URI for this Request. This will normally be
* called by the HTTP Connector, when it parses the request headers.
*
* @param uri The request URI
*/
public void setRequestURI(String uri) {
((HttpRequest) request).setRequestURI(uri);
}
/**
* Set the servlet path for this Request. This will normally be called
* when the associated Context is mapping the Request to a particular
* Wrapper.
*
* @param path The servlet path
*/
public void setServletPath(String path) {
((HttpRequest) request).setServletPath(path);
}
/**
* Set the Principal who has been authenticated for this Request. This
* value is also used to calculate the value to be returned by the
* <code>getRemoteUser()</code> method.
*
* @param principal The user Principal
*/
public void setUserPrincipal(Principal principal) {
((HttpRequest) request).setUserPrincipal(principal);
}
}
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseWrapper.java
Index: HttpResponseWrapper.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseWrapper.java,v 1.1 2000/08/10 21:29:50 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/08/10 21:29:50 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.connector;
import org.apache.tomcat.HttpResponse;
/**
* Abstract convenience class that wraps a Tomcat-internal <b>HttpResponse</b>
* object. By default, all methods are delegated to the wrapped response,
* but subclasses can override individual methods as required to provide the
* functionality that they require.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/08/10 21:29:50 $
*/
public abstract class HttpResponseWrapper
extends ResponseWrapper
implements HttpResponse {
// ----------------------------------------------------------- Constructors
/**
* Construct a wrapper for the specified response.
*
* @param response The response to be wrapped
*/
public HttpResponseWrapper(HttpResponse response) {
super(response);
}
// --------------------------------------------------------- Public Methods
/**
* Return the value for the specified header, or <code>null</code> 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
*/
public String getHeader(String name) {
return (((HttpResponse) response).getHeader(name));
}
/**
* 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[] getHeaderNames() {
return (((HttpResponse) response).getHeaderNames());
}
/**
* 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
*/
public String[] getHeaderValues(String name) {
return (((HttpResponse) response).getHeaderValues(name));
}
/**
* Return the error message that was set with <code>sendError()</code>
* for this response.
*/
public String getMessage() {
return (((HttpResponse) response).getMessage());
}
/**
* Return the HTTP status code associated with this Response.
*/
public int getStatus() {
return (((HttpResponse) response).getStatus());
}
}
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestWrapper.java
Index: RequestWrapper.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestWrapper.java,v 1.1 2000/08/10 21:29:50 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/08/10 21:29:50 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.connector;
import java.io.InputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import org.apache.tomcat.Connector;
import org.apache.tomcat.Context;
import org.apache.tomcat.Request;
import org.apache.tomcat.Response;
import org.apache.tomcat.Wrapper;
/**
* Abstract convenience class that wraps a Tomcat-internal <b>Request</b>
* object. By default, all methods are delegated to the wrapped request,
* but subclasses can override individual methods as required to provide the
* functionality that they require.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/08/10 21:29:50 $
*/
public abstract class RequestWrapper implements Request {
// ----------------------------------------------------------- Constructors
/**
* Construct a wrapper for the specified request.
*
* @param request The request to be wrapped
*/
public RequestWrapper(Request request) {
super();
this.request = request;
}
// ----------------------------------------------------- Instance Variables
/**
* The wrapped request.
*/
protected Request request = null;
/**
* Return the wrapped request.
*/
public Request getWrappedRequest() {
return (this.request);
}
// ------------------------------------------------------------- Properties
/**
* Return the authorization credentials sent with this request.
*/
public String getAuthorization() {
return (request.getAuthorization());
}
/**
* Set the authorization credentials sent with this request.
*
* @param authorization The new authorization credentials
*/
public void setAuthorization(String authorization) {
request.setAuthorization(authorization);
}
/**
* Return the Connector through which this Request was received.
*/
public Connector getConnector() {
return (request.getConnector());
}
/**
* Set the Connector through which this Request was received.
*
* @param connector The new connector
*/
public void setConnector(Connector connector) {
request.setConnector(connector);
}
/**
* Return the Context within which this Request is being processed.
*/
public Context getContext() {
return (request.getContext());
}
/**
* 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 <code>getContextPath()</code>,
* and thus enables parsing of the request URI.
*
* @param context The newly associated Context
*/
public void setContext(Context context) {
request.setContext(context);
}
/**
* Return descriptive information about this Request implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
*/
public String getInfo() {
return (request.getInfo());
}
/**
* Return the <code>ServletRequest</code> for which this object
* is the facade.
*/
public ServletRequest getRequest() {
return (request.getRequest());
}
/**
* Return the Response with which this Request is associated.
*/
public Response getResponse() {
return (request.getResponse());
}
/**
* Set the Response with which this Request is associated.
*
* @param response The new associated response
*/
public void setResponse(Response response) {
request.setResponse(response);
}
/**
* Return the input stream associated with this Request.
*/
public InputStream getStream() {
return (request.getStream());
}
/**
* Set the input stream associated with this Request.
*
* @param stream The new input stream
*/
public void setStream(InputStream stream) {
request.setStream(stream);
}
/**
* Return the Wrapper within which this Request is being processed.
*/
public Wrapper getWrapper() {
return (request.getWrapper());
}
/**
* Set the Wrapper within which this Request is being processed. This
* must be called as soon as the appropriate Wrapper is identified, and
* before the Request is ultimately passed to an application servlet.
*
* @param wrapper The newly associated Wrapper
*/
public void setWrapper(Wrapper wrapper) {
request.setWrapper(wrapper);
}
// --------------------------------------------------------- Public Methods
/**
* Create and return a ServletInputStream to read the content
* associated with this Request.
*
* @exception IOException if an input/output error occurs
*/
public ServletInputStream createInputStream() throws IOException {
return (request.createInputStream());
}
/**
* Perform whatever actions are required to flush and close the input
* stream or reader, in a single operation.
*
* @exception IOException if an input/output error occurs
*/
public void finishRequest() throws IOException {
request.finishRequest();
}
/**
* Release all object references, and initialize instance variables, in
* preparation for reuse of this object.
*/
public void recycle() {
request.recycle();
}
/**
* Set the content length associated with this Request.
*
* @param length The new content length
*/
public void setContentLength(int length) {
request.setContentLength(length);
}
/**
* Set the content type (and optionally the character encoding)
* associated with this Request. For example,
* <code>text/html; charset=ISO-8859-4</code>.
*
* @param type The new content type
*/
public void setContentType(String type) {
request.setContentType(type);
}
/**
* Set the protocol name and version associated with this Request.
*
* @param protocol Protocol name and version
*/
public void setProtocol(String protocol) {
request.setProtocol(protocol);
}
/**
* Set the remote IP address associated with this Request. NOTE: This
* value will be used to resolve the value for <code>getRemoteHost()</code>
* if that method is called.
*
* @param remote The remote IP address
*/
public void setRemoteAddr(String remote) {
request.setRemoteAddr(remote);
}
/**
* Set the name of the scheme associated with this request. Typical values
* are <code>http</code>, <code>https</code>, and <code>ftp</code>.
*
* @param scheme The scheme
*/
public void setScheme(String scheme) {
request.setScheme(scheme);
}
/**
* Set the value to be returned by <code>isSecure()</code>
* for this Request.
*
* @param secure The new isSecure value
*/
public void setSecure(boolean secure) {
request.setSecure(secure);
}
/**
* Set the name of the server (virtual host) to process this request.
*
* @param name The server name
*/
public void setServerName(String name) {
request.setServerName(name);
}
/**
* Set the port number of the server to process this request.
*
* @param port The server port
*/
public void setServerPort(int port) {
request.setServerPort(port);
}
}
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseWrapper.java
Index: ResponseWrapper.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseWrapper.java,v 1.1 2000/08/10 21:29:50 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/08/10 21:29:50 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.connector;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletResponse;
import org.apache.tomcat.Connector;
import org.apache.tomcat.Context;
import org.apache.tomcat.Request;
import org.apache.tomcat.Response;
import org.apache.tomcat.Wrapper;
/**
* Abstract convenience class that wraps a Tomcat-internal <b>Response</b>
* object. By default, all methods are delegated to the wrapped response,
* but subclasses can override individual methods as required to provide the
* functionality that they require.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/08/10 21:29:50 $
*/
public abstract class ResponseWrapper implements Response {
// ----------------------------------------------------------- Constructors
/**
* Construct a wrapper for the specified response.
*
* @param response The response to be wrapped
*/
public ResponseWrapper(Response response) {
super();
this.response = response;
}
// ----------------------------------------------------- Instance Variables
/**
* The wrapped response.
*/
protected Response response = null;
/**
* Return the wrapped response.
*/
public Response getWrappedResponse() {
return (this.response);
}
// ------------------------------------------------------------- Properties
/**
* Return the Connector through which this Response is returned.
*/
public Connector getConnector() {
return (response.getConnector());
}
/**
* Set the Connector through which this Response is returned.
*
* @param connector The new connector
*/
public void setConnector(Connector connector) {
response.setConnector(connector);
}
/**
* Return the number of bytes actually written to the output stream.
*/
public int getContentCount() {
return (response.getContentCount());
}
/**
* Return the Context with which this Response is associated.
*/
public Context getContext() {
return (response.getContext());
}
/**
* Set the Context with which this Response is associated. This should
* be called as soon as the appropriate Context is identified.
*
* @param context The associated Context
*/
public void setContext(Context context) {
response.setContext(context);
}
/**
* Return the "processing inside an include" flag.
*/
public boolean getIncluded() {
return (response.getIncluded());
}
/**
* Set the "processing inside an include" flag.
*
* @param included <code>true</code> if we are currently inside a
* RequestDispatcher.include(), else <code>false</code>
*/
public void setIncluded(boolean included) {
response.setIncluded(included);
}
/**
* Return descriptive information about this Response implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
*/
public String getInfo() {
return (response.getInfo());
}
/**
* Return the Request with which this Response is associated.
*/
public Request getRequest() {
return (response.getRequest());
}
/**
* Set the Request with which this Response is associated.
*
* @param request The new associated request
*/
public void setRequest(Request request) {
response.setRequest(request);
}
/**
* Return the <code>ServletResponse</code> for which this object
* is the facade.
*/
public ServletResponse getResponse() {
return (response.getResponse());
}
/**
* Return the output stream associated with this Response.
*/
public OutputStream getStream() {
return (response.getStream());
}
/**
* Set the output stream associated with this Response.
*
* @param stream The new output stream
*/
public void setStream(OutputStream stream) {
response.setStream(stream);
}
// --------------------------------------------------------- Public Methods
/**
* Create and return a ServletOutputStream to write the content
* associated with this Response.
*
* @exception IOException if an input/output error occurs
*/
public ServletOutputStream createOutputStream() throws IOException {
return (response.createOutputStream());
}
/**
* 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
*/
public void finishResponse() throws IOException {
response.finishResponse();
}
/**
* Return the content length that was set or calculated for this Response.
*/
public int getContentLength() {
return (response.getContentLength());
}
/**
* Return the content type that was set or calculated for this response,
* or <code>null</code> if no content type was set.
*/
public String getContentType() {
return (response.getContentType());
}
/**
* Return a PrintWriter that can be used to render error messages,
* regardless of whether a stream or writer has already been acquired.
*/
public PrintWriter getReporter() {
return (response.getReporter());
}
/**
* Release all object references, and initialize instance variables, in
* preparation for reuse of this object.
*/
public void recycle() {
response.recycle();
}
/**
* Reset the data buffer but not any status or header information.
*/
public void resetBuffer() {
response.resetBuffer();
}
}