rest - Spring 3.1.1 and json getting error 406 -


i have written simple rest based controller using @responsebody expect return json. somehow not able work expected. when run url "http://localhost:8080/my-webapp/amazon/rips" ..it throws below error

http status 406 -jbweb000126: resource identified request capable of generating responses characteristics not acceptable according request 'accept' headers. can please lend helping hand.

mycontroller below:

@controller @requestmapping("/amazon") public class jsoncontroller {  @requestmapping(value="/{name}", method = requestmethod.get,produces = "application/json") public @responsebody book getshopinjson(@pathvariable string name) {      book book = new book();     book.setname(name);     book.setavailablity(false);      return book;  } 

book class below:

public class book {  public string getname() {     return name; }  public void setname(string name) {     this.name = name; }  public boolean isavailablity() {     return availablity; }  public void setavailablity(boolean availablity) {     this.availablity = availablity; }  private string name ; private boolean availablity; 

}

displatcher servlet below:

<beans xmlns="http://www.springframework.org/schema/beans"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"    xsi:schemalocation="     http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.1.xsd">  <context:component-scan base-package="com.rips.controller" />  <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">     <property name="prefix">         <value>/web-inf/pages/</value>     </property>     <property name="suffix">         <value>.jsp</value>     </property> </bean> 

<dependencies>   <dependency>       <groupid>org.springframework</groupid>       <artifactid>spring-jms</artifactid>       <version>3.1.1.release</version>   </dependency>   <dependency>       <groupid>org.springframework</groupid>       <artifactid>spring-webmvc</artifactid>       <version>3.1.1.release</version>   </dependency>    <dependency>       <groupid>org.springframework</groupid>       <artifactid>spring-web</artifactid>       <version>3.1.1.release</version>   </dependency>    <dependency>       <groupid>junit</groupid>       <artifactid>junit</artifactid>       <version>3.8.1</version>       <scope>test</scope>   </dependency>    <dependency>       <groupid>org.codehaus.jackson</groupid>       <artifactid>jackson-mapper-asl</artifactid>       <version>${jackson.version}</version>   </dependency>   <dependency>       <groupid>org.codehaus.jackson</groupid>       <artifactid>jackson-core-asl</artifactid>       <version>${jackson.version}</version>   </dependency> 

with @codechimp realized request sending not having proper accept headers. used chromes "advanced rest client" , added headers key ="accept" , value ="application/json",i able proper response.

update found <mvc:annotation-driven /> not added in dispatcher servlet configures support http message conversion @requestbody/@responsebody.once added piece of info there no need use advanced rest client.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -