[MAGNOLIA-2472] GZip Filter throws IllegalStateException when performing a redirect Created: 10/Nov/08  Updated: 23/Jan/13  Resolved: 05/Dec/08

Status: Closed
Project: Magnolia
Component/s: cache
Affects Version/s: 3.6.3
Fix Version/s: 4.0

Type: Bug Priority: Major
Reporter: Jackson Nicolas Assignee: Jan Haderka
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

WinXP, JDK 1.5


Issue Links:
relation
is related to MAGNOLIA-2387 Request stored in WebContext is not u... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

I have a paragraph using Freemarker and an action paragraph class.
I've recently decided to add a page redirect. I do attempt the page
redirect by accessing response object via WebContext. Everything works
fine until the redirect is actually performed.

Please note: The redirect works fine when I disable the GZip Filter.

My Code:

WebContext ctx = null;
if(MgnlContext.getInstance() instanceof WebContext)
ctx = (WebContext)MgnlContext.getInstance();

if(ctx != null) {
try {
HttpServletResponse response = (HttpServletResponse) ctx.getResponse();

if (!response.isCommitted())

{ response.reset(); response.sendRedirect(MgnlContext.getContextPath() + ContentUtil.getContentByUUID(ContentRepository.WEBSITE, redirectPage).getHandle() + "." + ServerConfiguration.getInstance().getDefaultExtension()); }

} catch (IOException ioe)

{ //TODO: handling }

}

The error:

java.lang.IllegalStateException: Failure when attempting to set
response header Content-Encoding: gzip
info.magnolia.cms.util.RequestHeaderUtil.addAndVerifyHeader(RequestHeaderUtil.java:66)
info.magnolia.module.cache.filter.GZipFilter.doFilter(GZipFilter.java:101)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:62)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:71)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:73)
info.magnolia.cms.filters.CosMultipartRequestFilter.doFilter(CosMultipartRequestFilter.java:84)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:71)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:71)
info.magnolia.cms.security.BaseSecurityFilter.doFilter(BaseSecurityFilter.java:61)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:71)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:71)
info.magnolia.cms.security.LogoutFilter.doFilter(LogoutFilter.java:81)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:62)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:71)
info.magnolia.cms.security.auth.login.LoginFilter.doFilter(LoginFilter.java:76)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:71)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:71)
info.magnolia.cms.filters.ContentTypeFilter.doFilter(ContentTypeFilter.java:80)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:71)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:71)
info.magnolia.cms.filters.ContextFilter.doFilter(ContextFilter.java:72)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:71)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:71)
info.magnolia.cms.filters.CompositeFilter.doFilter(CompositeFilter.java:64)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:71)
info.magnolia.cms.filters.MgnlMainFilter.doFilter(MgnlMainFilter.java:97)
info.magnolia.cms.filters.MgnlMainFilter.doFilter(MgnlMainFilter.java:200)



 Comments   
Comment by Jan Haderka [ 10/Nov/08 ]

Was just about to reply to you on the list. This issue is related to problem described at MAGNOLIA-2387. Changes already made for 3.7 resolve the problem.
However I would like to point out that since paragraph can be rendered anywhere on the page, you can never guarantee response not to be already committed before redirecting. If all you want is to redirect from one url to another, it might be better to use virtualURIMapping instead.

Comment by Philipp Bracher [ 14/Nov/08 ]

Note: you should not execute redirects in paragraphs. Once you reach the paragraph (the action is executed) the main template has already written its content.

Comment by Jan Haderka [ 05/Dec/08 ]

The problem was caused by discrepancy between real response and one available via WebContext. For details see MAGNOLIA-2387.
Also as mentioned by Philipp it is not advisable to make redirects from inside of paragraphs, since paragraph can be rendered at any time during page rendering process and response can be already committed at that time.
If necessary initiate this from pages using actions or from filters.

Comment by Magnolia International [ 05/Dec/08 ]

Can't this be backported to the 3.6 branch ?

Comment by Jan Haderka [ 05/Dec/08 ]

It would need backporting all the changes done for MAGNOLIA-2387

  • filter and filterChain
  • TemplateRenderers
  • WebContext
  • tags (Include)

It can be done if necessary, but I would rather not.
There are new methods introduced in the public API (MgnlContext) and changes to existing API (RequestAttributeStrategy).
Plus the effort to test on all major platforms to make sure that everything is all right in the backport as well.

On top of all that, the use case presented here is IMHO invalid. You should not redirect from within paragraphs. If you redirect from Filter or from page template you should not be seeing this issue even on 3.6

Comment by Magnolia International [ 05/Dec/08 ]

ok

Comment by Philipp Bracher [ 08/Dec/08 ]

Definitely no back-port.

Generated at Mon Feb 12 03:37:03 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.