[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    cvs commit: jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl BufferedSe
From:       jstrachan () apache ! org
Date:       2001-10-29 22:32:47
[Download RAW message or body]

jstrachan    01/10/29 14:32:47

  Modified:    messenger/src/java/org/apache/commons/messagelet/impl
                        MessageletRequestImpl.java
                        MessageletResponseImpl.java ServletRequestImpl.java
  Added:       messenger/src/java/org/apache/commons/messagelet/impl
                        BufferedServletInputStream.java
                        HttpMessageletRequestImpl.java
                        HttpMessageletResponseImpl.java
                        HttpServletRequestImpl.java
                        HttpServletResponseImpl.java
  Log:
  Added HttpServetRequest and HttpServletResponse implementation classes ready for \
the Messagelet dispatcher which is capable of dispatching to a HTTP style servlet \
such as JSP  
  Revision  Changes    Path
  1.3       +3 -3      \
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/MessageletRequestImpl.java
  
  Index: MessageletRequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/MessageletRequestImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MessageletRequestImpl.java	2001/10/26 14:27:26	1.2
  +++ MessageletRequestImpl.java	2001/10/29 22:32:47	1.3
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: MessageletRequestImpl.java,v 1.2 2001/10/26 14:27:26 jstrachan Exp $
  + * $Id: MessageletRequestImpl.java,v 1.3 2001/10/29 22:32:47 jstrachan Exp $
    */
   package org.apache.commons.messagelet.impl;
   
  @@ -30,11 +30,11 @@
   import org.apache.commons.collections.IteratorEnumeration;
   import org.apache.commons.messagelet.MessageletRequest;
   
  -/** <p><code>JmsServletRequest</code> represents a servlet request from
  +/** <p><code>MessageletRequestImpl</code> represents a servlet request from
     * a JMS Message source.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.2 $
  +  * @version $Revision: 1.3 $
     */
   public class MessageletRequestImpl extends ServletRequestWrapper implements \
MessageletRequest {  
  
  
  
  1.4       +3 -3      \
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/MessageletResponseImpl.java
  
  Index: MessageletResponseImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/MessageletResponseImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MessageletResponseImpl.java	2001/10/26 14:27:26	1.3
  +++ MessageletResponseImpl.java	2001/10/29 22:32:47	1.4
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: MessageletResponseImpl.java,v 1.3 2001/10/26 14:27:26 jstrachan Exp $
  + * $Id: MessageletResponseImpl.java,v 1.4 2001/10/29 22:32:47 jstrachan Exp $
    */
   package org.apache.commons.messagelet.impl;
   
  @@ -24,11 +24,11 @@
   import org.apache.commons.messagelet.MessageletResponse;
   import org.apache.commons.messenger.Messenger;
   
  -/** <p><code>JmsServletResponse</code> represents a servlet request from
  +/** <p><code>MessageletResponseImpl</code> represents a servlet request from
     * a JMS Message source.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.3 $
  +  * @version $Revision: 1.4 $
     */
   public class MessageletResponseImpl extends ServletResponseWrapper implements \
MessageletResponse {  
  
  
  
  1.2       +4 -6      \
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/ServletRequestImpl.java
  
  Index: ServletRequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/ServletRequestImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletRequestImpl.java	2001/10/26 11:52:16	1.1
  +++ ServletRequestImpl.java	2001/10/29 22:32:47	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/ServletRequestImpl.java,v \
                1.1 2001/10/26 11:52:16 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/10/26 11:52:16 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/ServletRequestImpl.java,v \
1.2 2001/10/29 22:32:47 jstrachan Exp $  + * $Revision: 1.2 $
  + * $Date: 2001/10/29 22:32:47 $
    *
    * ====================================================================
    *
  @@ -92,7 +92,7 @@
    *
    * @author Craig R. McClanahan
    * @author James Strachan
  - * @version $Revision: 1.1 $ $Date: 2001/10/26 11:52:16 $
  + * @version $Revision: 1.2 $ $Date: 2001/10/29 22:32:47 $
    */
   
   public class ServletRequestImpl implements ServletRequest {
  @@ -219,8 +219,6 @@
       }
       
       // ------------------------------------------------------------- Properties
  -
  -
   
   
   
  
  
  
  1.1                  \
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/BufferedServletInputStream.java
  
  Index: BufferedServletInputStream.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   * 
   * $Id: BufferedServletInputStream.java,v 1.1 2001/10/29 22:32:47 jstrachan Exp $
   */
  package org.apache.commons.messagelet.impl;
  
  import java.io.ByteArrayInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.UnsupportedEncodingException;
  
  
  import javax.servlet.ServletInputStream;
  
  /** 
   * <p><code>BufferedServletInputStream</code> implements
   * a ServletInputStream using an underlying InputStream.</p>
   *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
   */
  public class BufferedServletInputStream extends ServletInputStream {
      
      protected static final byte[] NO_DATA = new byte[0];
      
      /** The underlying <code>InputStream</code> */
      private InputStream in;
      
      
      public BufferedServletInputStream() {
          this.in = new ByteArrayInputStream( NO_DATA );
      }
      
      public BufferedServletInputStream(InputStream in) {
          this.in = in;
      }
      
      public BufferedServletInputStream(String text) {
          in = new ByteArrayInputStream( text.getBytes() );
      }
      
      public BufferedServletInputStream(byte[] data) {
          in = new ByteArrayInputStream(data);
      }
      
      // Delegating methods from InputStream
      //-------------------------------------------------------------------------    
      
      public int available() throws IOException {
          return in.available();
      }    
      
      public void close() throws IOException {
          in.close();
      }
      
      public void mark(int readlimit) {
          in.mark(readlimit);
      }
      
      public boolean markSupported() {
          return in.markSupported();
      }
      
      public int read(byte[] b) throws IOException {
          return in.read(b);
      }
      
      public int read(byte[] b, int off, int len) throws IOException {
          return in.read(b, off, len);
      }
      
      public int read() throws IOException {
          return in.read();
      }
          
      public void reset() throws IOException {
          in.reset();
      }    
      
      public long skip(long n) throws IOException {
          return in.skip(n);
      }    
  }
  
  
  
  1.1                  \
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/HttpMessageletRequestImpl.java
  
  Index: HttpMessageletRequestImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   * 
   * $Id: HttpMessageletRequestImpl.java,v 1.1 2001/10/29 22:32:47 jstrachan Exp $
   */
  package org.apache.commons.messagelet.impl;
  
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  
  import java.util.Collections;
  import java.util.Enumeration;
  import java.util.HashMap;
  import java.util.Map;
  
  import javax.jms.JMSException;
  import javax.jms.Message;
  import javax.jms.MessageListener;
  import javax.jms.TextMessage;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.ServletInputStream;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletRequestWrapper;
  
  import org.apache.commons.collections.IteratorEnumeration;
  import org.apache.commons.messagelet.MessageletRequest;
  
  /** <p><code>HttpMessageletRequestImpl</code> represents a servlet request from
    * a JMS Message source which appears to be a HTTP request so that JSP can process
    * the request as if it were a HTTP request.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class HttpMessageletRequestImpl extends HttpServletRequestWrapper implements \
MessageletRequest {  
      /** The Message which caused this request */
      private Message message;
      /** The parameters of this request or null if they have not been parsed yet */
      private Map parameters;
      /** The stream to read the body of the current Message */
      private ServletInputStream stream;
      
      public HttpMessageletRequestImpl(HttpServletRequest request) {
          super(request);
      }
  
      public void setMessage(Message message) throws JMSException {
          this.message = message;
          this.parameters = null;
          this.stream = createInputStream();
      }
      
      // MessageletRequest methods
      //-------------------------------------------------------------------------    
      
      /** @return the Message which originated this request */
      public Message getMessage() {
          return message;
      }
  
      
      // ServletRequest methods
      //-------------------------------------------------------------------------    
  
      public ServletInputStream getInputStream() {
          return stream;
      }
  
      public BufferedReader getReader() {
          return new BufferedReader( new InputStreamReader( stream ) );
      }
  
  
      /**
       * Return the value of the specified request parameter, if any; otherwise,
       * return <code>null</code>.  If there is more than one value defined,
       * return only the first one.
       *
       * @param name Name of the desired request parameter
       */
      public String getParameter(String name) {
  
          parseParameters();
          String values[] = (String[]) parameters.get(name);
          if (values != null)
              return (values[0]);
          else
              return (null);
  
      }
  
  
      /**
       * Returns a <code>Map</code> of the parameters of this request.
       * Request parameters are extra information sent with the request.
       * For HTTP servlets, parameters are contained in the query string
       * or posted form data.
       *
       * @return A <code>Map</code> containing parameter names as keys
       *  and parameter values as map values.
       */
      public Map getParameterMap() {
          parseParameters();
          return parameters;
      }
  
  
      /**
       * Return the names of all defined request parameters for this request.
       */
      public Enumeration getParameterNames() {
          parseParameters();
          return new IteratorEnumeration(parameters.keySet().iterator());
      }
  
  
      /**
       * Return the defined values for the specified request parameter, if any;
       * otherwise, return <code>null</code>.
       *
       * @param name Name of the desired request parameter
       */
      public String[] getParameterValues(String name) {
          parseParameters();
          String values[] = (String[]) parameters.get(name);
          if (values != null)
              return (values);
          else
              return (null);
      }
  
  
      // Implementation methods
      //-------------------------------------------------------------------------    
  
  
      /**
       * Parse the parameters of this request, if it has not already occurred.
       */
      protected void parseParameters() {
          if (parameters == null) {
              Map map = new HashMap();
              parameters = Collections.unmodifiableMap( map );
          }
      }
      
      protected ServletInputStream createInputStream() throws JMSException {
          if ( message instanceof TextMessage ) {
              TextMessage textMessage = (TextMessage) message;
              return new BufferedServletInputStream( textMessage.getText() );
          }
          
          // ##### handle ByteMessage and StreamMessage somehow one day?
          return new BufferedServletInputStream();
      }
      
  }
  
  
  
  
  1.1                  \
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/HttpMessageletResponseImpl.java
  
  Index: HttpMessageletResponseImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   * 
   * $Id: HttpMessageletResponseImpl.java,v 1.1 2001/10/29 22:32:47 jstrachan Exp $
   */
  package org.apache.commons.messagelet.impl;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import javax.jms.Destination;
  import javax.jms.JMSException;
  import javax.jms.Message;
  import javax.jms.MessageListener;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpServletResponseWrapper;
  
  import org.apache.commons.messagelet.MessageletResponse;
  import org.apache.commons.messenger.Messenger;
  
  /** <p><code>HttpMessageletResponseImpl</code> represents a servlet request from
    * a JMS Message source which appears like a HTTP request.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class HttpMessageletResponseImpl extends HttpServletResponseWrapper \
implements MessageletResponse {  
      /** the messenger used to send replies to */
      private Messenger messenger;
      /** the reply to destination to send replies to */
      private Destination replyToDestination;
      
      /** The BufferedServletOutputStream that is given to the servlet to capture
       * the response 
       */
      private BufferedServletOutputStream stream = null;
      /** The PrintWriter that has been returned by getWriter(), if any */
      protected PrintWriter writer;
      
      public HttpMessageletResponseImpl(HttpServletResponse response) {
          super(response);
      }
  
      /** Resets the response, ready for a new request */
      public void reset() {
          writer = null;
          stream = null;
      }
      
      /** Called to finish the request */
      public void finish() throws IOException, JMSException {
          try {
              if ( writer != null ) {
                  writer.flush();
                  writer.close();
              }
              if ( stream != null ) {
                  byte[] data = stream.toByteArray();
  
                  // for now assume a text message
                  String text = new String(data);
                  Message message = getReplyMessenger().createTextMessage( text );
                  sendReply( message );
              }
          }
          finally {
              writer = null;
              stream = null;
          }
      }
      
      // MessageletResponse methods
      //-------------------------------------------------------------------------    
      
      /** Sends a reply to the original message */
      public void sendReply(Message replyMessage) throws JMSException {
          getReplyMessenger().send( getReplyToDestination(), replyMessage );
      }
      
      public Messenger getReplyMessenger() {
          return messenger;
      }
      
      public Destination getReplyToDestination() {
          return replyToDestination;
      }
      
      public void setReplyMessenger(Messenger messenger) {
          this.messenger = messenger;
      }
      
      public void setReplyToDestination(Destination replyToDestination) {
          this.replyToDestination = replyToDestination;
      }
      
      
      // Implementation methods
      //-------------------------------------------------------------------------    
      
      public void flushBuffer() throws IOException {
          if ( stream != null ) {
              stream.flush();
          }
      }
      
      public ServletOutputStream getOutputStream() throws IOException {
          if (writer != null) {
              throw new IllegalStateException("getWriter() has already been called " \
+  "for this response");
          }
          if (stream == null) {
              stream = createOutputStream();
          }
          return stream;
      }
      
      public PrintWriter getWriter() throws IOException {
          if (writer != null) {
              return writer;
          }        
          if (stream != null) {
              throw new IllegalStateException("getOutputStream() has already been \
called for this response");  }        
          stream = createOutputStream();
          writer = new PrintWriter(stream);
          return writer;
      }
      
      protected BufferedServletOutputStream createOutputStream() {
          return new BufferedServletOutputStream();
      }
  }
  
  
  
  
  1.1                  \
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/HttpServletRequestImpl.java
  
  Index: HttpServletRequestImpl.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/HttpServletRequestImpl.java,v \
                1.1 2001/10/29 22:32:47 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2001/10/29 22:32:47 $
   *
   * ====================================================================
   *
   * 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.commons.messagelet.impl;
  
  import java.io.BufferedReader;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.IOException;
  import java.io.UnsupportedEncodingException;
  import java.security.Principal;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Date;
  import java.util.Enumeration;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Locale;
  import java.util.Map;
  
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletInputStream;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  
  import org.apache.commons.collections.IteratorEnumeration;
  
  /**
   * Based on the HttpRequestBase code from Catalina.
   *
   * @author Craig R. McClanahan
   * @author James Strachan
   * @version $Revision: 1.1 $ $Date: 2001/10/29 22:32:47 $
   */
  
  public class HttpServletRequestImpl extends ServletRequestImpl implements \
HttpServletRequest {  
  
      /**
       * The authentication type used for this request.
       */
      protected String authType = null;
  
  
      /**
       * The context path for this request.
       */
      protected String contextPath = "";
  
  
      /**
       * The set of cookies associated with this Request.
       */
      protected ArrayList cookies = new ArrayList();
  
  
      /**
       * The set of SimpleDateFormat formats to use in getDateHeader().
       */
      protected SimpleDateFormat formats[] = {
          new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
          new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
          new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
      };
  
  
  
      /**
       * The HTTP headers associated with this Request, keyed by name.  The
       * values are ArrayLists of the corresponding header values.
       */
      protected HashMap headers = new HashMap();
  
  
  
      /**
       * The request method associated with this Request.
       */
      protected String method = null;
  
  
      /**
       * The path information for this request.
       */
      protected String pathInfo = null;
  
  
      /**
       * The query string for this request.
       */
      protected String queryString = null;
  
  
      /**
       * Was the requested session ID received in a cookie?
       */
      protected boolean requestedSessionCookie = false;
  
  
      /**
       * The requested session ID (if any) for this request.
       */
      protected String requestedSessionId = null;
  
  
      /**
       * Was the requested session ID received in a URL?
       */
      protected boolean requestedSessionURL = false;
  
  
      /**
       * The request URI associated with this request.
       */
      protected String requestURI = null;
  
  
      /**
       * The servlet path for this request.
       */
      protected String servletPath = null;
  
  
      /**
       * The currently active session for this request.
       */
      protected HttpSession session = null;
  
  
      /**
       * The Principal who has been authenticated for this Request.
       */
      protected Principal userPrincipal = null;
  
  
  
      // --------------------------------------------------------- Public Methods
  
      public HttpServletRequestImpl(ServletContext servletContext) {
          super( servletContext );
      }
  
  
      /**
       * Add a Cookie to the set of Cookies associated with this Request.
       *
       * @param cookie The new cookie
       */
      public void addCookie(Cookie cookie) {
  
          synchronized (cookies) {
              cookies.add(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) {
  
          name = name.toLowerCase();
          synchronized (headers) {
              ArrayList values = (ArrayList) headers.get(name);
              if (values == null) {
                  values = new ArrayList();
                  headers.put(name, values);
              }
              values.add(value);
          }
  
      }
  
  
      /**
       * Clear the collection of Cookies associated with this Request.
       */
      public void clearCookies() {
  
          synchronized (cookies) {
              cookies.clear();
          }
  
      }
  
  
      /**
       * Clear the collection of Headers associated with this Request.
       */
      public void clearHeaders() {
  
          headers.clear();
  
      }
  
  
  
  
      /**
       * 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 authType The authentication type used
       */
      public void setAuthType(String authType) {
  
          this.authType = authType;
  
      }
  
  
      /**
       * 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) {
  
          if (path == null)
              this.contextPath = "";
          else
              this.contextPath = path;
  
      }
  
  
      /**
       * Set the HTTP request method used for this Request.
       *
       * @param method The request method
       */
      public void setMethod(String method) {
  
          this.method = method;
  
      }
  
  
      /**
       * 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) {
  
          this.pathInfo = path;
  
      }
  
  
      /**
       * 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) {
  
          this.queryString = query;
  
      }
  
  
      /**
       * 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) {
  
          this.requestedSessionCookie = 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) {
  
          this.requestedSessionId = 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) {
  
          this.requestedSessionURL = 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) {
  
          this.requestURI = 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) {
  
          this.servletPath = 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) {
  
          this.userPrincipal = principal;
  
      }
  
  
  
      // --------------------------------------------- HttpServletRequest Methods
  
  
      /**
       * Return the authentication type used for this Request.
       */
      public String getAuthType() {
  
          return (authType);
  
      }
  
  
      /**
       * Return the portion of the request URI used to select the Context
       * of the Request.
       */
      public String getContextPath() {
  
          return (contextPath);
  
      }
  
  
      /**
       * Return the set of Cookies received with this Request.
       */
      public Cookie[] getCookies() {
  
          synchronized (cookies) {
              if (cookies.size() < 1)
                  return (null);
              Cookie results[] = new Cookie[cookies.size()];
              return ((Cookie[]) cookies.toArray(results));
          }
  
      }
  
  
      /**
       * Return the value of the specified date header, if any; otherwise
       * return -1.
       *
       * @param name Name of the requested date header
       *
       * @exception IllegalArgumentException if the specified header value
       *  cannot be converted to a date
       */
      public long getDateHeader(String name) {
  
          String value = getHeader(name);
          if (value == null)
              return (-1L);
  
          // Work around a bug in SimpleDateFormat in pre-JDK1.2b4
          // (Bug Parade bug #4106807)
          value += " ";
  
          // Attempt to convert the date header in a variety of formats
          for (int i = 0; i < formats.length; i++) {
              try {
                  Date date = formats[i].parse(value);
                  return (date.getTime());
              } catch (ParseException e) {
                  ;
              }
          }
          throw new IllegalArgumentException(value);
  
      }
  
  
      /**
       * Return the first value of the specified header, if any; otherwise,
       * return <code>null</code>
       *
       * @param name Name of the requested header
       */
      public String getHeader(String name) {
  
          name = name.toLowerCase();
          synchronized (headers) {
              ArrayList values = (ArrayList) headers.get(name);
              if (values != null)
                  return ((String) values.get(0));
              else
                  return (null);
          }
  
      }
  
  
      /**
       * Return all of the values of the specified header, if any; otherwise,
       * return an empty enumeration.
       *
       * @param name Name of the requested header
       */
      public Enumeration getHeaders(String name) {
  
          name = name.toLowerCase();
          synchronized (headers) {
              ArrayList values = (ArrayList) headers.get(name);
              if (values != null)
                  return (new IteratorEnumeration( values.iterator() ));
              else
                  return (new IteratorEnumeration( Collections.EMPTY_LIST.iterator() \
));  }
  
      }
  
  
      /**
       * Return the names of all headers received with this request.
       */
      public Enumeration getHeaderNames() {
  
          synchronized (headers) {
              return (new IteratorEnumeration( headers.keySet().iterator() ));
          }
  
      }
  
  
      /**
       * Return the value of the specified header as an integer, or -1 if there
       * is no such header for this request.
       *
       * @param name Name of the requested header
       *
       * @exception IllegalArgumentException if the specified header value
       *  cannot be converted to an integer
       */
      public int getIntHeader(String name) {
  
          String value = getHeader(name);
          if (value == null)
              return (-1);
          else
              return (Integer.parseInt(value));
  
      }
  
  
      /**
       * Return the HTTP request method used in this Request.
       */
      public String getMethod() {
  
          return (method);
  
      }
  
  
      /**
       * Return the path information associated with this Request.
       */
      public String getPathInfo() {
  
          return (pathInfo);
  
      }
  
  
      /**
       * Return the extra path information for this request, translated
       * to a real path.
       */
      public String getPathTranslated() {
  
          if (pathInfo == null)
              return (null);
          else
              return (servletContext.getRealPath(pathInfo));
  
      }
  
  
      /**
       * Return the query string associated with this request.
       */
      public String getQueryString() {
  
          return (queryString);
  
      }
  
  
      /**
       * Return the name of the remote user that has been authenticated
       * for this Request.
       */
      public String getRemoteUser() {
  
          if (userPrincipal != null)
              return (userPrincipal.getName());
          else
              return (null);
  
      }
  
  
      /**
       * Return the session identifier included in this request, if any.
       */
      public String getRequestedSessionId() {
  
          return (requestedSessionId);
  
      }
  
  
      /**
       * Return the request URI for this request.
       */
      public String getRequestURI() {
  
          return (requestURI);
  
      }
  
  
      /**
       * Reconstructs the URL the client used to make the request.
       * The returned URL contains a protocol, server name, port
       * number, and server path, but it does not include query
       * string parameters.
       * <p>
       * Because this method returns a <code>StringBuffer</code>,
       * not a <code>String</code>, you can modify the URL easily,
       * for example, to append query parameters.
       * <p>
       * This method is useful for creating redirect messages and
       * for reporting errors.
       *
       * @return A <code>StringBuffer</code> object containing the
       *  reconstructed URL
       */
      public StringBuffer getRequestURL() {
  
          StringBuffer url = new StringBuffer();
          String scheme = getScheme();
          int port = getServerPort();
          if (port < 0)
              port = 80; // Work around java.net.URL bug
  
          url.append(scheme);
          url.append("://");
          url.append(getServerName());
          if ((scheme.equals("http") && (port != 80))
              || (scheme.equals("https") && (port != 443))) {
              url.append(':');
              url.append(port);
          }
          url.append(getRequestURI());
  
          return (url);
  
      }
  
  
      /**
       * Return the portion of the request URI used to select the servlet
       * that will process this request.
       */
      public String getServletPath() {
  
          return (servletPath);
  
      }
  
  
      /**
       * Return the session associated with this Request, creating one
       * if necessary.
       */
      public HttpSession getSession() {
  
          return (getSession(true));
  
      }
  
  
      /**
       * Return the session associated with this Request, creating one
       * if necessary and requested.
       *
       * @param create Create a new session if one does not exist
       */
      public HttpSession getSession(boolean create) {
          return (null);
  
      }
  
  
      /**
       * Return <code>true</code> if the session identifier included in this
       * request came from a cookie.
       */
      public boolean isRequestedSessionIdFromCookie() {
  
          if (requestedSessionId != null)
              return (requestedSessionCookie);
          else
              return (false);
  
      }
  
  
      /**
       * Return <code>true</code> if the session identifier included in this
       * request came from the request URI.
       */
      public boolean isRequestedSessionIdFromURL() {
  
          if (requestedSessionId != null)
              return (requestedSessionURL);
          else
              return (false);
  
      }
  
  
      /**
       * Return <code>true</code> if the session identifier included in this
       * request came from the request URI.
       *
       * @deprecated As of Version 2.1 of the Java Servlet API, use
       *  <code>isRequestedSessionIdFromURL()</code> instead.
       */
      public boolean isRequestedSessionIdFromUrl() {
  
          return (isRequestedSessionIdFromURL());
  
      }
  
  
      /**
       * Return <code>true</code> if the session identifier included in this
       * request identifies a valid session.
       */
      public boolean isRequestedSessionIdValid() {
          return false;
  
      }
  
  
      /**
       * Return <code>true</code> if the authenticated user principal
       * possesses the specified role name.
       *
       * @param role Role name to be validated
       */
      public boolean isUserInRole(String role) {  
          return false;
      }
  
  
      /**
       * Return the principal that has been authenticated for this Request.
       */
      public Principal getUserPrincipal() {
  
          return (userPrincipal);
  
      }
  }
  
  
  
  1.1                  \
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/HttpServletResponseImpl.java
  
  Index: HttpServletResponseImpl.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/HttpServletResponseImpl.java,v \
                1.1 2001/10/29 22:32:47 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2001/10/29 22:32:47 $
   *
   * ====================================================================
   *
   * 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.commons.messagelet.impl;
  
  
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Locale;
  import java.util.TimeZone;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletResponse;
  
  
  /**
   * Based on the HttpRequestBase code from Catalina.
   *
   * @author Craig R. McClanahan
   * @author James Strachan
   * @version $Revision: 1.1 $ $Date: 2001/10/29 22:32:47 $
   */
  
  public class HttpServletResponseImpl extends ServletResponseImpl implements \
HttpServletResponse {  
      /**
       * The set of Cookies associated with this Response.
       */
      protected ArrayList cookies = new ArrayList();
  
  
      /**
       * The date format we will use for creating date headers.
       */
      protected static final SimpleDateFormat format =
          new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz",Locale.US);
      static {
          format.setTimeZone(TimeZone.getTimeZone("GMT"));
      };
  
  
      /**
       * The HTTP headers explicitly added via addHeader(), but not including
       * those to be added with setContentLength(), setContentType(), and so on.
       * This collection is keyed by the header name, and the elements are
       * ArrayLists containing the associated values that have been set.
       */
      protected HashMap headers = new HashMap();
  
  
  
      /**
       * The error message set by <code>sendError()</code>.
       */
      protected String message = getStatusMessage(HttpServletResponse.SC_OK);
  
  
      /**
       * The HTTP status code associated with this Response.
       */
      protected int status = HttpServletResponse.SC_OK;
  
  
      /**
       * The time zone with which to construct date headers.
       */
      protected static final TimeZone zone = TimeZone.getTimeZone("GMT");
  
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Return an array of all cookies set for this response, or
       * a zero-length array if no cookies have been set.
       */
      public Cookie[] getCookies() {
  
          synchronized (cookies) {
              return ((Cookie[]) cookies.toArray(new Cookie[cookies.size()]));
          }
  
      }
  
  
      /**
       * 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) {
  
          ArrayList values = null;
          synchronized (headers) {
              values = (ArrayList) headers.get(name);
          }
          if (values != null)
              return ((String) values.get(0));
          else
              return (null);
  
      }
  
  
      /**
       * 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() {
  
          synchronized (headers) {
              String results[] = new String[headers.size()];
              return ((String[]) headers.keySet().toArray(results));
          }
  
      }
  
  
      /**
       * 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) {
  
          ArrayList values = null;
          synchronized (headers) {
              values = (ArrayList) headers.get(name);
          }
          if (values == null)
              return (new String[0]);
          String results[] = new String[values.size()];
          return ((String[]) values.toArray(results));
  
      }
  
  
      /**
       * Return the error message that was set with <code>sendError()</code>
       * for this Response.
       */
      public String getMessage() {
  
          return (this.message);
  
      }
  
  
      /**
       * Return the HTTP status code associated with this Response.
       */
      public int getStatus() {
  
          return (this.status);
  
      }
  
  
      /**
       * Release all object references, and initialize instance variables, in
       * preparation for reuse of this object.
       */
      public void recycle() {
          //super.recycle();
          cookies.clear();
          headers.clear();
          message = getStatusMessage(HttpServletResponse.SC_OK);
          status = HttpServletResponse.SC_OK;
  
      }
  
  
      /**
       * Reset this response, and specify the values for the HTTP status code
       * and corresponding message.
       *
       * @exception IllegalStateException if this response has already been
       *  committed
       */
      public void reset(int status, String message) {
  
          reset();
          setStatus(status, message);
  
      }
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * Returns a default status message for the specified HTTP status code.
       *
       * @param status The status code for which a message is desired
       */
      protected String getStatusMessage(int status) {
  
          switch (status) {
          case SC_OK:
              return ("OK");
          case SC_ACCEPTED:
              return ("Accepted");
          case SC_BAD_GATEWAY:
              return ("Bad Gateway");
          case SC_BAD_REQUEST:
              return ("Bad Request");
          case SC_CONFLICT:
              return ("Conflict");
          case SC_CONTINUE:
              return ("Continue");
          case SC_CREATED:
              return ("Created");
          case SC_EXPECTATION_FAILED:
              return ("Expectation Failed");
          case SC_FORBIDDEN:
              return ("Forbidden");
          case SC_GATEWAY_TIMEOUT:
              return ("Gateway Timeout");
          case SC_GONE:
              return ("Gone");
          case SC_HTTP_VERSION_NOT_SUPPORTED:
              return ("HTTP Version Not Supported");
          case SC_INTERNAL_SERVER_ERROR:
              return ("Internal Server Error");
          case SC_LENGTH_REQUIRED:
              return ("Length Required");
          case SC_METHOD_NOT_ALLOWED:
              return ("Method Not Allowed");
          case SC_MOVED_PERMANENTLY:
              return ("Moved Permanently");
          case SC_MOVED_TEMPORARILY:
              return ("Moved Temporarily");
          case SC_MULTIPLE_CHOICES:
              return ("Multiple Choices");
          case SC_NO_CONTENT:
              return ("No Content");
          case SC_NON_AUTHORITATIVE_INFORMATION:
              return ("Non-Authoritative Information");
          case SC_NOT_ACCEPTABLE:
              return ("Not Acceptable");
          case SC_NOT_FOUND:
              return ("Not Found");
          case SC_NOT_IMPLEMENTED:
              return ("Not Implemented");
          case SC_NOT_MODIFIED:
              return ("Not Modified");
          case SC_PARTIAL_CONTENT:
              return ("Partial Content");
          case SC_PAYMENT_REQUIRED:
              return ("Payment Required");
          case SC_PRECONDITION_FAILED:
              return ("Precondition Failed");
          case SC_PROXY_AUTHENTICATION_REQUIRED:
              return ("Proxy Authentication Required");
          case SC_REQUEST_ENTITY_TOO_LARGE:
              return ("Request Entity Too Large");
          case SC_REQUEST_TIMEOUT:
              return ("Request Timeout");
          case SC_REQUEST_URI_TOO_LONG:
              return ("Request URI Too Long");
          case SC_REQUESTED_RANGE_NOT_SATISFIABLE:
              return ("Requested Range Not Satisfiable");
          case SC_RESET_CONTENT:
              return ("Reset Content");
          case SC_SEE_OTHER:
              return ("See Other");
          case SC_SERVICE_UNAVAILABLE:
              return ("Service Unavailable");
          case SC_SWITCHING_PROTOCOLS:
              return ("Switching Protocols");
          case SC_UNAUTHORIZED:
              return ("Unauthorized");
          case SC_UNSUPPORTED_MEDIA_TYPE:
              return ("Unsupported Media Type");
          case SC_USE_PROXY:
              return ("Use Proxy");
          case 207:       // WebDAV
              return ("Multi-Status");
          case 422:       // WebDAV
              return ("Unprocessable Entity");
          case 423:       // WebDAV
              return ("Locked");
          case 507:       // WebDAV
              return ("Insufficient Storage");
          default:
              return ("HTTP Response Status " + status);
          }
  
      }
  
  
  
      // ------------------------------------------------ ServletResponse Methods
  
  
      /**
       * Flush the buffer and commit this response.  If this is the first output,
       * send the HTTP headers prior to the user data.
       *
       * @exception IOException if an input/output error occurs
       */
      public void flushBuffer() throws IOException {
  /*
          if (!isCommitted()) {
              sendHeaders();
          }
  */
          super.flushBuffer();
  
      }
  
  
      /**
       * Clear any content written to the buffer.  In addition, all cookies
       * and headers are cleared, and the status is reset.
       *
       * @exception IllegalStateException if this response has already
       *  been committed
       */
      public void reset() {
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          super.reset();
          cookies.clear();
          headers.clear();
          message = null;
          status = HttpServletResponse.SC_OK;
  
      }
  
  
      /**
       * Set the content length (in bytes) for this Response.
       *
       * @param length The new content length
       */
      public void setContentLength(int length) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          super.setContentLength(length);
  
      }
  
  
  
      /**
       * Set the content type for this Response.
       *
       * @param type The new content type
       */
      public void setContentType(String type) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          super.setContentType(type);
  
      }
  
  
      /**
       * Set the Locale that is appropriate for this response, including
       * setting the appropriate character encoding.
       *
       * @param locale The new locale
       */
      public void setLocale(Locale locale) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          super.setLocale(locale);
          String language = locale.getLanguage();
          if ((language != null) && (language.length() > 0)) {
              String country = locale.getCountry();
              StringBuffer value = new StringBuffer(language);
              if ((country != null) && (country.length() > 0)) {
                  value.append('-');
                  value.append(country);
              }
              setHeader("Content-Language", value.toString());
          }
  
      }
  
  
      // -------------------------------------------- HttpServletResponse Methods
  
  
      /**
       * Add the specified Cookie to those that will be included with
       * this Response.
       *
       * @param cookie Cookie to be added
       */
      public void addCookie(Cookie cookie) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          synchronized (cookies) {
              cookies.add(cookie);
          }
  
      }
  
  
      /**
       * Add the specified date header to the specified value.
       *
       * @param name Name of the header to set
       * @param value Date value to be set
       */
      public void addDateHeader(String name, long value) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          addHeader(name, format.format(new Date(value)));
  
      }
  
  
      /**
       * Add the specified header to the specified value.
       *
       * @param name Name of the header to set
       * @param value Value to be set
       */
      public void addHeader(String name, String value) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          synchronized (headers) {
              ArrayList values = (ArrayList) headers.get(name);
              if (values == null) {
                  values = new ArrayList();
                  headers.put(name, values);
              }
              values.add(value);
          }
  
      }
  
  
      /**
       * Add the specified integer header to the specified value.
       *
       * @param name Name of the header to set
       * @param value Integer value to be set
       */
      public void addIntHeader(String name, int value) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          addHeader(name, "" + value);
  
      }
  
  
      /**
       * Has the specified header been set already in this response?
       *
       * @param name Name of the header to check
       */
      public boolean containsHeader(String name) {
  
          synchronized (headers) {
              return (headers.get(name) != null);
          }
  
      }
  
  
      /**
       * Encode the session identifier associated with this response
       * into the specified redirect URL, if necessary.
       *
       * @param url URL to be encoded
       */
      public String encodeRedirectURL(String url) {
  
          return (url);
  
      }
  
  
      /**
       * Encode the session identifier associated with this response
       * into the specified redirect URL, if necessary.
       *
       * @param url URL to be encoded
       *
       * @deprecated As of Version 2.1 of the Java Servlet API, use
       *  <code>encodeRedirectURL()</code> instead.
       */
      public String encodeRedirectUrl(String url) {
  
          return (encodeRedirectURL(url));
  
      }
  
  
      /**
       * Encode the session identifier associated with this response
       * into the specified URL, if necessary.
       *
       * @param url URL to be encoded
       */
      public String encodeURL(String url) {
          
          return (url);
      }
  
  
      /**
       * Encode the session identifier associated with this response
       * into the specified URL, if necessary.
       *
       * @param url URL to be encoded
       *
       * @deprecated As of Version 2.1 of the Java Servlet API, use
       *  <code>encodeURL()</code> instead.
       */
      public String encodeUrl(String url) {
  
          return (encodeURL(url));
  
      }
  
  
      /**
       * Send an error response with the specified status and a
       * default message.
       *
       * @param status HTTP status code to send
       *
       * @exception IllegalStateException if this response has
       *  already been committed
       * @exception IOException if an input/output error occurs
       */
      public void sendError(int status) throws IOException {
  
          sendError(status, getStatusMessage(status));
  
      }
  
  
      /**
       * Send an error response with the specified status and message.
       *
       * @param status HTTP status code to send
       * @param message Corresponding message to send
       *
       * @exception IllegalStateException if this response has
       *  already been committed
       * @exception IOException if an input/output error occurs
       */
      public void sendError(int status, String message) throws IOException {
  
          if (isCommitted()) {
              throw new IllegalStateException( "Cannot send error, already committed" \
);  }
  
          if (included) {
              return;     // Ignore any call from an included servlet
          }
  
          //setError();
  
          // Record the status code and message.
          this.status = status;
          this.message = message;
  
          // Clear any data content that has been buffered
          resetBuffer();
  
          // Cause the response to be committed
          /* Per spec clarification, no default content type is set
          String contentType = getContentType();
          if ((contentType == null) || "text/plain".equals(contentType))
              setContentType("text/html");
          */
  
          // Temporarily comment out the following flush so that
          // default error reports can still set the content type
          // FIXME - this stuff needs to be refactored
          /*
          try {
              flushBuffer();
          } catch (IOException e) {
              ;
          }
          */
  
      }
  
  
      /**
       * Send a temporary redirect to the specified redirect location URL.
       *
       * @param location Location URL to redirect to
       *
       * @exception IllegalStateException if this response has
       *  already been committed
       * @exception IOException if an input/output error occurs
       */
      public void sendRedirect(String location) throws IOException {
  
          if (isCommitted()) {
              throw new IllegalStateException( "Cannot send error, already committed" \
);  }
          if (included)
              return;     // Ignore any call from an included servlet
  
          // Clear any data content that has been buffered
          resetBuffer();
  
          // Generate a temporary redirect to the specified location
          //String absolute = toAbsolute(location);
          String absolute = location;
          setStatus(SC_MOVED_TEMPORARILY);
          setHeader("Location", absolute);
  
      }
  
  
      /**
       * Set the specified date header to the specified value.
       *
       * @param name Name of the header to set
       * @param value Date value to be set
       */
      public void setDateHeader(String name, long value) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          setHeader(name, format.format(new Date(value)));
  
      }
  
  
      /**
       * Set the specified header to the specified value.
       *
       * @param name Name of the header to set
       * @param value Value to be set
       */
      public void setHeader(String name, String value) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          ArrayList values = new ArrayList();
          values.add(value);
          synchronized (headers) {
              headers.put(name, values);
          }
  
          String match = name.toLowerCase();
          if (match.equals("content-length")) {
              int contentLength = -1;
              try {
                  contentLength = Integer.parseInt(value);
              } catch (NumberFormatException e) {
                  ;
              }
              if (contentLength >= 0)
                  setContentLength(contentLength);
          } else if (match.equals("content-type")) {
              setContentType(value);
          }
  
      }
  
  
      /**
       * Set the specified integer header to the specified value.
       *
       * @param name Name of the header to set
       * @param value Integer value to be set
       */
      public void setIntHeader(String name, int value) {
  
          if (isCommitted())
              return;
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          setHeader(name, "" + value);
  
      }
  
  
      /**
       * Set the HTTP status to be returned with this response.
       *
       * @param status The new HTTP status
       */
      public void setStatus(int status) {
  
          setStatus(status, getStatusMessage(status));
  
      }
  
  
      /**
       * Set the HTTP status and message to be returned with this response.
       *
       * @param status The new HTTP status
       * @param message The associated text message
       *
       * @deprecated As of Version 2.1 of the Java Servlet API, this method
       *  has been deprecated due to the ambiguous meaning of the message
       *  parameter.
       */
      public void setStatus(int status, String message) {
  
          if (included)
              return;     // Ignore any call from an included servlet
  
          this.status = status;
          this.message = message;
  
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic