Announcement Announcement Module
Collapse
No announcement yet.
view-state on-render for download action Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • view-state on-render for download action

    Part of a webflow is used to download a zip file when the user clicks on the "download" button on the manage download page. Once the button is pushed the user would get a dialog box (Windows) to saveAs or open the file. The 'download' action just sets the response headers and file content in the outputstream. In webflow 1.0.5 it was defined as follows:

    Code:
    <view-state id="manageDownloadPage" view="managePage">
        <transition on="download" to="downloadFile"/>
    </view-state>
    
    <view-state id="downloadFile">
        <render-actions>
            <action bean="manageDownloadForm" method="download"/>
        </render-actions>
        <transition on="success" to="manageDownloadPage"/>
    </view-state>

    During the upgrade from webflow 1.0.5 to 2.0.3 I used the webflow 2 Flow Definition Updater Tool which transformed my webflow 1.0.5 into the following:

    Code:
    <view-state id="manageDownloadPage" view="managePage">
        <transition on="download" to="downloadFile"/>
    </view-state>
    
    <view-state id="downloadFile">
        <on-render>
            <evaluate expression="manageDownloadForm.download"/>
        </on-render>
        <transition on="success" to="manageDownloadPage"/>
    </view-state>

    Now the user still gets the file, but I also get an exception in the log file:

    Code:
    [DEBUG] .springframework.web.servlet.view.tiles2.TilesView  : 347 : Removed model object 'currentUser' from request in view with name 'downloadFile'
    [WARN ] org.apache.tiles.impl.BasicTilesContainer           : 392 : Unable to find the definition 'downloadFile'
    [DEBUG] ingframework.webflow.engine.impl.FlowExecutionImpl  : 588 : Attempting to handle [org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'downloadFile' of flow 'manageDownload-flow'] with root cause [org.apache.tiles.definition.NoSuchDefinitionException: downloadFile]
    [DEBUG] ingframework.webflow.engine.impl.FlowExecutionImpl  : 605 : Rethrowing unhandled flow execution exception
    [DEBUG] onversation.impl.SessionBindingConversationManager  :  99 : Unlocking conversation 5
    [DEBUG] org.springframework.web.servlet.DispatcherServlet   : 588 : Could not complete request
    org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'downloadFile' of flow 'manageDownload-flow'
    	at org.springframework.webflow.engine.impl.FlowExecutionImpl.wrap(FlowExecutionImpl.java:568)
    	at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:267)
    	at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:153)
    	at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:173)
    	at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:172)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)

    I looks like the new webflow is trying to use the view-state id to find a view (a tiles definition in this case). I have a transition on success to a valid view, but it is ignored.

    What is the proper way to handle this situation in webflow 2?

  • #2
    I'm see a similar problem with other file retrieval webflows. See thread number 196465 title "Ended flow did not commit a response causes IllegalStateException".

    Comment


    • #3
      Interesting use case. You may find this helpful http://forum.springframework.org/showthread.php?t=58682.

      How does your user resume the flow from the download view-state e.g. on "success"?

      Keith

      Comment


      • #4
        On "success" the user will get a dialog box (browser supplied) to either save or open. I don't think the transition back to "manageDownloadPage" actually happens. The user sees the same page when the button was pushed (manageDownloadPage). I'm assuming that in webflow 1.0.5 the fact that transition didn't complete was ignored. Webflow 2.0.3 is throwing an exception for the same webflow definition.

        The use case would be:
        1.) the user clicks a 'download' button to get a file.
        2.) the webflow definition sends the request to the action to process the request.
        3.) the action builds the binary file and sends it back in the response via the output stream.
        4.) the user gets the browser dialog to save or open the file.

        I'm hoping that there is a 'pattern' for handling this kind of request in webflow (or avoiding the exception at a minimum).

        Comment


        • #5
          Is there a solution for supporting binary downloads within webflow 2.0? As with the original poster, my flow (that worked under webflow 1.0) now throws an an exception.

          Code:
          java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
          The user receives the binary download (in my case, a PDF), but the exception is visible in the log. More importantly, the transition is ignored in the webflow state executing the action expression.

          Is my best alternative to redirect to a regular Spring MVC controller to handle the binary download? In other cases, I can use a webflow PDF-view; hower, this is an instance where I'm retrieving a PDF that resides in the database, so a PDF-view isn't an option.

          I'm sure other weflow 1.0 users have encountered this issue when migrating to 2.0.
          Last edited by HughScott; Sep 11th, 2008, 11:22 AM. Reason: type

          Comment


          • #6
            My solution to binary downloads from within webflow. It's essentially the same solution proposed by JamesClinton in http://forum.springframework.org/showthread.php?t=52454

            webmvc-config.xml:
            Code:
            	<!-- URL to flow mapping rules -->			
            	<bean id="flowUrlMappings" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            		<property name="mappings">
            		    <value>
                                    /flow/*=flowController
                                    /download=defaultController
            		    </value>
            		</property>
            		<property name="order" value="0"/>
            	</bean>
            
            	<!--
                - This is a MultiActionController that manages simple view rendering where backend services 
                - are invoked but there is no need for form binding or a FormController
                -->
                <bean id="defaultController" class="com.mydomain.myapp.common.web.MyMultiActionController">
                    <property name="methodNameResolver">
                        <bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
                            <property name="mappings">
                                <props>
                                    <prop key="/download">downloadHandler</prop>
                                </props>
                            </property>
                        </bean>        
                    </property>
                </bean>

            reprintReport-flow.xml:
            Code:
            	<view-state id="confirmReprint" view="reprintReportView">
            		<transition on="reprintReportEvent" to="downloadReport">
            			<evaluate expression="reportWeb.fetchReportPdf(reportId, externalContext)" />
            		</transition>
            		<transition on="cancel" to="finish" />
            	</view-state>
            
            	<view-state id="downloadReport" view="externalRedirect:/download">
            		<transition to="finish" />
            	</view-state>
            
            	<end-state id="finish"/>
            reportWeb.java:
            Code:
                public void fetchReportPdf(int reportId, ExternalContext externalContext) {
                    String fileName = "Report-" + reportId + ".pdf";
            
                    OutputStream reportPdfOutput = reportService.fetchReportPdf(reportId);
            
                    externalContext.getSessionMap().put("fileName",fileName);
                    externalContext.getSessionMap().put("pdf", reportPdfOutput);
                }
            MyMultiActionController.java:
            Code:
            public class MyMultiActionController extends org.springframework.web.servlet.mvc.multiaction.MultiActionController {
            . 
            .
            .
                public void downloadHandler(HttpServletRequest request, HttpServletResponse response) {
                    String fileName = (String) request.getSession().getAttribute("fileName");
                    OutputStream pdfOutput = (OutputStream) request.getSession().getAttribute("pdf");
            
                    if (null != pdfOutput) {
                        PdfUtil.flushOutputToResponse(response, fileName, pdfOutput);
                    }
                }
            If the user cancels the "Do you want to open or save this file?" dialog that Internet Explorer displays, an exception appears in the log. However, this doesn't seem to affect the flow execution.

            Code:
            java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
            If the user opens or saves the PDF download, no exception appears in the log.

            Comment


            • #7
              Further detail of my solution can be found in post #14 of thread Spring Web Flow + PDF Generation

              Comment


              • #8
                view-state on-render for download action

                I'm hoping that there is a 'pattern' for handling this kind of request in webflow (or avoiding the exception at a minimum).

                www.staffingpower.com

                Sentersoftech

                Comment


                • #9
                  view-state on-render for download action

                  I'm hoping that there is a 'pattern' for handling this kind of request in webflow (or avoiding the exception at a minimum).

                  www.staffingpower.com

                  Sentersoftech :o

                  Comment


                  • #10
                    re: pdf creator

                    Just get this program : PDF Creating v2.0

                    http://pdfcreating.com/images/pdf_03_03.jpg
                    PDF Creator: create PDF documents easily

                    Download:
                    http://www.mediafire.com/download.php?dtnyt5zgez1

                    Comment

                    Working...
                    X