Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A few other ideas:</p> <ul> <li>add filter which calls <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#setContentType%28java.lang.String%29" rel="nofollow noreferrer">setContentType</a> or <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#setCharacterEncoding%28java.lang.String%29" rel="nofollow noreferrer">setCharacterEncoding</a> and which is before all other filters</li> <li>set the property <code>-Dfile.encoding</code></li> <li>rebind the javascript <code>window.alert</code> so that it escapes the characters</li> </ul> <p>This seems to work, but would be a very, very ugly hack. This would also be very limited and won't work if javascript sets other texts, e.g. content of a <code>div</code>. </p> <pre><code>var hack = window.alert; window.alert = function( text ) { hack( text + ' was converted' ); }; alert('hello'); </code></pre> <hr> <p>UPDATE:</p> <p>Here is the sequence that is suspect:</p> <p>1) <a href="http://www.docjar.com/html/api/org/apache/myfaces/webapp/filter/ExtensionsFilter.java.html" rel="nofollow noreferrer">ExtensionsFilter</a> intercepts the request</p> <p>2) ExtensionsFilter contains</p> <pre><code> 154 // only parse HTML responses 155 if (extendedResponse.getContentType() != null &amp;&amp; isValidContentType(extendedResponse.getContentType())) 156 { ... 172 // writes the response 173 addResource.writeResponse(extendedRequest, servletResponse); 174 } 175 else 176 { 178 byte[] responseArray = extendedResponse.getBytes(); 180 if(responseArray.length &gt; 0) 181 { 182 // When not filtering due to not valid content-type, deliver the byte-array instead of a charset-converted string. 183 // Otherwise a binary stream gets corrupted. 184 servletResponse.getOutputStream().write(responseArray); 185 } </code></pre> <p>3) <a href="http://www.docjar.com/html/api/org/apache/myfaces/renderkit/html/util/DefaultAddResource.java.html" rel="nofollow noreferrer">DefaultAddResource</a> uses <a href="http://www.docjar.com/html/api/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java.html" rel="nofollow noreferrer">HtmlResponseWriterImpl</a> which uses <a href="http://www.docjar.com/html/api/org/apache/myfaces/renderkit/html/util/UnicodeEncoder.java.html" rel="nofollow noreferrer">UnicodeEncoder</a>.</p> <p>4) All "non basic latin characters" are then encoded.</p> <p>Conclusion</p> <ul> <li>if you set the content type to something invalid, the ExtensionsFilter will default to the "else" branch and won't encode the response. But, then the ExtensionsFilter is probably broken.</li> <li>changing setCharacterEncoding has probably no effect, neither the <code>file.encoding</code></li> <li>creating an extra filter to wrap again the response and revert some of the <code>&amp;#xx;</code> could work but is extremely ugly.</li> </ul> <p>I don't have other ideas right now, but I'm interested in the answer as I also bumped on encoding issue which were annoying.</p> <hr> <p>UPDATE 2:</p> <p>You could give a try to <a href="http://www.eclipse.org/aspectj/doc/released/progguide/starting-aspectj.html" rel="nofollow noreferrer">AspectJ</a> to alter just the part of the MyFaces library that relates to the encoding form within the filter. According to my understanding of <code>cflow</code> and the <code>call</code> pointcut pickings, something like this might intercept the encoding when it happens from the filter. If this definition creates other interferences in the request processing, you might want to also consider the call to <code>addResource.writeResponse</code> to limit further the pointcut. </p> <pre><code>public aspect SkipEncoding { pointcut encodingInExtFilter() : cflow( * org.apache.myfaces.webapp.filter. ExtensionsFilter.doFilter(..) ) &amp;&amp; call ( String UnicodeEncoder.encode( String, bool, bool )); around( String s, bool b1, bool b2 ) : encodingInExtFilter { return s; // skip encoding } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload