Announcement Announcement Module
Collapse
No announcement yet.
406 not acceptable Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 406 not acceptable

    Hi everyone,

    I recently ran into a strange behaviour.

    I'm testing spring REST capabilities. I use no views and send data in the body with @ResponseBody

    - I specify the accept header 'application/xml' in my client side restTemplate.exchange method
    - I use AnnotationMethodHandlerAdapter at server side
    - Jaxb2 is present in my classpath (as I use jdk6)
    - My domain object is annotated with @XmlRootElement

    With all these conditions everything should go well but I get a 406 not acceptable error code

    src/test/stories/FindingInterestPointsAroundMeShouldSucceedStory.gr oovy
    Code:
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML))
    src/test/stories-context.xml (spring client side)
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    	<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
    		<constructor-arg ref="httpClientFactory" />
    	</bean>
    
    	<bean id="httpClientFactory"
    		class="org.springframework.http.client.CommonsClientHttpRequestFactory">
    		<constructor-arg ref="httpClient" />
    	</bean>
    
    	<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
    		<constructor-arg ref="httpClientParams" />
    	</bean>
    
    	<bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams">
    		<property name="connectionManagerClass"
    			value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" />
    	</bean>
    </beans>
    src/main/webapp/interest-points-servlet.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
                               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                               http://www.springframework.org/schema/context
                               http://www.springframework.org/schema/context/spring-context-3.0.xsd
                               http://www.springframework.org/schema/mvc
                               http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
    	<context:component-scan base-package="org.diveintojee" />
    
    	<bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
    
    	<mvc:annotation-driven/>
    
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
    
    </beans>
    src/main/java/org/diveintojee/poc/webmvc/InterestPointsController.java
    Code:
    package org.diveintojee.poc.webmvc;
    
    import java.util.List;
    
    import org.diveintojee.poc.domain.InterestPoint;
    import org.diveintojee.poc.domain.service.InterestPointsService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    /**
     * @author [email protected]
     */
    @Controller
    public class InterestPointsController {
    
        @Autowired
        private InterestPointsService interestPointsService;
    
        @RequestMapping(value = "/find", method = RequestMethod.GET)
        @ResponseBody
        public List<InterestPoint> find(final InterestPoint interestPoint) {
    
            return interestPointsService.findByExample(interestPoint);
    
        }
    }

    You can clone the application on github : https://[email protected]/lgueye/interest-points.git

    If not on github I can easily provide a tarball archive.

    To test the offending behaviour you can :
    - change the media sent to 'application/xml' in the source src/test/stories/FindingInterestPointsAroundMeShouldSucceedStory.gr oovy
    - run mvn clean install
    - note the build failure

    You can change the log level in src/main/resources/log4j.xml

    I use spring 3.0.6

    Regards,

    Louis GUEYE

  • #2
    any ideas ?

    Hi everyone ?

    Any ideas on that issue ?
    Using jdk6 should allow me to marshall/unmarshall xml out of the box.

    I'm stuck. I really don't get what I'm doing wrong

    Louis.

    Comment


    • #3
      [solved]

      logging beetwen stacks is crucial. If I had do that I wouldn't have lost 4 days with that issue.

      I was sending a bad header : "application/". no wonder that value did not match any supported header.

      my bad.

      Comment

      Working...
      X