title: Order of request parameters for content-type application/x-www-form-urlencoded in Spring MVC
body: <p>I am working on web service which consumes requests of type  <code>application/x-www-form-urlencoded</code>. Here is an example of such a request body:</p>
  
  <pre><code>loginId=tester&amp;action=add&amp;requestId=987654321&amp;data=somedata
  </code></pre>
  
  <p>The request is signed (with <code>SHA1withRSA</code>) by the client and the signature is sent as a  HTTP header.</p>
  
  <p>The thing is that I always get the parameters in different order, for example:</p>
  
  <pre><code>action=add&amp;loginId=tester&amp;requestId=987654321&amp;data=somedata
  </code></pre>
  
  <p>Therefor verifying the signature always fails.</p>
  
  <p>Interesting is that this occurs only if the <code>Content-Type</code> is <code>application/x-www-form-urlencoded</code> and if I switch the <code>Content-Type</code> to <code>text/plain</code> then everything works perfectly.</p>
  
  <p>I've used different types of clients (even monitored the traffic using a TCP monitor) and I am sure that the issue is not caused by the client app.</p>
  
  <p>Here is part of my custom message converter (note that I am directly printing the incoming request to console):</p>
  
  <pre><code>@Override
  protected Object readInternal(Class&lt;?&gt; clazz, HttpInputMessage inputMessage) throws IOException,
          HttpMessageNotReadableException {
  
      log.debug("&gt; readInternal - message to Object");
      InputStream inputStream = inputMessage.getBody();
      byte[] bytes = IOUtils.toByteArray(inputStream);
      String body = new String(bytes, charset);
  
      log.debug("Body: {}", body);
  }
  </code></pre>
  
  <p>And my Spring MVC configuration:</p>
  
  <pre><code>&lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt;
  
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
      &lt;property name="messageConverters"&gt;
          &lt;array&gt;
              &lt;bean class="converter.NvpHttpMessageConverter"&gt;
                  &lt;property name="charset" value="UTF-8" /&gt;
                  &lt;property name="nvpConverter" ref="nvpConverter" /&gt;
              &lt;/bean&gt;
          &lt;/array&gt;
      &lt;/property&gt;
  
  &lt;/bean&gt;
  </code></pre>
  
  <p>I believe that Spring somehow detects that content type is <code>application/x-www-form-urlencoded</code> and uses some kind of pre-processing. Is my assumption correct? Can this be turned off?</p>
  
  <p>I'm using Tomcat 7.</p>