You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by cm...@apache.org on 2001/08/01 16:33:05 UTC
cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger XHttpServletRequestFacade22.java XHttpServletRequestFacade23.java XHttpServletResponseFacade22.java XHttpServletResponseFacade23.java XHttpServletRequestFacade.java XHttpServletResponseFacade.java
cmlenz 01/08/01 07:33:05
Modified: . build.xml
Added: src/webdav/server/org/apache/slide/webdav/logger
XHttpServletRequestFacade22.java
XHttpServletRequestFacade23.java
XHttpServletResponseFacade22.java
XHttpServletResponseFacade23.java
Removed: src/webdav/server/org/apache/slide/webdav/logger
XHttpServletRequestFacade.java
XHttpServletResponseFacade.java
Log:
Make the WebdavServlet Servlet 2.3 compatible:
- Add new versions of XHttpServletRequestFacade and
XHttpServletResponseFacade that use the Servlet API 2.3
- Add Servlet API version as suffix to the corresponding
source files
- Change the build file so that the correct version of the
files is used during compilation
Revision Changes Path
1.101 +36 -5 jakarta-slide/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-slide/build.xml,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -r1.100 -r1.101
--- build.xml 2001/07/31 05:45:47 1.100
+++ build.xml 2001/08/01 14:33:05 1.101
@@ -304,7 +304,6 @@
<echo message="--- Required Libraries ---" />
<echo message="servlet.present (must be present) = ${servlet.present}" />
- <echo message="servlet23.present (must NOT be present) = ${servlet23.present}" />
<echo message="jaxp10.present (must be present) = ${jaxp10.present}" />
<echo message="jdom.present (must be present) = ${jdom.present}" />
<echo message="dom.present (must be present) = ${dom.present}" />
@@ -314,6 +313,7 @@
<echo message="--- Optional Libraries ---" />
+ <echo message="servlet23.present (optional) = ${servlet23.present}" />
<echo message="jaxp11.present (optional) = ${jaxp11.present}" />
<echo message="jmx.present (optional) = ${jmx.present}" />
<echo message="ant.present (optional) = ${ant.present}" />
@@ -358,9 +358,34 @@
<!-- =================================================================== -->
+ <!-- Prepare WebdavServlet for build against Servlet 2.2 API -->
+ <!-- =================================================================== -->
+ <target name="prepare-servlet22" depends="setenv"
+ unless="servlet23.present">
+ <copy overwrite="true" preservelastmodified="true"
+ todir="src/webdav/server/org/apache/slide/webdav/logger">
+ <fileset dir="src/webdav/server/org/apache/slide/webdav/logger" />
+ <mapper type="glob" from="*22.java" to="*.java" />
+ </copy>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Prepare WebdavServlet for build against Servlet 2.3 API -->
+ <!-- =================================================================== -->
+ <target name="prepare-servlet23" depends="setenv"
+ if="servlet23.present">
+ <copy overwrite="true" preservelastmodified="true"
+ todir="src/webdav/server/org/apache/slide/webdav/logger">
+ <fileset dir="src/webdav/server/org/apache/slide/webdav/logger" />
+ <mapper type="glob" from="*23.java" to="*.java" />
+ </copy>
+ </target>
+
+ <!-- =================================================================== -->
<!-- Prepare -->
<!-- =================================================================== -->
- <target name="prepare" depends="setenv">
+ <target name="prepare" depends="setenv,prepare-servlet22,
+ prepare-servlet23">
<mkdir dir="${slide.build}"/>
<mkdir dir="${slide.build}/classes"/>
@@ -452,7 +477,7 @@
deprecation="${compile.deprecation}"
optimize="${compile.optimize}"
includes="**/webdav/**"
- excludes="**/CVS/**,**/package.html">
+ excludes="**/CVS/**,**/package.html,**/XHttpServlet*Facade2*.java">
<classpath refid="webdavservlet.classpath"/>
</javac>
@@ -668,6 +693,11 @@
<target name="clean">
<delete dir="${slide.build}"/>
<delete dir="${slide.dist}"/>
+ <delete>
+ <fileset dir="src/webdav/server/org/apache/slide/webdav/logger"
+ includes="XHttpServletRequestFacade.java,
+ XHttpServletResponseFacade.java" />
+ </delete>
</target>
@@ -677,8 +707,9 @@
<target name="javadoc" depends="prepare" unless="skip.javadoc">
<property name="copyright" value="" />
<javadoc sourcepath="src/share" destdir="${slide.build}/doc/javadoc"
- doctitle="Slide JavaDoc" package="true" noindex="true"
- author="true" packagenames="org.*">
+ doctitle="Slide ${version} API Documentation"
+ windowtitle="Slide API Documentation"
+ package="true" noindex="true" author="true" packagenames="org.*">
<classpath refid="main.classpath"/>
</javadoc>
</target>
1.1 jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XHttpServletRequestFacade22.java
Index: XHttpServletRequestFacade22.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XHttpServletRequestFacade22.java,v 1.1 2001/08/01 14:33:05 cmlenz Exp $
* $Revision: 1.1 $
* $Date: 2001/08/01 14:33:05 $
*
* ====================================================================
*
* 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.slide.webdav.logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletInputStream;
import javax.servlet.RequestDispatcher;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Locale;
import java.security.Principal;
import org.apache.slide.common.Domain;
/**
* This class supports additional set-methods and a re-readable
* inputstream to the interface javax.servlet.http.HttpServletRequest.
*
* @author Hardy.Kiefer@softwareag.com
*
* @version 0.1
*
* @invariant (inputStream != null)
*
* @see javax.servlet.http.HttpServletRequest
*
*/
public class XHttpServletRequestFacade implements HttpServletRequest {
public static final String DEFAULT_CHAR_ENCODING = "8859_1";
/**
* the HttpServletRequest to re-read.
*
* @invariant (req != null)
*
* @see javax.servlet.http.HttpServletRequest
*/
private HttpServletRequest request;
/**
* the inputstream to re-read.
*
* @see java.io.BufferedInputStream
*/
private XServletInputStreamFacade inStreamFacade = null;
/**
* buffered reader which uses the input stream
*
* @see java.io.BufferedReader
*/
private BufferedReader reader = null;
/**
* true - if inputstream can read using a reader; false otherwise.
*/
private boolean usingReader = false;
/**
* true - if inputstream can read using a stream; false otherwise.
*/
private boolean usingStream = false;
/**
* This constructor creates an re-readable HttpServletRequest.
*
* @pre (req != null)
* @post
*
* @param req HttpServletRequest
*
* @exception
*
* @time
* @space
*
* @see
*/
public XHttpServletRequestFacade (HttpServletRequest request) {
Domain.debug("Create XHttpServletRequestFacade");
this.request = request;
}
/**
* Returns the value of the named attribute as an Object,
* or null if no attribute of the given name exists.
*
* @param name the named attribute
*
* @return Returns the value of the named attribute as an Object
*/
public Object getAttribute(String name) {
return request.getAttribute(name);
}
/**
* Returns an Enumeration containing the names of the attributes
* available to this request.
*
* @param name the named attribute
*
* @return Returns an Enumeration containing the names of the attributes
*/
public Enumeration getAttributeNames() {
return request.getAttributeNames();
}
/**
* Stores an attribute in this request.
*
* @param attribute name
* @param attribute value
*
* @return none
*/
public void setAttribute(String name, Object value) {
request.setAttribute(name, value);
}
/**
* Removes an attribute from this request.
*
* @param attribute name
*
* @return none
*/
public void removeAttribute(String name) {
request.removeAttribute(name);
}
/**
* Returns the name of the character encoding used in the body of this request.
*
* @param none
*
* @return Returns the name of the character encoding
*/
public String getCharacterEncoding() {
return request.getCharacterEncoding();
}
/**
* Returns the length, in bytes, of the request body
* and made available by the input stream, or -1 if the length is not known.
*
* @param none
*
* @return Returns the length
*/
public int getContentLength() {
return request.getContentLength();
}
/**
* Returns the MIME type of the body of the request,
* or null if the type is not known.
*
* @param none
*
* @return Returns the MIME type
*/
public String getContentType() {
return request.getContentType();
}
/**
* Returns an array containing all of the Cookie objects
* the client sent with this request.
*
* @param none
*
* @return Returns the Cookie objects
*/
public Cookie[] getCookies() {
return request.getCookies();
}
/**
* Returns the value of the specified request header
* as a long value that represents a Date object.
*
* @param name
*
* @return Returns a long value representing the date
*/
public long getDateHeader(String name) {
return request.getDateHeader(name);
}
/**
* Returns the value of the specified request header as a String.
*
* @param name
*
* @return Returns the header
*/
public String getHeader(String name) {
return request.getHeader(name);
}
/**
* Returns all the values of the specified request header as an Enumeration of String objects.
*
* @param name
*
* @return Returns an enumeration of all the header names
*/
public Enumeration getHeaders(String name) {
return request.getHeaders(name);
}
/**
* Returns an enumeration of all the header names this request contains.
*
* @param none
*
* @return Returns an enumeration of all the header names
*/
public Enumeration getHeaderNames() {
return request.getHeaderNames();
}
/**
* Retrieves the body of the request as binary data using a ServletInputStream.
*
* @param none
*
* @return Returns the body of the request
*/
public ServletInputStream getInputStream() throws IOException {
Domain.debug("ENTER: XHttpServletRequestFacade:getInputStream()");
if (usingReader) {
throw new IllegalStateException("getReader() method has been called on this request");
}
usingStream = true;
if ( inStreamFacade == null ) {
inStreamFacade = new XServletInputStreamFacade( request.getInputStream());
}
Domain.debug("LEAVE: XHttpServletRequestFacade:getInputStream()");
return ( inStreamFacade );
}
/**
* Reads the next byte of data from the input stream.
*
* @param none
*
* @return the next byte of data, or -1 if the end of the stream is reached
*/
public int doRead() throws IOException {
return inStreamFacade.read();
}
/**
* Reads up to len bytes of data from the input stream into an array of bytes.
*
* @param b - the buffer into which the data is read.
* @param off - the start offset in array b at which the data is written.
* @param len - the maximum number of bytes to read.
*
* @return the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
*/
public int doRead( byte b[], int off, int len ) throws IOException {
return inStreamFacade.read( b, off, len );
}
/**
* Returns the value of the specified request header as an int.
*
* @param parameter name
*
* @return Returns the value
*/
/** Adapter: Tomcat Request doesn't deal with header to int conversion.
*/
public int getIntHeader(String name)
throws NumberFormatException
{
String value=request.getHeader( name );
if( value==null) return -1;
int valueInt=Integer.parseInt(value);
return valueInt;
}
/**
* Returns the name of the HTTP method with which
* this request was made, for example, GET, POST, or PUT.
*
* @param none
*
* @return Returns the method name
*/
public String getMethod() {
return request.getMethod();
}
/**
* Returns the value of a request parameter as a String,
* or null if the parameter does not exist.
*
* @param parameter name
*
* @return Returns the value
*/
/** Adapter: Request doesn't deal with this servlet convention
*/
public String getParameter(String name) {
return request.getParameter( name );
}
/**
* Returns an array of String objects containing all of the values
* the given request parameter has, or null if the parameter does not exist.
*
* @param parameter name
*
* @return Returns parameter values
*/
public String[] getParameterValues(String name) {
return request.getParameterValues(name);
}
/**
* Returns an Enumeration of String objects containing
* the names of the parameters contained in this request.
*
* @param none
*
* @return Returns an Enumeration of String objects
*/
/** Adapter: Request doesn't deal with this servlet convention
*/
public Enumeration getParameterNames() {
return request.getParameterNames();
}
/**
* Returns any extra path information associated with the
* URL the client sent when it made this request.
*
* @param none
*
* @return Returns any extra path information
*/
public String getPathInfo() {
return request.getPathInfo();
}
/**
* Returns any extra path information after the servlet
* name but before the query string, and translates it to a real path.
*
* @param none
*
* @return Returns any extra path information after the servlet name
*/
public String getPathTranslated() {
return request.getPathTranslated();
}
/**
* Returns the name and version of the protocol the request
* uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
*
* @param none
*
* @return Returns the name and version of the protocol
*/
public String getProtocol() {
return request.getProtocol();
}
/**
* Returns the query string that is contained in the request URL after the path.
*
* @param none
*
* @return Returns the query string
*/
public String getQueryString() {
return request.getQueryString();
}
/**
* Returns the login of the user making this request,
* if the user has been authenticated, or null if the user has not been authenticated.
*
* @param none
*
* @return Returns the login of the user making this request
*/
public String getRemoteUser() {
return request.getRemoteUser();
}
/**
* Returns the name of the scheme used to make this request,
* for example, http, https, or ftp.
*
* @param none
*
* @return Returns the name of the scheme
*/
public String getScheme() {
return request.getScheme();
}
/**
* Returns the host name of the server that received the request.
*
* @param none
*
* @return Returns the host name of the server
*/
public String getServerName() {
return request.getServerName();
}
/**
* Returns the port number on which this request was received.
*
* @param none
*
* @return Returns the port number
*/
public int getServerPort() {
return request.getServerPort();
}
/**
* Retrieves the body of the request as character data using a BufferedReader.
*
* @param none
*
* @return Returns a BufferedReader
*/
public BufferedReader getReader() throws IOException {
Domain.debug("ENTER: XHttpServletRequestFacade:getReader()");
if (usingStream) {
throw new IllegalStateException("getInputStream() method has been called on this request");
}
usingReader = true;
if ( inStreamFacade == null ) {
inStreamFacade = new XServletInputStreamFacade( request.getInputStream());
}
if( reader != null ) {
Domain.debug("LEAVE: XHttpServletRequestFacade:getReader() - reader != null");
return reader; // method already called
}
String encoding = request.getCharacterEncoding();
if (encoding == null) {
encoding = DEFAULT_CHAR_ENCODING;
}
InputStreamReader r = new InputStreamReader(inStreamFacade, encoding);
reader= new BufferedReader(r);
Domain.debug("LEAVE: XHttpServletRequestFacade:getReader() - new BufferedReader");
return reader;
}
/**
* Returns the Internet Protocol (IP) address of the client that sent the request
*
* @param none
*
* @return Returns IP address
*/
public String getRemoteAddr() {
return request.getRemoteAddr();
}
/**
* Returns the fully qualified name of the client
* that sent the request, or the IP address of the client
* if the name cannot be determined.
*
* @param none
*
* @return Returns client name
*/
public String getRemoteHost() {
return request.getRemoteHost();
}
/**
* Returns the part of this request's URL from the
* protocol name up to the query string in the first line of the HTTP request.
*
* @param none
*
* @return Returns the part of this request's URL
*/
public String getRequestURI() {
return request.getRequestURI();
}
/**
* Returns a RequestDispatcher object that acts as a wrapper
* for the resource located at the given path.
*
* @param path
*
* @return Returns RequestDispatcher
*/
public RequestDispatcher getRequestDispatcher(String path) {
return request.getRequestDispatcher(path);
}
/**
* Returns the preferred Locale that the client will accept content in,
* based on the Accept-Language header.
*
* @param none
*
* @return Returns the preferred Locale
*/
/** Adapter: first elelment
*/
public Locale getLocale() {
return (Locale)getLocales().nextElement();
}
/**
* Returns an Enumeration of Locale objects indicating,
* in decreasing order starting with the preferred locale,
* the locales that are acceptable to the client based on the Accept-Language header.
*
* @param none
*
* @return Returns an Enumeration of Locale objects
*/
/** Delegate to RequestUtil
*/
public Enumeration getLocales() {
return request.getLocales();
}
/**
* Returns the portion of the request URI that indicates
* the context of the request.
*
* @param none
*
* @return Returns the URI
*/
/** Delegate to Context
*/
public String getContextPath() {
return request.getContextPath();
}
/**
* Returns the part of this request's URL that calls the servlet.
*
* @param none
*
* @return Returns the part of this request's URL that calls the servlet
*/
public String getServletPath() {
return request.getServletPath();
}
/**
* Deprecated. As of Version 2.1 of the Java Servlet API,
* use ServletContext.getRealPath(java.lang.String) instead.
*
* @deprecated
*
* @param parameter name
*
* @return Returns the value
*/
public String getRealPath(String name) {
return request.getRealPath(name);
}
// -------------------- Security --------------------
/**
* Returns the name of the authentication scheme
* used to protect the servlet, for example,
* "BASIC" or "SSL," or null if the servlet was not protected.
*
* @param none
*
* @return Returns the name of the authentication scheme
*/
public String getAuthType() {
return request.getAuthType();
}
/**
* Returns a boolean indicating whether this request was made
* using a secure channel, such as HTTPS.
*
* @param none
*
* @return Returns a boolean
*/
public boolean isSecure() {
return request.isSecure();
}
/**
* Returns a boolean indicating whether the authenticated
* user is included in the specified logical "role".
*
* @param role - a String specifying the name of the role
*
* @return Returns a boolean indicating whether the user making this request belongs to a given role; false if the user has not been authenticated
*/
public boolean isUserInRole(String role) {
return request.isUserInRole(role);
}
/**
* Returns a java.security.Principal object containing the
* name of the current authenticated user.
*
* @param none
*
* @return Returns a java.security.Principal object
*/
public Principal getUserPrincipal() {
return request.getUserPrincipal();
}
// -------------------- Session --------------------
/**
* Returns the current session associated with this request,
* or if the request does not have a session, creates one.
*
* @param none
*
* @return Returns the current session
*/
public HttpSession getSession() {
return request.getSession(true);
}
/**
* Returns the current HttpSession associated with this request
* or, if if there is no current session and create is true, returns a new session.
*
* @param true - to create a new session for this request if necessary;
* false to return null if there's no current session
*
* @return Returns the HttpSession associated with this request or null
* if create is false and the request has no valid session
*/
public HttpSession getSession(boolean create) {
return request.getSession( create );
}
/**
* Returns the session ID specified by the client.
*
* @param none
*
* @return Returns the session ID
*/
public String getRequestedSessionId() {
return request.getRequestedSessionId();
}
/**
* Checks whether the requested session ID is still valid.
*
* @param none
*
* @return Returns true if this request has an id for a valid session in the current session context; false otherwise
*/
public boolean isRequestedSessionIdValid() {
// so here we just assume that if we have a session it's,
// all good, else not.
HttpSession session = (HttpSession)request.getSession(false);
return (session != null);
}
/**
* Checks whether the requested session ID came in as a cookie.
*
* @param none
*
* @return Returns true if the session ID came in as a cookie; otherwise, false
*/
public boolean isRequestedSessionIdFromCookie() {
return request.isRequestedSessionIdFromCookie();
}
/**
* Deprecated. As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL() instead
*
* @param none
* @deprecated
*
* @return
*/
public boolean isRequestedSessionIdFromUrl() {
return isRequestedSessionIdFromURL();
}
/**
* Checks whether the requested session ID came in as part of the request URL.
*
* @param none
*
* @return true if the session ID came in as part of a URL; otherwise, false
*/
public boolean isRequestedSessionIdFromURL() {
return request.isRequestedSessionIdFromURL();
}
/**
* Returns the content of the buffered input stream.
*
* @return copy of input stream as string.
*/
public String getRequestBody() throws IOException {
if ( usingStream ){
Domain.debug("XHttpServletRequestFacade:getRequestBody() - usingStream");
return inStreamFacade.getBufferContent();
} else if ( usingReader ) {
Domain.debug("XHttpServletRequestFacade:getRequestBody() - usingReader");
return reader.toString();
} else {
Domain.debug("XHttpServletRequestFacade:getRequestBody() - nor Reader nor Stream - do nothing");
return "";
}
}
}
1.1 jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XHttpServletRequestFacade23.java
Index: XHttpServletRequestFacade23.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XHttpServletRequestFacade23.java,v 1.1 2001/08/01 14:33:05 cmlenz Exp $
* $Revision: 1.1 $
* $Date: 2001/08/01 14:33:05 $
*
* ====================================================================
*
* 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.slide.webdav.logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletInputStream;
import javax.servlet.RequestDispatcher;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Locale;
import java.security.Principal;
import org.apache.slide.common.Domain;
/**
* This class supports additional set-methods and a re-readable
* inputstream to the interface javax.servlet.http.HttpServletRequest.
*
* @author Hardy.Kiefer@softwareag.com
* Christopher Lenz (cmlenz at apache.org)
*
* @version 0.1
*
* @invariant (inputStream != null)
*
* @see javax.servlet.http.HttpServletRequest
*
*/
public class XHttpServletRequestFacade extends HttpServletRequestWrapper {
public static final String DEFAULT_CHAR_ENCODING = "8859_1";
/**
* the inputstream to re-read.
*
* @see java.io.BufferedInputStream
*/
private XServletInputStreamFacade inStreamFacade = null;
/**
* buffered reader which uses the input stream
*
* @see java.io.BufferedReader
*/
private BufferedReader reader = null;
/**
* true - if inputstream can read using a reader; false otherwise.
*/
private boolean usingReader = false;
/**
* true - if inputstream can read using a stream; false otherwise.
*/
private boolean usingStream = false;
/**
* This constructor creates an re-readable HttpServletRequest.
*
* @pre (req != null)
* @post
*
* @param req HttpServletRequest
*
* @exception
*
* @time
* @space
*
* @see
*/
public XHttpServletRequestFacade (HttpServletRequest request) {
super(request);
Domain.debug("Create XHttpServletRequestFacade");
}
/**
* Retrieves the body of the request as binary data using a ServletInputStream.
*
* @param none
*
* @return Returns the body of the request
*/
public ServletInputStream getInputStream() throws IOException {
Domain.debug("ENTER: XHttpServletRequestFacade:getInputStream()");
if (usingReader) {
throw new IllegalStateException("getReader() method has been called on this request");
}
usingStream = true;
if ( inStreamFacade == null ) {
inStreamFacade = new XServletInputStreamFacade( super.getInputStream());
}
Domain.debug("LEAVE: XHttpServletRequestFacade:getInputStream()");
return ( inStreamFacade );
}
/**
* Reads the next byte of data from the input stream.
*
* @param none
*
* @return the next byte of data, or -1 if the end of the stream is reached
*/
public int doRead() throws IOException {
return inStreamFacade.read();
}
/**
* Reads up to len bytes of data from the input stream into an array of bytes.
*
* @param b - the buffer into which the data is read.
* @param off - the start offset in array b at which the data is written.
* @param len - the maximum number of bytes to read.
*
* @return the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
*/
public int doRead( byte b[], int off, int len ) throws IOException {
return inStreamFacade.read( b, off, len );
}
/**
* Retrieves the body of the request as character data using a BufferedReader.
*
* @param none
*
* @return Returns a BufferedReader
*/
public BufferedReader getReader() throws IOException {
Domain.debug("ENTER: XHttpServletRequestFacade:getReader()");
if (usingStream) {
throw new IllegalStateException("getInputStream() method has been called on this request");
}
usingReader = true;
if ( inStreamFacade == null ) {
inStreamFacade = new XServletInputStreamFacade( super.getInputStream());
}
if( reader != null ) {
Domain.debug("LEAVE: XHttpServletRequestFacade:getReader() - reader != null");
return reader; // method already called
}
String encoding = super.getCharacterEncoding();
if (encoding == null) {
encoding = DEFAULT_CHAR_ENCODING;
}
InputStreamReader r = new InputStreamReader(inStreamFacade, encoding);
reader= new BufferedReader(r);
Domain.debug("LEAVE: XHttpServletRequestFacade:getReader() - new BufferedReader");
return reader;
}
/**
* Returns the content of the buffered input stream.
*
* @return copy of input stream as string.
*/
public String getRequestBody() throws IOException {
if ( usingStream ){
Domain.debug("XHttpServletRequestFacade:getRequestBody() - usingStream");
return inStreamFacade.getBufferContent();
} else if ( usingReader ) {
Domain.debug("XHttpServletRequestFacade:getRequestBody() - usingReader");
return reader.toString();
} else {
Domain.debug("XHttpServletRequestFacade:getRequestBody() - nor Reader nor Stream - do nothing");
return "";
}
}
}
1.1 jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XHttpServletResponseFacade22.java
Index: XHttpServletResponseFacade22.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XHttpServletResponseFacade22.java,v 1.1 2001/08/01 14:33:05 cmlenz Exp $
* $Revision: 1.1 $
* $Date: 2001/08/01 14:33:05 $
*
* ====================================================================
*
* 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.slide.webdav.logger;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.BufferedOutputStream;
import java.io.IOException;
// import java.net.*;
import java.util.Locale;
import java.util.Enumeration;
import java.util.Vector;
// import java.lang.IllegalArgumentException;
import javax.servlet.http.Cookie;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.slide.common.Domain;
/**
* This class supports additional set-methods and a re-readable
* inputstream to the interface javax.servlet.http.HttpServletResponse.
*
* @author Hardy.Kiefer@softwareag.com
*
* @version 0.1
*
* @invariant (inputStream != null)
*
* @see javax.servlet.http.HttpServletResponse
*
*/
public class XHttpServletResponseFacade implements HttpServletResponse
{
public static final String DEFAULT_CHAR_ENCODING = "8859_1";
// default implementation will just append everything here
StringBuffer body=null;
/**
* the HttpServletResponse to re-read.
*
* @invariant (response != null)
*
* @see javax.servlet.http.HttpServletResponse
*/
private HttpServletResponse response;
protected HttpServletRequest request;
public void setRequest(HttpServletRequest request) {
this.request = request;
}
public HttpServletRequest getRequest() {
return request;
}
/**
* true - if outputstream can write using a stream; false otherwise.
*/
private boolean usingStream = false;
/**
* true - if outputstream can write using a writer; false otherwise.
*/
private boolean usingWriter = false;
/**
* output stream used for building the writer.
*
* @see javax.servlet.ServletOutputStream
*/
XServletOutputStreamFacade osFacade = null;
/**
* writer which uses the output stream.
*
* @see java.io.PrintWriter
*/
PrintWriter writer = null;
/**
* response headers
*/
Vector responseHeaders = new Vector();
public Enumeration getResponseHeaders() {
return responseHeaders.elements();
}
/**
* This constructor creates an re-writable HttpServletRes�pmse.
*
* @pre (response != null)
* @post
*
* @param response HttpServletResponse
*
* @exception
*
* @time
* @space
*
* @see
*/
public XHttpServletResponseFacade(HttpServletResponse response) {
Domain.debug("Create XHttpServletResponseFacade");
this.response = response;
}
// -------------------- Public methods --------------------
/**
* Adds the specified cookie to the response.
*
* @param cookie - the Cookie to return to the client
*
* @return none
*/
public void addCookie(javax.servlet.http.Cookie cookie) {
responseHeaders.add(
new XResponseHeader(
"Cookie",
cookie.getName() + " " +
cookie.getValue() + " " +
cookie.getDomain()
)
);
response.addCookie(cookie);
}
/**
* Returns a boolean indicating whether the named response header has already been set.
*
* @param name - the header name
*
* @return true if the named response header has already been set; false otherwise
*/
public boolean containsHeader(String name) {
return response.containsHeader(name);
}
/**
* Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.
*
* @param url - the url to be encoded.
*
* @return the encoded URL if encoding is needed; the unchanged URL otherwise.
*/
public String encodeRedirectURL(String location) {
return response.encodeRedirectURL(location);
}
/**
* Deprecated. As of version 2.1, use encodeRedirectURL(String url) instead
*
* @param url - the url to be encoded.
*
* @return the encoded URL if encoding is needed; the unchanged URL otherwise.
* @deprecated
*/
public String encodeRedirectUrl(String location) {
return encodeRedirectURL(location);
}
/**
* Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
*
* @param url - the url to be encoded.
*
* @return the encoded URL if encoding is needed; the unchanged URL otherwise.
*/
public String encodeURL(String url) {
return response.encodeUrl(url);
}
/**
* Deprecated. As of version 2.1, use encodeURL(String url) instead.
*
* @param url - the url to be encoded.
*
* @return the encoded URL if encoding is needed; the unchanged URL otherwise.
*
* @deprecated
*/
public String encodeUrl(String url) {
return encodeURL(url);
}
/**
* Returns the name of the charset used for the MIME body sent in this response.
*
* @return a String specifying the name of the charset, for example, ISO-8859-1
*/
public String getCharacterEncoding() {
return response.getCharacterEncoding();
}
/**
* Returns a ServletOutputStream suitable for writing binary data in the response.
*
* @return a ServletOutputStream for writing binary data
*/
public ServletOutputStream getOutputStream()
throws IOException {
Domain.debug("ENTER: XHttpServletResponseFacade:getOutputStream()");
if ( usingWriter ) {
throw new IllegalStateException("Writer is already being used for this response");
}
usingStream = true;
if( osFacade == null ) {
osFacade = new XServletOutputStreamFacade(
response.getOutputStream(),
response.getCharacterEncoding());
}
Domain.debug("LEAVE: XHttpServletResponseFacade:getOutputStream()");
return osFacade;
}
/**
* Returns a PrintWriter object that can send character text to the client.
*
* @return a PrintWriter object that can return character data to the client
*/
public PrintWriter getWriter() throws IOException {
Domain.debug("ENTER: XHttpServletResponseFacade:getWriter()");
if (usingStream) {
throw new IllegalStateException("OutputStream is already being used for this response");
}
usingWriter= true ;
if( writer == null ) {
writer = new XServletWriterFacade( response.getWriter() );
}
Domain.debug("LEAVE: XHttpServletResponseFacade:getWriter()");
return writer;
}
public PrintWriter getWriter(ServletOutputStream outs) throws IOException {
Domain.debug("ENTER: XHttpServletResponseFacade:getWriter(ServletOutputStream)");
if(writer!=null) return writer;
// it already did all the checkings
//hak started = true;
usingWriter = true;
// writer = new XServletWriterFacade( getConverter(outs), this);
Domain.debug("LEAVE: XHttpServletResponseFacade:getWriter(ServletOutputStream)");
return writer;
}
public Writer getConverter( ServletOutputStream outs ) throws IOException {
String encoding = getCharacterEncoding();
OutputStreamWriter osWriter;
if (encoding == null) {
// use default platform encoding - is this correct ?
osWriter = new OutputStreamWriter(outs);
} else {
try {
osWriter = new OutputStreamWriter(outs, encoding);
} catch (java.io.UnsupportedEncodingException ex) {
// XXX log it
System.out.println("Unsuported encoding: " + encoding );
return new OutputStreamWriter(outs);
}
}
return osWriter;
}
/**
* Sends an error response to the client using the specified status.
*
* @param sc - the error status code.
*/
public void sendError(int sc) throws IOException {
sendError(sc, "No detailed message");
}
/**
* Sends an error response to the client using the specified status code and descriptive message.
*
* @param sc - the error status code
* msg - the descriptive message
*/
public void sendError(int sc, String msg) throws IOException {
response.sendError(sc, msg);
}
/**
* Sends a temporary redirect response to the client using the specified redirect location URL.
*
* @param location - the redirect location URL
*/
public void sendRedirect(String location)
throws IOException, IllegalArgumentException {
response.sendRedirect(location);
}
private int contentLength = 0;
/**
* Sets the content type of the response being sent to the client.
*
* @param len - an integer specifying the length of the content being returned to the client; sets the Content-Length header
*/
public void setContentLength(int len) {
contentLength = len;
response.setContentLength(len);
}
public int getContentLength() {
return contentLength;
}
private String contentType;
/**
* Sets the content type of the response being sent to the client.
*
* @param type - a String specifying the MIME type of the content
*/
public void setContentType(String type) {
contentType = type;
response.setContentType(type);
}
public String getContentType() {
return contentType;
}
/**
* Sets a response header with the given name and date-value.
*
* @param name - the name of the header to set
* value - the assigned date value
*/
public void setDateHeader(String name, long date) {
responseHeaders.add(new XResponseHeader(name, String.valueOf(date)));
response.setDateHeader(name, date);
}
/**
* Adds a response header with the given name and date-value.
*
* @param name - the name of the header to set
* value - the additional date value
*/
public void addDateHeader(String name, long date) {
responseHeaders.add(new XResponseHeader(name, String.valueOf(date)));
response.addDateHeader(name, date);
}
/**
* Sets a response header with the given name and value.
*
* @param name - the name of the header
* value - the header value
*/
public void setHeader(String name, String value) {
responseHeaders.add(new XResponseHeader(name, value));
response.setHeader(name, value);
}
/**
* Adds a response header with the given name and value.
*
* @param name - the name of the header
* value - the header value
*/
public void addHeader(String name, String value) {
responseHeaders.add(new XResponseHeader(name, value));
response.addHeader(name, value);
}
/**
* Sets a response header with the given name and integer value.
*
* @param name - the name of the header
* value - the assigned integer value
*/
public void setIntHeader(String name, int value) {
responseHeaders.add(new XResponseHeader(name, String.valueOf(value)));
response.setHeader(name, Integer.toString(value));
}
/**
* Adds a response header with the given name and integer value.
*
* @param name - the name of the header
* value - the assigned integer value
*/
public void addIntHeader(String name, int value) {
responseHeaders.add(new XResponseHeader(name, String.valueOf(value)));
response.addHeader(name, Integer.toString(value));
}
/**
* Sets the status code for this response.
*
* @param sc - the status code
*/
public void setStatus(int sc) {
status = sc;
response.setStatus(sc);
}
private int bufferSize = 0;
/**
* Sets the preferred buffer size for the body of the response.
*
* @param size - the preferred buffer size
*/
public void setBufferSize(int size) throws IllegalStateException {
bufferSize = size;
response.setBufferSize(size);
}
/**
* Returns the actual buffer size used for the response.
*
* @return the actual buffer size used
*/
public int getBufferSize() {
return response.getBufferSize();
}
/**
* Clears any data that exists in the buffer as well as the status code and headers.
*/
public void reset() throws IllegalStateException {
response.reset();
}
/**
* Returns a boolean indicating if the response has been committed.
*
* @return a boolean indicating if the response has been committed
*/
public boolean isCommitted() {
return response.isCommitted();
}
/**
* Forces any content in the buffer to be written to the client.
*/
public void flushBuffer() throws IOException {
response.flushBuffer();
}
/**
* Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
*
* @param loc - the locale of the response
*/
public void setLocale(Locale loc) {
response.setLocale(loc);
}
/**
* Returns the locale assigned to the response.
*
* @return the locale assigned to the response.
*/
public Locale getLocale() {
return response.getLocale();
}
/**
*
* @deprecated
*/
private int status = -1;
private String msg = "";
public void setStatus(int sc, String msg) {
status = sc;
msg = msg;
response.setStatus(sc);
}
public int getStatus() {
return status;
}
public String getMessage() {
return msg;
}
/**
* Returns the content of the buffered output stream.
*
* @return copy of outputstream as string.
*/
public String getResponseBody() throws IOException {
if ( usingStream ) {
Domain.debug("XHttpServletResponseFacade:getResponseBody() - usingStream");
return osFacade.getOutputBuffer();
} else if ( usingWriter ) {
Domain.debug("XHttpServletResponseFacade:getResponseBody() - usingWriter");
return (( XServletWriterFacade )writer).getOutputBuffer();
} else {
Domain.debug("XHttpServletResponseFacade:getResponseBody() - nor writer nor stream - osFacade = " + osFacade + " writer = " + writer);
return "";
}
}
}
1.1 jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XHttpServletResponseFacade23.java
Index: XHttpServletResponseFacade23.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/logger/XHttpServletResponseFacade23.java,v 1.1 2001/08/01 14:33:05 cmlenz Exp $
* $Revision: 1.1 $
* $Date: 2001/08/01 14:33:05 $
*
* ====================================================================
*
* 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.slide.webdav.logger;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.Locale;
import java.util.Enumeration;
import java.util.Vector;
import javax.servlet.http.Cookie;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import javax.servlet.http.HttpServletRequest;
import org.apache.slide.common.Domain;
/**
* This class supports additional set-methods and a re-readable
* inputstream to the interface javax.servlet.http.HttpServletResponse.
*
* @author Hardy.Kiefer@softwareag.com
* Christopher Lenz (cmlenz at apache.org)
*
* @version 0.1
*
* @invariant (inputStream != null)
*
* @see javax.servlet.http.HttpServletResponse
*
*/
public class XHttpServletResponseFacade extends HttpServletResponseWrapper
{
public static final String DEFAULT_CHAR_ENCODING = "8859_1";
// default implementation will just append everything here
StringBuffer body=null;
protected HttpServletRequest request;
public void setRequest(HttpServletRequest request) {
this.request = request;
}
public HttpServletRequest getRequest() {
return request;
}
/**
* true - if outputstream can write using a stream; false otherwise.
*/
private boolean usingStream = false;
/**
* true - if outputstream can write using a writer; false otherwise.
*/
private boolean usingWriter = false;
/**
* output stream used for building the writer.
*
* @see javax.servlet.ServletOutputStream
*/
XServletOutputStreamFacade osFacade = null;
/**
* writer which uses the output stream.
*
* @see java.io.PrintWriter
*/
PrintWriter writer = null;
/**
* response headers
*/
Vector responseHeaders = new Vector();
public Enumeration getResponseHeaders() {
return responseHeaders.elements();
}
/**
* This constructor creates an re-writable HttpServletRes�pmse.
*
* @pre (response != null)
* @post
*
* @param response HttpServletResponse
*
* @exception
*
* @time
* @space
*
* @see
*/
public XHttpServletResponseFacade(HttpServletResponse response) {
super(response);
Domain.debug("Create XHttpServletResponseFacade");
}
// -------------------- Public methods --------------------
/**
* Adds the specified cookie to the response.
*
* @param cookie - the Cookie to return to the client
*
* @return none
*/
public void addCookie(javax.servlet.http.Cookie cookie) {
responseHeaders.add(
new XResponseHeader(
"Cookie",
cookie.getName() + " " +
cookie.getValue() + " " +
cookie.getDomain()
)
);
super.addCookie(cookie);
}
/**
* Returns a ServletOutputStream suitable for writing binary data in the response.
*
* @return a ServletOutputStream for writing binary data
*/
public ServletOutputStream getOutputStream()
throws IOException {
Domain.debug("ENTER: XHttpServletResponseFacade:getOutputStream()");
if ( usingWriter ) {
throw new IllegalStateException("Writer is already being used for this response");
}
usingStream = true;
if( osFacade == null ) {
osFacade = new XServletOutputStreamFacade(
super.getOutputStream(),
super.getCharacterEncoding());
}
Domain.debug("LEAVE: XHttpServletResponseFacade:getOutputStream()");
return osFacade;
}
/**
* Returns a PrintWriter object that can send character text to the client.
*
* @return a PrintWriter object that can return character data to the client
*/
public PrintWriter getWriter() throws IOException {
Domain.debug("ENTER: XHttpServletResponseFacade:getWriter()");
if (usingStream) {
throw new IllegalStateException("OutputStream is already being used for this response");
}
usingWriter= true ;
if( writer == null ) {
writer = new XServletWriterFacade( super.getWriter() );
}
Domain.debug("LEAVE: XHttpServletResponseFacade:getWriter()");
return writer;
}
public PrintWriter getWriter(ServletOutputStream outs) throws IOException {
Domain.debug("ENTER: XHttpServletResponseFacade:getWriter(ServletOutputStream)");
if(writer!=null) return writer;
// it already did all the checkings
//hak started = true;
usingWriter = true;
// writer = new XServletWriterFacade( getConverter(outs), this);
Domain.debug("LEAVE: XHttpServletResponseFacade:getWriter(ServletOutputStream)");
return writer;
}
public Writer getConverter( ServletOutputStream outs ) throws IOException {
String encoding = getCharacterEncoding();
OutputStreamWriter osWriter;
if (encoding == null) {
// use default platform encoding - is this correct ?
osWriter = new OutputStreamWriter(outs);
} else {
try {
osWriter = new OutputStreamWriter(outs, encoding);
} catch (java.io.UnsupportedEncodingException ex) {
// XXX log it
System.out.println("Unsuported encoding: " + encoding );
return new OutputStreamWriter(outs);
}
}
return osWriter;
}
/**
* Sets a response header with the given name and date-value.
*
* @param name - the name of the header to set
* value - the assigned date value
*/
public void setDateHeader(String name, long date) {
responseHeaders.add(new XResponseHeader(name, String.valueOf(date)));
super.setDateHeader(name, date);
}
/**
* Adds a response header with the given name and date-value.
*
* @param name - the name of the header to set
* value - the additional date value
*/
public void addDateHeader(String name, long date) {
responseHeaders.add(new XResponseHeader(name, String.valueOf(date)));
super.addDateHeader(name, date);
}
/**
* Sets a response header with the given name and value.
*
* @param name - the name of the header
* value - the header value
*/
public void setHeader(String name, String value) {
responseHeaders.add(new XResponseHeader(name, value));
super.setHeader(name, value);
}
/**
* Adds a response header with the given name and value.
*
* @param name - the name of the header
* value - the header value
*/
public void addHeader(String name, String value) {
responseHeaders.add(new XResponseHeader(name, value));
super.addHeader(name, value);
}
/**
* Sets a response header with the given name and integer value.
*
* @param name - the name of the header
* value - the assigned integer value
*/
public void setIntHeader(String name, int value) {
responseHeaders.add(new XResponseHeader(name, String.valueOf(value)));
super.setHeader(name, Integer.toString(value));
}
/**
* Adds a response header with the given name and integer value.
*
* @param name - the name of the header
* value - the assigned integer value
*/
public void addIntHeader(String name, int value) {
responseHeaders.add(new XResponseHeader(name, String.valueOf(value)));
super.addHeader(name, Integer.toString(value));
}
/**
*
* @deprecated
*/
private int status = -1;
private String msg = "";
public void setStatus(int sc, String msg) {
status = sc;
msg = msg;
super.setStatus(sc);
}
public int getStatus() {
return status;
}
public String getMessage() {
return msg;
}
/**
* Returns the content of the buffered output stream.
*
* @return copy of outputstream as string.
*/
public String getResponseBody() throws IOException {
if ( usingStream ) {
Domain.debug("XHttpServletResponseFacade:getResponseBody() - usingStream");
return osFacade.getOutputBuffer();
} else if ( usingWriter ) {
Domain.debug("XHttpServletResponseFacade:getResponseBody() - usingWriter");
return (( XServletWriterFacade )writer).getOutputBuffer();
} else {
Domain.debug("XHttpServletResponseFacade:getResponseBody() - nor writer nor stream - osFacade = " + osFacade + " writer = " + writer);
return "";
}
}
}