This seems like a pretty clear-cut "bug" in the Servlet filter architecture. The fact that one is unable to redirect a request once response headers are commited (albeit not actually sent) is a silly limitation.

I don't think commiting headers after Wicket operations is appropriate either. There should be a safe way to commit headers within the Filter before the Wicket operation, then if Wicket chooses to redirect, the headers get discarded.

Anyway, it's too late for me to think straight (I've had a very long day) but this is something we should look into in the future.

I don't know that IRedirectListener would work (before like you said, it would allow setting of headers *after* processing, not before). The only workaround I can think of is to store the headers ourselves in the Wicket layer and only commit them to the Servlet API if a redirect does not occur. In other words, emulate the desired behavior.

Gili


Johan Compagner wrote:
We could add something for that with pages like we do already for other resources.

i also don't know what happens if you set headers afterwards instead of at front (but that is depeding if it already send something to the client i think)

Else you have to check the url. with a IRedirectListener param you can set the headers
And bookmarkable pages also.

joahn


Gili wrote:


That seems to imply it is impossible to apply a servlet filter which adds response headers (for caching). I mean, I have absolutely no way of knowing ahead of time which Wicket page I am filtering is going to redirect or not.

I believe Eelco originally recommended caching headers should be set using servlet filters. If this is no longer viable, we'd have to add support directly into Wicket core, no?

Gili

Johan Compagner wrote:

with a redirect nothing should be written to the stream i believe.



Gili wrote:


In my AddResponseHeaders filter (it's in the stack-trace) my code reads:

HttpServletResponse response = (HttpServletResponse) servletResponse;

    // set the provided HTTP response parameters
for (Enumeration e=config.getInitParameterNames(); e.hasMoreElements();)
    {
      String headerName = (String) e.nextElement();
response.addHeader(headerName, config.getInitParameter(headerName));
    }
    chain.doFilter(servletRequest, servletResponse);


so really all I am doing is setting response headers, why would this cause problems for redirect? Is this normal?

Gili

Johan Compagner wrote:

that is strange somehow there is already written something to the stream when we want to redirect I added some more info (the redirect url) so that you can see which urls are causing these problems.

johan


Gili wrote:


I just noticed this in my tomcat logs. Has anyone else experienced the same thing? (This is rc3)

23:42:21,171 ERROR WebResponse:148 - Unable to redirect. HTTP Response has already been committed. 23:42:21,171 ERROR [Webpage]:260 - Servlet.service() for servlet Webpage threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423) at wicket.protocol.http.WebResponse.redirect(WebResponse.java:156) at wicket.protocol.http.BufferedWebResponse.close(BufferedWebResponse.java:74) at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:226)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.be.desktopbeautifier.web.filter.AddResponseHeaders.doFilter(AddResponseHeaders.java:44) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:526) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Unknown Source)


This does not occur on a regular basis but if it's a bug, it would be nice to be able to track it down and fix it.

Gili


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop

Reply via email to