Announcement Announcement Module
Collapse
No announcement yet.
@RequestBody resulted in 415 (Unsupported Media Type); Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @RequestBody resulted in 415 (Unsupported Media Type);

    Hi! i have :

    Code:
    <bean
    		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    			<property name="order" value="0"/>
    		</bean>
    		
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    		<property name="messageConverters">
    			   <ref bean="messageConverter"/>
    		</property>
    	</bean>
    	
    	<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
            <property name="messageConverters">
                <list>
                    <ref bean="messageConverter"/>
                </list>
            </property>
        </bean>
    		
    		<bean id="messageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
                        <property name="marshaller" ref="jaxbMarshaller" />
                        <property name="unmarshaller" ref="jaxbMarshaller" />
                    </bean>
    		
    		<!-- Resolve views based on string names -->
        <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
    
    
        <!-- XML view using a JAXB2 marshaller -->
        <bean id="jaxbView" class="org.springframework.web.servlet.view.xml.MarshallingView">
            <constructor-arg ref="jaxbMarshaller" />
        </bean>
    
    
        <!-- JAXB2 marshaller. Automagically turns beans into xml -->
        <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="classesToBeBound">
                <list>
                    <value>com.wallet.Response</value>
                </list>
            </property>
            
        </bean>
        
        <context:component-scan base-package="com.wallet"/>
    
       <context:annotation-config/>
       
       <mvc:view-controller path="/" />
    controller:

    Code:
    @Controller
    public class WalletController {
    	
    	@RequestMapping(value="/wallet", method=RequestMethod.GET)
        public ModelAndView myRestMethod(@RequestBody Response response) {
    		response.setNewBalance(45);
            return new ModelAndView("jaxbView", BindingResult.MODEL_KEY_PREFIX + "response", response);
        }
    
    }
    and client :

    Code:
    Response response = (Response)restTemplate.getForObject(URL, Response.class, vars);
    but when i try to make request i got:

    Code:
    WARNING: GET request for "http://localhost:8080/wallet/wallet" resulted in 415 (Unsupported Media Type); invoking error handler
    Exception in thread "Thread-2" org.springframework.web.client.HttpClientErrorException: 415 Unsupported Media Type
    	at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76)
    	at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:486)
    	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:443)
    can anybody help to me... what is the problem ?
Working...
X