Note that there are some explanatory texts on larger screens.

plurals
  1. POhaving trouble getting automatically formatted json data from annotated controller
    primarykey
    data
    text
    <p>From what I understand, if you're using the mvc:annotation-driven tag, then you can pass back JSON formatted objects, provided that the relevant jackson jar files are present in the classpath. This is the case.</p> <p>However, I'm getting a 406 (not acceptable) response from the server.</p> <p>here's the relevant section from the annotated controller:</p> <pre><code>@RequestMapping(value = "/{groupEventUID}/{attendeeId}/update2.htm", method = RequestMethod.POST) public @ResponseBody DateResponse submitDate2(@PathVariable String groupEventUID, @PathVariable int attendeeId, ModelMap model) { return new DateResponse(); } </code></pre> <p>This is the jquery code on the client page:</p> <pre><code> &lt;script type="text/JavaScript"&gt; $(document).ready(function(){ $(".dayblock").click(function(){ $(event.target).css('background-color','green'); $.ajax({ url: "update2.htm", type: "POST", dataType: "json", success: function(data){ alert("Data Loaded: " + data); } }); }); }); &lt;/script&gt; </code></pre> <p>The jackson jars that I've tried placing in the classpath are:</p> <p>jackson-core-asl-1.7.2.jar and jackson-mapper-asl-1.7.2.jar</p> <p>I also tried</p> <p>jackson-all-1.7.2.jar</p> <p>still getting the dreaded 406..</p> <p>Does the DateResponse object need to be explicitly annotated to convert it to JSON? I would have thought that using the existing field names would be the default behaviour.</p> <p>I think the most frustrating thing is that I can't see any back end exceptions, so I'm resorting to trial and error.</p> <p>EDIT: Here are the http headers</p> <pre><code>Request URL:http://localhost:8080/7uid/5/update2.htm Request Method:POST Status Code:406 Not Acceptable Request Headers Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-GB,en-US;q=0.8,en;q=0.6 Connection:keep-alive Content-Length:0 Cookie:JSESSIONID=C8B515F9BE0773BF7916E3FA7F17EE30 Host:localhost:8080 Origin:http://localhost:8080 Referer:http://localhost:8080/7uid/5/showAttendeeCalendar.htm User-Agent:Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.84 Safari/534.13 accept:application/json, text/javascript, */*; q=0.01 x-requested-with:XMLHttpRequest Response Headers Cache-Control:no-cache no-store Content-Length:1070 Content-Type:text/html;charset=utf-8 Date:Mon, 07 Feb 2011 16:31:03 GMT Expires:Thu, 01 Jan 1970 00:00:00 GMT Pragma:no-cache Server:Apache-Coyote/1.1 </code></pre> <p>And here is the dispatcher-servlet.xml file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" 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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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" &gt; &lt;context:component-scan base-package="com.crowdbot.nightout.web"/&gt; &lt;context:component-scan base-package="com.crowdbot.nightout.dao"/&gt; &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt; &lt;bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /&gt; &lt;!-- Most controllers will use the ControllerClassNameHandlerMapping above, but for the index controller we are using ParameterizableViewController, so we must define an explicit mapping for it. --&gt; &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="mappings"&gt; &lt;props&gt; &lt;prop key="index.htm"&gt;indexController&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- The index controller. --&gt; &lt;bean name="indexController" class="org.springframework.web.servlet.mvc.ParameterizableViewController" p:viewName="index" /&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /&gt; &lt;bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="loadTimeWeaver"&gt; &lt;bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="emf"/&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="myTxManager" /&gt; &lt;bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;&lt;/bean&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;property name="messageConverters"&gt; &lt;list&gt; &lt;ref bean="jacksonMessageConverter"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;mvc:annotation-driven/&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /&gt; &lt;/beans&gt; </code></pre> <p>EDIT2: here's the catalina.out</p> <pre><code>07-Feb-2011 17:05:46 org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /opt/java/jdk1.6.0_21/jre/lib/amd64/server:/opt/java/jdk1.6.0_21/jre/lib/amd64:/opt/java/jdk1.6.0_21/jre/../lib/$ 07-Feb-2011 17:05:46 org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8080 07-Feb-2011 17:05:46 org.apache.catalina.startup.Catalina load INFO: Initialization processed in 786 ms 07-Feb-2011 17:05:46 org.apache.catalina.core.StandardService start INFO: Starting service Catalina 07-Feb-2011 17:05:46 org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/6.0.29 07-Feb-2011 17:05:46 org.apache.catalina.startup.HostConfig deployDescriptor INFO: Deploying configuration descriptor host-manager.xml 07-Feb-2011 17:05:46 org.apache.catalina.startup.HostConfig deployDescriptor INFO: Deploying configuration descriptor ROOT.xml 07-Feb-2011 17:05:47 org.springframework.web.context.ContextLoader initWebApplicationContext INFO: Root WebApplicationContext: initialization started 07-Feb-2011 17:05:47 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing Root WebApplicationContext: startup date [Mon Feb 07 17:05:47 GMT 2011]; root of context hierarchy 07-Feb-2011 17:05:47 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml] 07-Feb-2011 17:05:47 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3cc70b0d: defining beans []; root of factory hierarchy 07-Feb-2011 17:05:47 org.springframework.web.context.ContextLoader initWebApplicationContext INFO: Root WebApplicationContext: initialization completed in 329 ms 07-Feb-2011 17:05:47 org.springframework.web.servlet.FrameworkServlet initServletBean INFO: FrameworkServlet 'dispatcher': initialization started 07-Feb-2011 17:05:47 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Mon Feb 07 17:05:47 GMT 2011]; parent: Root WebApplicationContext 07-Feb-2011 17:05:47 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] 07-Feb-2011 17:05:48 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@228b677f: defining beans [mainController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annot$ 07-Feb-2011 17:05:48 org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean createNativeEntityManagerFactory INFO: Building JPA container EntityManagerFactory for persistence unit 'NightOutPU' 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/main] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/main/*] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/index.htm] onto handler [org.springframework.web.servlet.mvc.ParameterizableViewController@4d3af084] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/addEditGroupEvent.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/groupEventSuccess.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/addEditAttendee.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/showAttendees.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/{attendeeId}/showAttendeeCalendar.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/{attendeeId}/update.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/{attendeeId}/update2.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/addEditGroupEvent.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/groupEventSuccess.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/addEditAttendee.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/showAttendees.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/{attendeeId}/showAttendeeCalendar.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/{attendeeId}/update.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/{groupEventUID}/{attendeeId}/update2.htm] onto handler [com.crowdbot.nightout.web.MainController@41a7c484] 07-Feb-2011 17:05:49 org.springframework.web.servlet.FrameworkServlet initServletBean INFO: FrameworkServlet 'dispatcher': initialization completed in 1909 ms 07-Feb-2011 17:05:49 org.apache.catalina.startup.HostConfig deployDescriptor INFO: Deploying configuration descriptor manager.xml 07-Feb-2011 17:05:49 org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory docs 07-Feb-2011 17:05:49 org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory examples 07-Feb-2011 17:05:49 org.apache.coyote.http11.Http11Protocol start INFO: Starting Coyote HTTP/1.1 on http-8080 </code></pre> <p>and here's the localhost log for the same period:</p> <pre><code>07-Feb-2011 17:05:47 org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext 07-Feb-2011 17:05:47 org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet 'dispatcher' 07-Feb-2011 17:05:49 org.apache.catalina.core.ApplicationContext log INFO: ContextListener: contextInitialized() 07-Feb-2011 17:05:49 org.apache.catalina.core.ApplicationContext log INFO: SessionListener: contextInitialized() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload