Announcement Announcement Module
Collapse
No announcement yet.
HttpMediaTypeNotSupportedException-Content type 'application/x-www-form-urlencoded' n Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HttpMediaTypeNotSupportedException-Content type 'application/x-www-form-urlencoded' n

    Hi all,

    I am trying to create a Spring REST service using @RequestBody to translate XML data to my mapped objects.

    I am doing a POST to 'create' but the 'create' method was never triggered. The debugger shows:

    HttpMediaTypeNotSupportedException, id=192
    MediaType id=197
    Content type 'application/x-www-form-urlencoded' not supported


    My POJO for mapping the XML data:

    @Configurable
    public class XMLObject {
    ...
    }

    My Controller:

    @Controller
    public class XMLObjectController {
    @RequestMapping(value = "/xmlobject", method = RequestMethod.POST)
    public String create(@RequestBody XMLObject xmlobject, ModelMap modelMap) {
    System.out.println("XMLObject: " + xmlobject);
    if (xmlobject == null) throw new IllegalArgumentException("An XMLObject request is required");
    return "redirect:/xmlobject/";
    }

    My webmvc_config.xml:

    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <property name="classesToBeBound">
    <list>
    <value>com.demo.domain.XMLObject</value>
    </list>
    </property>
    <!-- <property name="schema" value="classpath:org/springframework/oxm/schema.xsd"/> -->
    </bean>

    <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">
    <property name="marshaller" ref="marshaller" />
    <property name="unmarshaller" ref="marshaller" />
    </bean>

    Any ideas will be greatly appreciated.

    Many Thanks in advance.
Working...
X