Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you closely examine the stack trace, all the classes involved (in parsing HTTP text to Java request object) are from the framework and there is <strong>no user control over it</strong>. </p> <p>Now the <strong>basic premise</strong> behind this is: The server will always assume that the data it received is <strong>always URL encoded</strong> and HENCE it will always try to decode. </p> <p>If the decoding fails, that implies that the basic tenets of the HTTP protocol were not adhered to and hence rejects the request outrightly without giving user a chance to handle it.</p> <p>So IMHO, you cannot handle this condition as the server is rightly handling it by itself. </p> <p><strong>EDIT:</strong></p> <p>One the solution proposed by @Ravi above <em>looks</em> like it solves the problem. I tried the same code but I could never catch the exception ! </p> <p>Digging down deeper, it became clear why that exception (<code>java.io.CharConversionException</code>) could not be handled in any user defined code.</p> <p>Though <code>java.io.CharConversionException</code>is thrown but its never propagated in the call hierarchy. Here is why,</p> <p>In the stack trace </p> <pre><code> at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:83) at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:49) at org.apache.tomcat.util.http.Parameters.urlDecode(Parameters.java:429) at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:412) </code></pre> <p>Look at the <strong>source</strong> of the method <code>processParameters()</code> in class <code>org.apache.tomcat.util.http.Parameters</code> (Code taken from <a href="http://grepcode.com/file/repository.springsource.com/org.apache.coyote/com.springsource.org.apache.coyote/6.0.18/org/apache/tomcat/util/http/Parameters.java#Parameters.processParameters%28byte%5B%5D,int,int,java.lang.String%29" rel="nofollow">grepcode</a>)</p> <pre><code>public void processParameters( byte bytes[], int start, int len, String enc ) { int end=start+len; int pos=start; if( debug&gt;0 ) log( "Bytes: " + new String( bytes, start, len )); do { boolean noEq=false; int valStart=-1; int valEnd=-1; int nameStart=pos; int nameEnd=ByteChunk.indexOf(bytes, nameStart, end, '=' ); // Workaround for a&amp;b&amp;c encoding int nameEnd2=ByteChunk.indexOf(bytes, nameStart, end, '&amp;' ); if( (nameEnd2!=-1 ) &amp;&amp; ( nameEnd==-1 || nameEnd &gt; nameEnd2) ) { nameEnd=nameEnd2; noEq=true; valStart=nameEnd; valEnd=nameEnd; if( debug&gt;0) log("no equal " + nameStart + " " + nameEnd + " " + new String(bytes, nameStart, nameEnd-nameStart) ); } if( nameEnd== -1 ) nameEnd=end; if( ! noEq ) { valStart= (nameEnd &lt; end) ? nameEnd+1 : end; valEnd=ByteChunk.indexOf(bytes, valStart, end, '&amp;'); if( valEnd== -1 ) valEnd = (valStart &lt; end) ? end : valStart; } pos=valEnd+1; if( nameEnd&lt;=nameStart ) { log.warn("Parameters: Invalid chunk ignored."); continue; // invalid chunk - it's better to ignore } tmpName.setBytes( bytes, nameStart, nameEnd-nameStart ); tmpValue.setBytes( bytes, valStart, valEnd-valStart ); try { addParam( urlDecode(tmpName, enc), urlDecode(tmpValue, enc) ); } catch (IOException e) { // Exception during character decoding: skip parameter log.warn("Parameters: Character decoding failed. " + "Parameter skipped.", e); } tmpName.recycle(); tmpValue.recycle(); } while( pos&lt;end ); } </code></pre> <p>In the method, there is do-while loop for parsing all the request parameters. Look at the <strong>try-catch block</strong> at the end of loop in the method. There is a comment which says</p> <pre><code>// Exception during character decoding: skip parameter </code></pre> <p>So even if the exception is thrown but its <strong>not propagated</strong>. Its logged as a warning message and parameter value is set to null. So it's clear that <strong>you will never be able to catch that exception</strong> (<code>java.io.CharConversionException</code>)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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