title: UnMarshalling content-type=application/x-www-form-urlencoded using Jaxb2Marshaller throws error "Content is not allowed in prolog"
body: <p>I am trying to setup a rest service which handles request of content-type=application/x-www-form-urlencoded. I am currently using Jaxb2Marshaller for unmarshalling the request. However while unmarshalling, it is throwing error "[org.xml.sax.SAXParseException: Content is not allowed in prolog.]". </p>
  
  <p>I checked the xml request as string. It is in url-encoded form as:   %3C%3Fxml+version=%221.0%22+encoding%3D%22UTF-8%22+standalone%3D%22yes%22%3F%3E%3Cxrsi%.</p>
  
  <p>It seems this encoded xml string request is causing the error. Is there any way to decode the request first than unmarshall? </p>
  
  <p>Below is my context setting:</p>
  
  <pre><code>&lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
          &lt;property name="maxUploadSize" value="100000000" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"&gt;
          &lt;property name="autodetectAnnotations" value="true" /&gt;
          &lt;!-- Set some properties to make the outputted xml look nicer --&gt;
      &lt;/bean&gt;
  
      &lt;mvc:annotation-driven&gt;
          &lt;mvc:message-converters&gt;
              &lt;!-- Configure the XStream message converter --&gt;
              &lt;bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
                  &lt;property name="marshaller" ref="jaxbMarshaller2" /&gt;
                  &lt;property name="unmarshaller" ref="jaxbMarshaller2" /&gt;
  
                  &lt;property name="supportedMediaTypes"&gt;
                      &lt;list&gt;
                          &lt;bean class="org.springframework.http.MediaType"&gt;
                              &lt;constructor-arg index="0" value="application" /&gt;
                              &lt;constructor-arg index="1" value="xml" /&gt;
                          &lt;/bean&gt;
                          &lt;bean class="org.springframework.http.MediaType"&gt;
                              &lt;constructor-arg index="0" value="application" /&gt;
                              &lt;constructor-arg index="1" value="x-www-form-urlencoded" /&gt;
                          &lt;/bean&gt;
                      &lt;/list&gt;
                  &lt;/property&gt;
              &lt;/bean&gt;
          &lt;/mvc:message-converters&gt;
      &lt;/mvc:annotation-driven&gt;
  
      &lt;bean id="jaxbMarshaller2" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
  
          &lt;property name="classesToBeBound"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.auto.server.schema.ReceiveRequest&lt;/value&gt;
                  &lt;value&gt;com.auto.server.schema.ReceiveReply&lt;/value&gt;
  
              &lt;/list&gt;
  
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean name="viewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
  
          &lt;property name="ignoreAcceptHeader" value="true" /&gt;
          &lt;property name="favorParameter" value="true" /&gt;
          &lt;property name="favorPathExtension" value="true" /&gt;
          &lt;!-- if no content type is specified, return json. --&gt;
          &lt;property name="defaultContentType" value="application/x-www-form-urlencoded" /&gt;
  
          &lt;property name="mediaTypes"&gt;
              &lt;map&gt;
                  &lt;entry key="xml" value="application/x-www-form-urlencoded" /&gt;
              &lt;/map&gt;
          &lt;/property&gt;
          &lt;property name="defaultViews"&gt;
              &lt;list&gt;
                  &lt;bean class="org.springframework.web.servlet.view.xml.MarshallingView"&gt;
                      &lt;constructor-arg ref="jaxbMarshaller" /&gt;
                      &lt;property name="modelKey" value="responseObject" /&gt;
                  &lt;/bean&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- REST API controllers --&gt;
      &lt;context:component-scan base-package="com.auto.server.schema" /&gt;
  
  Here is the controller part
  
  @ResponseBody
      @RequestMapping(value = "/heartbeat", method = RequestMethod.POST, headers = { "content-type=application/x-www-form-urlencoded" }, consumes = "application/x-www-form-urlencoded;charset=UTF-8")
      public Object heartBeat(@RequestBody ReceiveRequest request) {
  
          ReceiveReply reply = new ReceiveReply();        
          return reply;
      }
  </code></pre>