Hi James,

You are correct if your Layout is set to VelocityECSLayout (which is now
deprecated). However, I found that on switching to VelocityOnlyLayout,
even though data.declareDirectResponse() is called, the exception
occurred. 

Have you found differently with VelocityOnlyLayout?

I have fixed the problem by creating the following class and calling 

data.setLayout("DirectResponseLayout");

in my Action method.

(Note that RunData.isOutSet() is deprecated!!!)


package com.whatever.modules.layouts;

// Turbine Classes
import org.apache.turbine.modules.Layout;
import org.apache.turbine.util.RunData;

/**
 * This layout allows an action to manipulate the 
 * ServletOutputStream directly. It requires that
 * data.declareDirectResponse() has been called to
 * indicate that the OutputStream is being
 * handled else an Exception is thrown
 *
 * @author <a href="mailto:[EMAIL PROTECTED]">Peter Courcoux</a>
 */
public class DirectResponseLayout extends Layout
{
    /**
     * Method called by LayoutLoader.
     *
     * @param RunData
     */
    public void doBuild( RunData data ) throws Exception
    {
        if (!data.isOutSet())
            {
                throw new Exception(
                    "data.declareDirectResponse() has not been called");
            }
    }
}



On Wed, 2003-03-19 at 16:37, James Cooper wrote:
> Hi Peter,
> I came across the exact same problem myself, the OutputStream seems to be
> called twice and the Servlet container (I use Tomcat) throws a
> IllegalStateException. The problem is fixed simply by invoking the
> declareDirectResponse method.
> 
> <snip>
> aData.declareDirectResponse();
> 
> HttpServletResponse lRes = aData.getResponse();
> 
> // Setting content type and headers
> lRes.setContentType(aContentType);
> lRes.setContentLength(aWriter.toString().length());
> lRes.setHeader("Content-type", aContentType);
> lRes.setHeader("Content-Disposition", "attachment;filename = " + aFileName);
> 
> // Get the output stream from the response object
> OutputStream lOut = lRes.getOutputStream();
> 
> // Using the output stream, push the contents contained within the
> StringWriter to the
> // user
> lOut.write(aWriter.toString().getBytes());
> lRes.flushBuffer();
> </snip>
> 
> 
> -----Original Message-----
> From: Henning P. Schmiedehausen [mailto:[EMAIL PROTECTED]
> Sent: 19 March 2003 14:12
> To: [EMAIL PROTECTED]
> Subject: Re: Direct Response and IllegalStateException
> 
> 
> Peter Courcoux <[EMAIL PROTECTED]> writes:
> 
> >Hi all,
> 
> >I have recently changed from using turbine 2.2-b3 to 2.2.1 and from
> >using VelocityECSLayout to VelocityOnlyLayout.
> 
> Actually, I'm getting more and more unhappy with the deprecation of
> VelocityECSLayout. There seem to be many quirks that can't be fixed
> in a clean manner. We might have to think about this a little more.
> 
> >One of my actions which extends VelocitySecureAction handles a file
> >download by obtaining the HttpServletResponse setting the headers and
> >then obtaining and writing directly to the ServletOutputStream.
> 
> >Before the changes outlined above this caused no problem. Having made
> >the changes the following Exception occurs after the completion of the
> >download and closing the ServletOutputStream.
> 
> Could you please post some code snippets. How do you do the file
> download? Directly from the action (you shouldn't do that) or do you
> have a screen which does the download to which you redirect? I'm
> getting a little scared by reading that you try to manipulate the
> Servlet output stream by yourself. :-)
> 
>       Regards
>               Henning
> 
> --
> Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
> [EMAIL PROTECTED]        +49 9131 50 654 0   http://www.intermeta.de/
> 
> Java, perl, Solaris, Linux, xSP Consulting, Web Services
> freelance consultant -- Jakarta Turbine Development  -- hero for hire
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

Regards,

Peter

-- 
Peter Courcoux <[EMAIL PROTECTED]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to