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

Jan Riehn commented on WICKET-4433:
-----------------------------------

Hello,

Martins solution does not really fix the problem. The first request is 
scheduled and executed, might be that the RestartResponseException should avoid 
this. 
The following snippet fits better:

public class MyRequestCycleListener extends AbstractRequestCycleListener {
    @Override
    public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler 
handler) {
        if (handler instanceof IPageRequestHandler) {          
            if (condition) {
                throw new RedirectToUrlException("http://wicket.apache.org/";);
            }
       }
   }
}

Best regards,

Jan

                
> 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
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to