Announcement Announcement Module
Collapse
No announcement yet.
Return from getJSON() not being handled? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Return from getJSON() not being handled?

    I am attempting to make use of spring 3 ajax with a simple heartbeat checker. In the jsp I have code that makes the following call:

    function testHeartBeat()
    { $.getJSON( "myApp/StatusCheck?message=Status",
    function( data ) {
    document.getElementById( "heartbeatStatus" ).value = data.response;});}

    The controller which receives this is:

    @RequestMapping(value="/StatusCheck", method=RequestMethod.GET )
    public @ResponseBody HeartBeat getHeartbeat( @RequestParam String message )
    { HeartBeat hb = HeartBeat.Transmit( message );
    return ( hb ); }

    The getHeartbeat is called and returns back a heartbeat object but the callback function in the javascript never runs apparently. I am using <mvc:annotation-driven /> with spring mvc 3.0.5. What I get back is a 406 error: "The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()."

  • #2
    Make sure you have registered the MappingJacksonHttpMessageConverter.

    Code:
    <bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
    
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="jacksonMessageConverter"/>
            </list>
        </property>
    </bean>

    Comment


    • #3
      In the spring-samples the mvc-ajax example, mentioned in the http://blog.springsource.com/2010/01...-in-spring-3-0 blog article the MappingJacksonHttpMessageConverter was not registered. Does the sample not work then?

      Comment


      • #4
        According to the documentation, if you have the jackson libraries in the classpath and you use the <mvc:annotation-driven> configuration then it should automatically register the jackson converter for you.

        Comment


        • #5
          I made sure that the jackson jar is present (jackson-all-1.7.3.jar) along with <mvc:annotation-driven/> When I spin up the server I get the following:

          SEVERE: StandardWrapper.Throwable
          org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.An notationMethodHandlerAdapter#0': Cannot create inner bean '(inner bean)' of type [org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter] while setting bean property 'messageConverters' with key [6]; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)#8': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.VerifyError: (class: org/codehaus/jackson/map/ObjectMapper, method: writeValueAsBytes signature: (Ljava/lang/Object[B) Incompatible argument to function
          at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveInnerBean(BeanDefinitio nValueResolver.java:281)
          at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:125)
          at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveManagedList(BeanDefinit ionValueResolver.java:353)
          at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:153)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1325)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1086)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
          at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
          at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
          at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
          at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580)
          at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
          at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
          at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 42)
          at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 58)
          at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:339 )
          at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:306)
          at org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:127)
          at javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
          at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1173)
          at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:809)
          at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:129)
          at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
          at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
          at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
          at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
          at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
          at java.lang.Thread.run(Thread.java:662)

          I tried to find the error message on google but came up blank.

          Comment

          Working...
          X