portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn Golden <ggol...@umich.edu>
Subject FW: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/mod ules/pages DefaultPage.java
Date Fri, 29 Mar 2002 02:17:42 GMT
Way Cool! Our patch is in!

Now, we have to:

A) update the version of turbine we are using in Jetspeed

B) apply the other patch I made and posted to this list that changes all our
redirect attempts to do things the new, turbine supported way.

We need to do these together, else things will be broken - but then, they
are broken now.

I've attached that patch again here.

- Glenn

-----Original Message-----
From: jmcnally@apache.org [mailto:jmcnally@apache.org] 
Sent: Thursday, March 28, 2002 9:00 PM
To: jakarta-turbine-2-cvs@apache.org
Subject: cvs commit:
jakarta-turbine-2/src/java/org/apache/turbine/modules/pages DefaultPage.java


jmcnally    02/03/28 18:00:02

  Modified:    .        build.xml
               src/java/org/apache/turbine Turbine.java
               src/java/org/apache/turbine/modules/pages DefaultPage.java
  Log:
  patch by  Glenn Golden <ggolden@umich.edu>
  
  To follow the Servlet HTTP rules, we must do the redirect before
committing
  any headers or body to the response, and once we do a redirect we must not
  do anything else with the response.
  
  Revision  Changes    Path
  1.11      +1 -0      jakarta-turbine-2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/build.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- build.xml	13 Mar 2002 04:45:00 -0000	1.10
  +++ build.xml	29 Mar 2002 02:00:02 -0000	1.11
  @@ -241,6 +241,7 @@
               depends="prepare, prepare-jsp, prepare-freemarker,
prepare-python,
                        prepare-webmacro, prepare-log4java, prepare-castor"
               description="--> compiles the source code">
  +
           <javac srcdir="${build.src}"
               destdir="${build.dest}"
               excludes="**/package.html,**/*Test.java"
  
  
  
  1.12      +61 -42
jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java
  
  Index: Turbine.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Turbine.java	13 Mar 2002 19:44:19 -0000	1.11
  +++ Turbine.java	29 Mar 2002 02:00:02 -0000	1.12
  @@ -117,7 +117,7 @@
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
    * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  - * @version $Id: Turbine.java,v 1.11 2002/03/13 19:44:19 mpoeschl Exp $
  + * @version $Id: Turbine.java,v 1.12 2002/03/29 02:00:02 jmcnally Exp $
    */
   public class Turbine
       extends HttpServlet
  @@ -376,6 +376,9 @@
           throws IOException,
                  ServletException
       {
  +        // set to true if the request is to be redirected by the page
  +        boolean requestRedirected = false;
  +
           // Placeholder for the RunData object.
           RunData data = null;
           try
  @@ -584,46 +587,57 @@
                       AccessControlList.SESSION_KEY);
               }
   
  -            try
  +            // handle a redirect request
  +            requestRedirected = ((data.getRedirectURI() != null) 
  +                && (data.getRedirectURI().length() > 0));
  +            if (requestRedirected)
               {
  -                if ( data.isPageSet() == false &&
  -                     data.isOutSet() == false )
  -                    throw new Exception ( "Nothing to output" );
  -
  -                // We are all done! if isPageSet() output that way
  -                // otherwise, data.getOut() has already been written
  -                // to the data.getOut().close() happens below in the
  -                // finally.
  -                if ( data.isPageSet() && data.isOutSet() == false )
  -                {
  -                    // Modules can override these.
  -                    data.getResponse()
  -                        .setLocale( data.getLocale() );
  -                    data.getResponse()
  -                        .setContentType( data.getContentType() );
  -
  -                    // Handle the case where a module may want to send
  -                    // a redirect.
  -                    if ( ( data.getStatusCode() == 301 ||
  -                           data.getStatusCode() ==  302 ) &&
  -                         data.getRedirectURI() != null )
  +                if (data.getResponse().isCommitted())
  +                {
  +                    requestRedirected = false;
  +                    log ("redirect requested, response already committed:
" + 
  +                         data.getRedirectURI());
  +                }
  +                else
  +                {
  +
data.getResponse().sendRedirect(data.getRedirectURI());
  +                }
  +            }
  +
  +            if (!requestRedirected)
  +            {
  +                try
  +                {
  +                    if ( data.isPageSet() == false &&
  +                        data.isOutSet() == false )
  +                        throw new Exception ( "Nothing to output" );
  +
  +                    // We are all done! if isPageSet() output that way
  +                    // otherwise, data.getOut() has already been written
  +                    // to the data.getOut().close() happens below in the
  +                    // finally.
  +                    if ( data.isPageSet() && data.isOutSet() == false )
                       {
  +                        // Modules can override these.
                           data.getResponse()
  -                            .sendRedirect ( data.getRedirectURI() );
  -                    }
  +                            .setLocale( data.getLocale() );
  +                        data.getResponse()
  +                            .setContentType( data.getContentType() );
   
  -                    // Set the status code.
  -                    data.getResponse().setStatus ( data.getStatusCode()
);
  -                    // Output the Page.
  -                    data.getPage().output (data.getOut());
  +                        // Set the status code.
  +                        data.getResponse().setStatus (
data.getStatusCode() );
  +                        // Output the Page.
  +                        data.getPage().output (data.getOut());
  +                    }
  +                }
  +                catch ( Exception e )
  +                {
  +                    // The output stream was probably closed by the
client
  +                    // end of things ie: the client clicked the Stop
  +                    // button on the browser, so ignore any errors that
  +                    // result.
  +                    Log.debug("Output stream closed? ", e);
                   }
  -            }
  -            catch ( Exception e )
  -            {
  -                // The output stream was probably closed by the client
  -                // end of things ie: the client clicked the Stop
  -                // button on the browser, so ignore any errors that
  -                // result.
               }
           }
           catch ( Exception e )
  @@ -637,13 +651,18 @@
           finally
           {
               // Make sure to close the outputstream when we are done.
  -            try
  +            // Note: not for redirects, when we must not get a
printwriter on 
  +            // the response output stream.
  +            if (!requestRedirected)
               {
  -                data.getOut().close();
  -            }
  -            catch (Exception e)
  -            {
  -                // Ignore.
  +                try
  +                {
  +                    data.getOut().close();
  +                }
  +                catch (Exception e)
  +                {
  +                    // Ignore.
  +                }
               }
   
               // Return the used RunData to the factory for recycling.
  
  
  
  1.2       +4 -1
jakarta-turbine-2/src/java/org/apache/turbine/modules/pages/DefaultPage.java
  
  Index: DefaultPage.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/pages/Defaul
tPage.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultPage.java	16 Aug 2001 05:08:36 -0000	1.1
  +++ DefaultPage.java	29 Mar 2002 02:00:02 -0000	1.2
  @@ -119,7 +119,7 @@
    * written by John McNally.  I've only modified it for WebMacro use.
    *
    * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
  - * @version $Id: DefaultPage.java,v 1.1 2001/08/16 05:08:36 jvanzyl Exp $
  + * @version $Id: DefaultPage.java,v 1.2 2002/03/29 02:00:02 jmcnally Exp
$
    */
   public class DefaultPage extends Page
   {
  @@ -142,6 +142,9 @@
           {
               ActionLoader.getInstance().exec ( data, data.getAction() );
           }
  +
  +        // if a redirect was setup in data, don't do anything else
  +        if ((data.getRedirectURI() != null) &&
(data.getRedirectURI().length() > 0)) return;
   
           // Set the default doctype from the value given in
           // TurbineResources.properties.
  
  
  

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


Mime
View raw message