title: 406 Not Acceptable in Spring MVC application (OSGi, Virgo Web Server) using Jackson, Rome and JAXB2
body: <p>I just started learning the Virgo Web Server.
  I'm trying to work with Jakcson JSON in Spring MVC application.
  At this stage I can not get a GET request serialized object.
  The server returns "406 Not Acceptable":</p>
  
  <pre><code>The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().
  </code></pre>
  
  <p>The same problem arises when using Rome and JAXB2.</p>
  
  <p>Here is the project configuration files and code:</p>
  
  <p>Fragment pom.xml:</p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
    &lt;artifactId&gt;com.springsource.org.codehaus.jackson&lt;/artifactId&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
    &lt;artifactId&gt;com.springsource.org.codehaus.jackson.mapper&lt;/artifactId&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>MANIFEST.MF</p>
  
  <pre><code>Manifest-Version: 1.0
  Import-Bundle: com.springsource.org.apache.taglibs.standard;version="[
   1.1.2,1.3)",com.springsource.org.codehaus.jackson;version="[1.0.0,1.0
   .0]",com.springsource.org.codehaus.jackson.mapper;version="[1.0.0,1.0
   .0]"
  Bundle-Version: 2.3.0
  Tool: Bundlor 1.0.0.RELEASE
  Bundle-Name: GreenPages Web
  Import-Library: org.springframework.spring;version="[3.0, 3.1)"
  Bundle-ManifestVersion: 2
  Bundle-SymbolicName: greenpages.web
  Web-ContextPath: greenpages
  Import-Package: javax.servlet.jsp.jstl.core;version="[1.1.2,1.2.0)",ja
   vax.sql,org.apache.commons.dbcp,org.eclipse.virgo.web.dm;version="[2.
   0.0, 3.0.0)",org.springframework.core.io;version="[3.0.0.RELEASE,3.1.
   0)",org.springframework.stereotype;version="[3.0.0.RELEASE,3.1.0)",or
   g.springframework.ui;version="[3.0.0.RELEASE,3.1.0)",org.springframew
   ork.web.bind.annotation;version="[3.0.0.RELEASE,3.1.0)",org.springfra
   mework.web.servlet.mvc.annotation;version="[3.0.0.RELEASE,3.1.0)",org
   .springframework.web.servlet.view;version="[3.0.0.RELEASE,3.1.0)"
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt;
  
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;/WEB-INF/pages/index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
    &lt;!-- CONFIGURE A PARENT APPLICATION CONTEXT --&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;contextClass&lt;/param-name&gt;
      &lt;param-value&gt;org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext&lt;/param-value&gt;
    &lt;/context-param&gt;
  
    &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
    &lt;/context-param&gt;
  
    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
  
    &lt;!-- DISPATCHER SERVLET CONFIG --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.htm&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>dispatcher-servlet.xml</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:context="http://www.springframework.org/schema/context"
         xmlns:mvc="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
      &lt;context:component-scan base-package="greenpages.web"/&gt;
  
      &lt;!-- Configures the @Controller programming model --&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/&gt;
  
      &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt;
          &lt;property name="prefix" value="/WEB-INF/pages/"/&gt;
          &lt;property name="suffix" value=".jsp"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>GreenPagesController.java</p>
  
  <pre><code>package greenpages.web;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  @Controller
  public class GreenPagesController {
  
   @RequestMapping("/home.htm")
   public void home() {
   }
  
   // MappingJacksonHttpMessageConverter (requires Jackson on the classpath - particularly useful for serving JavaScript clients that expect to work with JSON)
   @RequestMapping(value="/json.htm", method=RequestMethod.POST)
   public @ResponseBody String readJson(@RequestBody JavaBean bean) {
    return "Read from JSON " + bean;
   }
  
   @RequestMapping(value="/json.htm", method=RequestMethod.GET)
   public @ResponseBody Object writeJson() {
    return new Object();
   }
  
  }
  </code></pre>
  
  <p>index.jsp</p>
  
  <pre><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
  &lt;html&gt;
    &lt;head&gt;
     &lt;title&gt;Simple jsp page&lt;/title&gt;
     &lt;script type="text/javascript" src="/greenpages/scripts/jquery-1.4.4.min.js"&gt;&lt;/script&gt;
     &lt;script type="text/javascript"&gt;
    $.getJSON("json.htm", function(message) {
     console.log(message);
    });
     &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
    &lt;form action="test.htm" method="get"&gt;
        &lt;input type="text" name="name"&gt;
        &lt;input type="submit"&gt;
    &lt;/form&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>AJAX Request <a href="http://localhost:8080/greenpages/json.htm" rel="noreferrer">http://localhost:8080/greenpages/json.htm</a>:
  Request Headers from Firebug:</p>
  
  <pre><code>GET /greenpages/json.htm HTTP/1.1
  Host: localhost:8080
  User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12
  Accept: application/json, text/javascript, */*; q=0.01
  Accept-Language: en-us,en;q=0.5
  Accept-Encoding: gzip,deflate
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  Keep-Alive: 115
  Connection: keep-alive
  X-Requested-With: XMLHttpRequest
  Referer: http://localhost:8080/greenpages/
  Cookie: JSESSIONID=18000E4E096D7978F61F5D1E8105B784; JSESSIONID=35FB0925786699EC587A1B64F30517AD
  </code></pre>
  
  <p>Response Headers:</p>
  
  <pre><code>HTTP/1.1 406 Not Acceptable
  Server: Apache-Coyote/1.1
  Content-Type: text/html;charset=utf-8
  Content-Length: 1070
  Date: Tue, 07 Dec 2010 11:15:58 GMT
  </code></pre>
  
  <p>In what may be the problem?</p>