Announcement Announcement Module
Collapse
No announcement yet.
REST and POST with XStream Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • REST and POST with XStream

    I'm using XStream instead of Jaxb to do the conversion. Everythings works fine with GET methods, but I receive a
    Code:
    org.springframework.web.client.HttpClientErrorException: 415 Unsupported Media Type
    when trying to work with POST.

    Simple pojos to use in the request / response is "Order" and "Bundle".

    Client Config:
    applicationContextXML
    Code:
    	<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
    		<constructor-arg ref="httpClientParams" />
    	</bean>
    	<bean id="httpClientFactory"
    		class="org.springframework.http.client.CommonsClientHttpRequestFactory">
    		<constructor-arg ref="httpClient" />
    	</bean>
    	<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
    		<constructor-arg ref="httpClientFactory" />
    		<property name="messageConverters">
    			<list>
    				<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
    				<property name="marshaller">
    						<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
    							<property name="autodetectAnnotations" value="true" />
    						</bean>
    				</property>
    				<property name="unmarshaller">
    						<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
    							<property name="autodetectAnnotations" value="true" />
    						</bean>
    				</property>
    				</bean>
    				<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
    			</list>
    		</property>
    	</bean>
    Client:
    Code:
    	private final RestTemplate restTemplate;
    
    	public RestClientImpl(RestTemplate restTemplate) {
    		this.restTemplate = restTemplate;
    	}
    	public Order submitOrder(Order order) {
    		return restTemplate.postForObject(submitOrderUrl, order,
    				Order.class);
    	}
    Server:
    applicationContext.xml
    Code:
    	<bean id="marshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
    		<property name="autodetectAnnotations" value="true" />
    	</bean>
    
    	<bean id="xmlView"
    		class="org.springframework.web.servlet.view.xml.MarshallingView">
    		<constructor-arg ref="marshaller" />
    	</bean>
    
    	<bean id="converter"
    		class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
    		<constructor-arg ref="marshaller" />
    	</bean>
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    		<property name="messageConverters">
    			<list>
    				<ref bean="converter" />
    			</list>
    		</property>
    	</bean>
    Server Code:
    Code:
    	@RequestMapping(value = "/test/order", method = RequestMethod.POST)
    	public ModelAndView submitOrder(@RequestBody Order order) {
    		Order submittedOrder = someService.submitOrder(order);
    		ModelAndView mav = new ModelAndView("xmlView",
    				BindingResult.MODEL_KEY_PREFIX + "order", submittedOrder);
    return mav;
    	}

  • #2
    I am getting the same issue with my code too, using XStream and REST template.

    It was doing the POST ok until I added <mvc:annotation-driven/> in preparation for adding @DateTimeFormat

    Comment


    • #3
      Great, that solved it for me!

      Comment


      • #4
        sir,can you please tell us,how did you solve this issue

        Originally posted by bwagner View Post
        Great, that solved it for me!
        i am facing the same problem,
        can you please tell us how did you solve

        Comment


        • #5
          if you're using <mvc:annotation-driven/>, remove it

          Comment

          Working...
          X