Announcement Announcement Module
Collapse
No announcement yet.
Receiving POST Request on Server Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Receiving POST Request on Server

    I am using spring rest based application. Currently i have requirement to accept content-type of application/x-www-form-urlencoded","application/json" mapped to the same uri. But its failing with following exception.

    RequestMapping(value=".json",method=RequestMethod. POST, consumes={"application/json"})
    public String createStrudentRecord(@RequestBody Student student, Model model) {
    ...}

    <bean id="jsonConverter"
    class="org.springframework.http.converter.json.Map pingJackson2HttpMessageConverter"/>

    <bean id="formConverter"
    class="org.springframework.http.converter.FormHttp MessageConverter"/>


    <bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
    <list>
    <ref bean="jsonConverter" />
    <ref bean="formConverter" />
    </list>
    </property>
    </bean>

    StackTrace :
    org.springframework.web.HttpRequestMethodNotSuppor tedException: Request method 'POST' not supported
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ServletHandlerMethodRe solver.resolveHandlerMethod(AnnotationMethodHandle rAdapter.java:670)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:435)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:428)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:838)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:727)
    at org.springframework.web.servlet.FrameworkServlet.s ervice(FrameworkServlet.java:812)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1093)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.e xecuteChain(AbstractShiroFilter.java:449)
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1 .call(AbstractShiroFilter.java:365)
    at org.apache.shiro.subject.support.SubjectCallable.d oCall(SubjectCallable.java:90)
    at org.apache.shiro.subject.support.SubjectCallable.c all(SubjectCallable.java:83)

    Any ideas what I am missing here ?

  • #2
    Please use [ code][code ] tags when posting, that way code/xml/stacktraces remain readable

    For starters you shouldn't be using the AnnotationMethodHandlerAdapter but the RequestMappingHandlerAdapter (judging from the classes you are on Spring 3.x)... Also you don't need to add the converters those are available by default (the same for the handler adapter/handlermapping) when using mvc:annotation-driven.

    Final thought, your mapping only accepts on the url .json... Nothing more,nothing less... So all other URLs are ignored...

    Comment

    Working...
    X