Re: Requesting a URL which is not mapped by Prettyfaces

Splash Forums PrettyFaces Users Requesting a URL which is not mapped by Prettyfaces Re: Requesting a URL which is not mapped by Prettyfaces

#21274

RedShadow
Participant

I would like to share my final solution with those people who try to setup Prettyfaces and a Gzip Filter:

Put the filter-mapping element after the prettyfaces filter with all dispatchers.

<dispatcher>FORWARD</dispatcher>

<dispatcher>REQUEST</dispatcher>

<dispatcher>ERROR</dispatcher>

<dispatcher>ASYNC</dispatcher>

Request is needed when the request is not mapped in PF and forward of course when it is. Error might be useful too and async should be no problem either.

The problem with that now is, that the PF-Filter only takes care of the global rewrite rules(correct me if i am wrong). If any rule applies to the current request, the request will be forwarded or redirected else just pushed through the filter chain.

The main modification you have to make to your gzip filter implementation is, to check wether you response is already a gzip response or not and if yes, then you will probably not want to wrap it again :D

Here a code snippet to do that:

boolean compress = true;

Object wrappedResponse = response;

while (wrappedResponse instanceof ServletResponseWrapper) {

if (wrappedResponse instanceof GZIPResponseWrapper) {

compress = false;

break;

} else {

wrappedResponse = ((ServletResponseWrapper) wrappedResponse).getResponse();

}

}

This modification allows you to use GZIP compression with PF without any errors or endless loops! <3