Hi,
I'm trying new features of Spring 3. I'm creating a simple application with MVC. The application is composed by
1. A controller with new REST feature (MarcoController)
================
package it.mplebani.spring.rest.controller;
import it.mplebani.spring.rest.data.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBod y;
import org.springframework.web.bind.annotation.RequestMap ping;
import org.springframework.web.bind.annotation.RequestMet hod;
@Controller
public class MarcoController {
@RequestMapping(value="/people/get" ,method = RequestMethod.GET)
public void all(){
System.out.println("ALL");
}
@RequestMapping(value="/people/new",method = RequestMethod.POST)
public void newPerson(@RequestBody Person person){
System.out.println("I am here");
}
}
================
2. A simple Domain Object (Person)
================
package it.mplebani.spring.rest.data;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Person {
public String name;
public String surname;
}
================
3. The servlet associated spring context
================
<bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="marshallingHttpMessageConverter"/>
</list>
</property>
</bean>
<bean id="marshallingHttpMessageConverter"
class="org.springframework.http.converter.xml.Mars hallingHttpMessageConverter"
p:marshaller-ref="jaxb2Marshaller" p:unmarshaller-ref="jaxb2Marshaller" />
<bean id="jaxb2Marshaller" class="it.mplebani.spring.rest.marshaller.MyJaxb2M arshaller">
<property name="classesToBeBound">
<list>
<value>it.mplebani.spring.rest.data.Person</value>
</list>
</property>
</bean>
<context:component-scan base-package="it.mplebani.spring.rest" />
================
4. the web.xml that associates the servletDispatcher with the spring context.
Now, I'm testing the servlet endpoint with RESTClient. Calling the GET endpoint all works fine. Calling the POST endpoint I retrieve a "HTTP/1.1 415 Unsupported Media Type".
Modifying the application changing the method newPerson the this new one
@RequestMapping(value="/people/new",method = RequestMethod.POST)
public void newPerson(String person){
System.out.println("I am here");
}
All works fine. In debugging mode I can see the application stack passing through this method.
I think this is a problem with @RequestBody or with the Marshaller.
Any idea?
Thanks
-- Marco


Reply With Quote
