Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » 406 Not Acceptable Jackson JSON in Virgo Web Server
406 Not Acceptable Jackson JSON in Virgo Web Server [message #643250] Mon, 06 December 2010 04:41 Go to next message
Alexey  is currently offline Alexey
Messages: 6
Registered: November 2010
Junior Member
Hi, 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":
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().
Here is the project configuration files and code:

Fragment pom.xml:
<dependency>
  <groupId>org.codehaus.jackson</groupId>
  <artifactId>com.springsource.org.codehaus.jackson</artifactId>
  <version>1.0.0</version>
</dependency>
<dependency>
  <groupId>org.codehaus.jackson</groupId>
  <artifactId>com.springsource.org.codehaus.jackson.mapper</artifactId>
  <version>1.0.0</version>
</dependency>


MANIFEST.MF
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)"


web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<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">

  <welcome-file-list>
    <welcome-file>/WEB-INF/pages/index.jsp</welcome-file>
  </welcome-file-list>

  <!-- CONFIGURE A PARENT APPLICATION CONTEXT -->
  <context-param>
    <param-name>contextClass</param-name>
    <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
  </context-param>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- DISPATCHER SERVLET CONFIG -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

</web-app>


dispatcher-servlet.xml
<?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/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">

    <context:component-scan base-package="greenpages.web"/>

    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>


GreenPagesController.java
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();
	}

}


index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
  	<title>Simple jsp page</title>
  	<script type="text/javascript" src="/greenpages/scripts/jquery-1.4.4.min.js"></script>
  	<script type="text/javascript">
		$.getJSON("json.htm", function(message) {
			console.log(message);
		});
  	</script>
  </head>
  <body>

  <form action="test.htm" method="get">
      <input type="text" name="name">
      <input type="submit">
  </form>

  </body>
</html>


http://farm6.static.flickr.com/5122/5237671086_3ac6415511_z.jpg

In what may be the problem?

[Updated on: Fri, 10 December 2010 04:40]

Report message to a moderator

Re: 406 Not Acceptable Jackson JSON in Virgo Web Server [message #643501 is a reply to message #643250] Tue, 07 December 2010 02:22 Go to previous messageGo to next message
Alexey  is currently offline Alexey
Messages: 6
Registered: November 2010
Junior Member
The same problem arises when using Rome and JAXB2. HTTP Status 406
Re: 406 Not Acceptable Jackson JSON in Virgo Web Server [message #643761 is a reply to message #643501] Wed, 08 December 2010 03:22 Go to previous messageGo to next message
Violeta Georgieva is currently offline Violeta Georgieva
Messages: 214
Registered: October 2010
Senior Member
Hi,

Can you give the dispatcher-servlet.xml content.
It seems that the one above is not the correct one (seems to be the web.xml?)

Regards,
Violeta
Re: 406 Not Acceptable Jackson JSON in Virgo Web Server [message #644259 is a reply to message #643761] Fri, 10 December 2010 04:42 Go to previous messageGo to next message
Alexey  is currently offline Alexey
Messages: 6
Registered: November 2010
Junior Member
Posted the wrong file in the dispatcher-servlet.xml, edited. Thanks
Re: 406 Not Acceptable Jackson JSON in Virgo Web Server [message #644923 is a reply to message #644259] Tue, 14 December 2010 14:17 Go to previous messageGo to next message
Violeta Georgieva is currently offline Violeta Georgieva
Messages: 214
Registered: October 2010
Senior Member
Hi,

I think that you are using wrong xml schema in the dispatcher-servlet.xml

you are using

xmlns:mvc="http://www.springframework.org/schema/tx


but I think that the correct one is

xmlns:mvc="http://www.springframework.org/schema/mvc


the schemas should look like this

<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.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd">


Can you try changing this and tell us what is the result.

Regards
Violeta
Re: 406 Not Acceptable Jackson JSON in Virgo Web Server [message #645478 is a reply to message #644923] Fri, 17 December 2010 06:33 Go to previous messageGo to next message
Alexey  is currently offline Alexey
Messages: 6
Registered: November 2010
Junior Member
Yes, it helped. Now everything works. Thank you very much. Спасибо)
Re: 406 Not Acceptable Jackson JSON in Virgo Web Server [message #849584 is a reply to message #645478] Thu, 19 April 2012 05:17 Go to previous message
rajkumar Mundel is currently offline rajkumar Mundel
Messages: 1
Registered: April 2012
Junior Member
Hi All,

I am getting same error
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().

Apache Tomcat/7.0.23

Attach are the files

1.dispatcher-servlet.xml
2.RegionCountry.jsp
3.RegionCountryController


Please help its urgent
Previous Topic:Failed to activate Greenpages Sample in Virgo 3.0.2
Next Topic:Developing with Virgo Using Maven/m2Eclipse
Goto Forum:
  


Current Time: Sun Apr 20 03:02:45 EDT 2014

Powered by FUDForum. Page generated in 0.02486 seconds