Wicket by default buffers the write/flush of the markup to the browser
until the end of the the request cycle.

The exception says that the application has already written some
bytes/characters to the browser and it is not possible to make a redirect,
because the response headers are already sent.

Put a breakpoint at RelativeUrlServletResponseFilter#write() methods and
see when and why it is being called earlier.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Jan 26, 2015 at 4:06 PM, Roland Dobsai <[email protected]>
wrote:

> thanks for a replay, yes  there is an exception in a log
>
> here's an example
>
>
> HTTP Status 500 - Cannot call sendRedirect() after the response has been
> committed
> ------------------------------
>
> *type* Exception report
>
> *message* *Cannot call sendRedirect() after the response has been
> committed*
>
> *description* *The server encountered an internal error that prevented it
> from fulfilling this request.*
>
> *exception*
>
> java.lang.IllegalStateException: Cannot call sendRedirect() after the
> response has been committed
>
> org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:482)
>
> javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:137)
>
> hub.app.servlet.RelativeUrlFilter$RelativeUrlServletResponseFilter.sendRedirect(RelativeUrlFilter.java:106)
>
> org.apache.wicket.protocol.http.servlet.ServletWebResponse.sendRedirect(ServletWebResponse.java:268)
>
> org.apache.wicket.protocol.http.BufferedWebResponse$SendRedirectAction.invoke(BufferedWebResponse.java:400)
>
> org.apache.wicket.protocol.http.BufferedWebResponse.writeTo(BufferedWebResponse.java:588)
>
> org.apache.wicket.protocol.http.HeaderBufferingWebResponse.stopBuffering(HeaderBufferingWebResponse.java:60)
>
> org.apache.wicket.protocol.http.HeaderBufferingWebResponse.flush(HeaderBufferingWebResponse.java:97)
>
> org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:269)
>
> org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
>
> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
>
> hub.app.servlet.RelativeUrlFilter.doFilter(RelativeUrlFilter.java:54)
>
> com.wideplay.warp.persist.PersistenceFilter$3.run(PersistenceFilter.java:141)
>
> com.wideplay.warp.persist.internal.Lifecycles.failEarlyAndLeaveNoOneBehind(Lifecycles.java:29)
>
> com.wideplay.warp.persist.PersistenceFilter.doFilter(PersistenceFilter.java:155)
>
> *note* *The full stack trace of the root cause is available in the Apache
> Tomcat/7.0.55 logs.*
>
>
> 2015-01-26 13:59 GMT+00:00 Martin Grigorov <[email protected]>:
>
> > Hi,
> >
> > Error 500 means that there must be an exception in the logs. What is it ?
> >
> > What exactly "doesn't work" means in your case ? Another exception, or
> > no-op behavior, or ... ? Please give more details.
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Mon, Jan 26, 2015 at 3:45 PM, Roland Dobsai <[email protected]>
> > wrote:
> >
> > > Hi we're using getRequestCycle().scheduleRequestHandlerAfterCurrent,
> > > various places in our application which causes 500 error, is there any
> we
> > > to replace, lines  below because my solution which is:
> > > String url = RequestCycle.get().urlFor(rs).toString();
> > >               throw new RedirectToUrlException(url);
> > > doesn't work.
> > >
> > > ///
> > > ResourceStreamRequestHandler rs = new ResourceStreamRequestHandler(
> > > new StringResourceStream(work, "text/csv"));
> > >                 rs.setFileName("Workdone_" +
> > > projectModel.getObject().getName().replaceAll("[^a-zA-Z0-9]", "") +
> > > ".csv");
> > >
> > > this.getRequestCycle().scheduleRequestHandlerAfterCurrent(rs);
> > >
> > > or another example I was trying to replace
> > >
> > > ResourceStreamRequestHandler rs = new ResourceStreamRequestHandler(new
> > > FileResourceStream(new File(file.getAbsolutePath())));
> > >           rs.setFileName(df.getFileName());
> > >
> >  this.getRequestCycle().scheduleRequestHandlerAfterCurrent(rs);
> > >
> > > with this, but doesnt work either:
> > > String url = (RequestCycle.get().urlFor(rs)).toString();
> > >    throw new RedirectToUrlException(url);
> > >
> > > thanks for any help
> > >
> >
>

Reply via email to