(This question is posted on Stackoverflow too, http://stackoverflow.com/questions/1...th-spring-mvc3)
I am new to Spring MVC (Spring 3) and REST, and I am trying out a little toy app to try out GET and POST web services. I have read the Spring's official reference, and found these questions in Stackoverflow, http://stackoverflow.com/questions/8...st-application , http://stackoverflow.com/questions/4...n-spring-mvc-3 but I am still stucked in making it works. Can anyone give me hints on what I missed?
My Controller is like this:
I have putted corresponding converter in the app ctx:Code:@Controller @RequestMapping(value = "/echo") public class EchoControllerImpl implements EchoController { @RequestMapping(method = RequestMethod.POST, value = "/echoByPost") public ModelAndView echoByPost(@ModelAttribute EchoDto input) { // ... } }
I even tried to add these to web.xml as I saw somewhere mentioning about it (though I don't really know what does it means)Code:<mvc:annotation-driven /> <bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller" > <property name="classesToBeBound"> <list> <value>foo.EchoDto</value> </list> </property> </bean> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="marshallingHttpMessageConverter" /> <ref bean="stringHttpMessageConverter" /> </list> </property> </bean> <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter" /> <bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"> <property name="marshaller" ref="jaxb2Marshaller" /> <property name="unmarshaller" ref="jaxb2Marshaller" /> </bean> <!-- other beans like ViewResolvers -->
Code:<filter> <filter-name>httpPutFormFilter</filter-name> <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class> </filter> <filter-mapping> <filter-name>httpPutFormFilter</filter-name> <servlet-name>spring-rest</servlet-name> </filter-mapping>
Then I tried to invoke my web service by Curl:
I found that my incoming object is not created through unmarshalling of JAXB2. Instead, seems that the ctor EchoDto(String) is called which the contains whole request xml message.Code:`curl -d "echoDto=<EchoDto><message>adrian</message></EchoDto>" http://localhost:8001/foo/rest/echo/echoByPost.xml`
(I also tried annotating the parameter with @RequestBody instead but it is even worse, that I cannot even invoke the controller method)
Can someone tell me what I have missed?
The Jaxb2Marshaller is setup correctly with the DTO class, coz I am able to use it as returned model object in case of another GET REST webserivce call.


Reply With Quote
