title: Spring MVC - Request method 'POST' not supported
body: <p>I am learning Spring MVC (with Thymeleaf) while porting over a JBoss Seam website to Spring MVC. </p>
  
  <p>I am trying to replace a HTTPServlet (doPost to /myservlet) with a Spring Controller with the following code:</p>
  
  <pre><code>@RequestMapping(value="/myservlet", method = RequestMethod.POST)
  public String executeAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
  
       StringBuilder buffer = new StringBuilder();
       BufferedReader reader = request.getReader();
  
       String line;
       while((line = reader.readLine()) != null) {
           buffer.append(line);
       }
  
       String payload = buffer.toString();
       System.out.println("payload: " + payload);
       return "/index";
  }
  </code></pre>
  
  <p>This method needs to read the XML Payload (String) sent via a HTTP Post to this endpoint.</p>
  
  <p>When the external client (.NET - which will be used in the live environment) invokes this I get the following log messages:</p>
  
  <pre><code>[org.springframework.web.servlet.PageNotFound] (default task-3) Request method 'POST' not supported
  [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-3) Handler execution resulted in exception: Request method 'POST' not supported
  </code></pre>
  
  <p>I have also tried this as a HTTPServlet but with the same problem. Can someone please advise as to what I am doing wrong?</p>
  
  <p>The web.xml contents are:</p>
  
  <pre><code>&lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
      &lt;error-page&gt;
          &lt;error-code&gt;404&lt;/error-code&gt;
          &lt;location&gt;/404.html&lt;/location&gt;
      &lt;/error-page&gt;
  
    &lt;!-- Send unauthorised request to the 404 page --&gt;
    &lt;error-page&gt;
      &lt;error-code&gt;403&lt;/error-code&gt;
      &lt;location&gt;/404.html&lt;/location&gt; 
    &lt;/error-page&gt;
  
      &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;!-- Processes application requests --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;
          /WEB-INF/spring/appServlet/servlet-context.xml
        &lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
    &lt;!-- Spring Security --&gt;
    &lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
  
    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
    &lt;/listener&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The xml payload:</p>
  
  <pre><code>&lt;Jobs&gt;
      &lt;Job Action="Post"&gt;
          &lt;AdvertiserName&gt;Advertiser1&lt;/AdvertiserName&gt;
          &lt;AdvertiserType ValueID="15897"&gt;15897&lt;/AdvertiserType&gt;
          &lt;SenderReference&gt;01111111&lt;/SenderReference&gt;
          &lt;DisplayReference&gt;DISPLAYREF_635346301296069467_4445_Test89
          &lt;/DisplayReference&gt;
          &lt;Classification ValueID="6211"&gt;1002915&lt;/Classification&gt;
          &lt;SubClassification&gt;&lt;/SubClassification&gt;
          &lt;Position&gt;&lt;![CDATA[CASE MANAGER]]&gt;&lt;/Position&gt;
          &lt;Description&gt;&lt;![CDATA[ The Case Manager role is the vital link between all parties within the mortgage application process. ...]]&gt;&lt;/Description&gt;
          &lt;Country ValueID="246"&gt;United Kingdom&lt;/Country&gt;
          &lt;Location ValueID="12096"&gt;Yorkshire&lt;/Location&gt;
          &lt;Area ValueID="107646"&gt;Bradford&lt;/Area&gt;
          &lt;PostalCode&gt;BD1 1EE&lt;/PostalCode&gt;
          &lt;ApplicationURL&gt;http://removed.com/Application.aspx?uPjAaXJ9HmZ04+4i/bqmFAz
          &lt;/ApplicationURL&gt;
          &lt;Language ValueID="120036"&gt;2057&lt;/Language&gt;
          &lt;ContactName&gt;Joe Bloggs&lt;/ContactName&gt;
          &lt;EmploymentType ValueID="2163"&gt;2163&lt;/EmploymentType&gt;
          &lt;StartDate&gt;&lt;/StartDate&gt;
          &lt;Duration&gt;&lt;/Duration&gt;
          &lt;WorkHours ValueID="2190"&gt;2190&lt;/WorkHours&gt;
          &lt;SalaryCurrency ValueID="1078"&gt;1007000&lt;/SalaryCurrency&gt;
          &lt;SalaryMinimum&gt;16200.00&lt;/SalaryMinimum&gt;
          &lt;SalaryMaximum&gt;16200.00&lt;/SalaryMaximum&gt;
          &lt;SalaryPeriod ValueID="2178"&gt;1007600&lt;/SalaryPeriod&gt;
          &lt;JobType&gt;APPLICATION&lt;/JobType&gt;
      &lt;/Job&gt;
  &lt;/Jobs&gt;
  </code></pre>