xml - Is there an example on how to use Spring 3.0 content negotiation for RESTful services? -


i reading spring 3.0 documentation , blog posts (followups) on how create rest style services spring mvc can't find working example on how use contentnegotiatingviewresolver. have test controller this

@controller public class indexcontroller implements serializable {     @requestmapping("/index")     public modelandview index()     {         modelandview mav = new modelandview();         mav.setviewname("index");         return mav;     }    } 

and tried use this

<bean     class="org.springframework.web.servlet.view.contentnegotiatingviewresolver">     <property name="mediatypes">         <map>             <entry key="html" value="text/html" />             <entry key="xml" value="text/xml" />             <!--                 <entry key="json" value="application/json"/>             -->         </map>     </property>     <property name="defaultcontenttype"><value>text/html</value></property>     <property name="defaultviews">         <bean class="org.springframework.web.servlet.view.xml.marshallingview">             <property name="marshaller">                 <bean class="org.springframework.oxm.xstream.xstreammarshaller" />             </property>         </bean>     </property>     <property name="viewresolvers">         <list>             <bean                 class="org.springframework.web.servlet.view.internalresourceviewresolver">                 <property name="prefix" value="/web-inf/views/pages/" />                 <property name="suffix" value=".jsp" />             </bean>         </list>     </property> </bean> 

trying resolve views according extension in url (i want support html, .xml , .json). .html view works (showing correct jsp view, too) nothing else tried getting json , xml , running seems work (setting defaultviews property 1 of things tried). there doesn't seem reading material either. have experience or examples?

i believe you're problem content-type of xml not text/xml, it's application/xml. you'll find marshallingview not accept content type of text/xml.

what contentnegotiatingviewresolver consult each of views, asking them if they'll accept content type resolved request. each content type want support, need view matching contenttype property.

you can either change content type in mediatypes property, or can override contenttype property of marshallingview text/xml.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -