[ 
https://issues.apache.org/jira/browse/WICKET-4433?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13218037#comment-13218037
 ] 

Martin Grigorov commented on WICKET-4433:
-----------------------------------------

Yes, it seems onBeginRequest() is not covered to handle reset handler 
exceptions ..
Here is a working code that does the same as what the exception would do:

       public void onBeginRequest(RequestCycle cycle) {
                IPageProvider provider = new PageProvider(PageTwo.class);
                RenderPageRequestHandler requestHandler = new 
RenderPageRequestHandler(provider) {
                        @Override
                        public void respond(IRequestCycle requestCycle)
                        {
                                requestCycle.getResponse().reset();
                                super.respond(requestCycle);
                        }
                };

                cycle.scheduleRequestHandlerAfterCurrent(requestHandler);
        }

I'm not sure whether onBeginRequest() should be improved.
                
> Exception (Header was already written to response!) when setting response 
> page in IRequestCycleListener
> -------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-4433
>                 URL: https://issues.apache.org/jira/browse/WICKET-4433
>             Project: Wicket
>          Issue Type: Bug
>    Affects Versions: 1.5.4
>            Reporter: Neil Curzon
>         Attachments: myproject.zip, myproject.zip
>
>
> We have an IRequestCycleListener implementation that's basically:
>       @Override
>       public void onBeginRequest(RequestCycle cycle) {
>               if (<condition>)) {
>                       cycle.setResponsePage(SpecificPage.class);
>               }
>       }
> This results in an exception when the condition is true, and the response 
> page is set:
> java.lang.IllegalStateException: Header was already written to response!
>       at 
> org.apache.wicket.protocol.http.HeaderBufferingWebResponse.checkHeader(HeaderBufferingWebResponse.java:64)
>       at 
> org.apache.wicket.protocol.http.HeaderBufferingWebResponse.setDateHeader(HeaderBufferingWebResponse.java:134)
>       at 
> org.apache.wicket.protocol.http.BufferedWebResponse$SetDateHeaderAction.invoke(BufferedWebResponse.java:310)
>       at 
> org.apache.wicket.protocol.http.BufferedWebResponse.writeTo(BufferedWebResponse.java:580)
>       at 
> org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:185)
>       at 
> org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167)
>       at 
> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781)
>       at 
> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
>       at 
> org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:304)
>       at 
> org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:313)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to