1

I'm trying to add Sniffy profiler into JSF project.

According to the documentation web.xml needs to be updated with following filter:

<filter>
    <filter-name>sniffer</filter-name>
    <filter-class>io.sniffy.servlet.SnifferFilter</filter-class>
    <init-param>
        <param-name>inject-html</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>enabled</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>sniffer</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

But web.xml already contains one filter:

<filter>
    <filter-name>Character Encoding Filter</filter-name>
    <filter-class>org.primefaces.titan.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Character Encoding Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>    
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

When sniffer filter is added (and works correctly) Character Encoding Filter stops working (characters are garbled).

How should web.xml looks like to have both filters working?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jan Kopecký
  • 93
  • 1
  • 7
  • Filters are invoked in the order they are declared in web.xml. Problem suggests that Sniffy filter accesses the request payload before character encoding filter gets chance to set request encoding. Logical solution would be to put the mapping of the character encoding filter before the Sniffy filter. – BalusC Jun 03 '16 at 21:26
  • @BalusC Declaring Character Encoding Filter before sniffer produce same result (characters are garbled). It seems to that in this case order of filters makes no difference. – Jan Kopecký Jun 04 '16 at 07:09
  • Can you show the value of Content-Type header returned from your server? You can check it in developer tools in your browser – bedrin Jun 07 '16 at 09:06
  • @bedrin Value of Content-Type is as follows: `Content-Type:"text/html;charset=UTF-8"` – Jan Kopecký Jun 07 '16 at 12:49

1 Answers1

3

Sniffy developer here. It is a bug in Sniffy - I plan to fix it in upcoming 3.1 release.

As a workaround you can add following to your JVM arguments:

-Dfile.encoding=UTF-8

bedrin
  • 4,458
  • 32
  • 53
  • 1
    I'm getting following warning when running Sniffy on Payara server. This could be useful when tracking the issue. `Warning: Unable to set request character encoding to UTF-8 from context , because request parameters have already been read, or ServletRequest.getReader() has already been called` – Jan Kopecký Jun 16 '16 at 12:01