-1

I am trying to achieve a REST web service api with spring and i am getting error 400 Bad request I think its about dispatcher configuration, I have read a lot of post and try different thing but couldn't fix the issue.

here the RequestMapping :

@Override
@RequestMapping(value=ServerPushApi.CREATE_PATH, method=RequestMethod.POST)
public @ResponseBody Status createNote(@RequestBody Note note) {
    if(note != null){
        db.storeNote(note);
        return Status.Ok;
    }
    return Status.Fail;
}

Here the dispatcher :

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"

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">

<context:component-scan base-package="ch.epfl.sweng.bogocoders.server" />    
<bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="order" value="1" />
    <property name="mediaTypes">
        <map>
            <entry key="json" value="application/json" />
        </map>
    </property>
    <property name="defaultViews">
        <list>
            <!-- JSON View -->
            <bean
                class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
        </list>
    </property>
    <property name="ignoreAcceptHeader" value="true" />
</bean>
</beans>

and finally the configuration file :

<dependencies>
    <!-- Compile/runtime dependencies -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>1.9.13</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>com.squareup.retrofit</groupId>
        <artifactId>retrofit</artifactId>
        <version>1.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-rest-webmvc</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>1.1.8.RELEASE</version>
    </dependency>
    <!-- Jackson JSON Mapper -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.11</version>
    </dependency>


    <!-- Test Dependencies -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-testing</artifactId>
        <version>1.9.13</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-stubs</artifactId>
        <version>1.9.13</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
        <version>1.1.8.RELEASE</version>
    </dependency>
</dependencies>

Thanks for the help.

afgbloch
  • 1
  • 4
  • The most probable reason could be either your request doesn't matches with the one sevice expect or there is some issue while message translation. First check you request header and verify , if everything is correct then try enable verbose logging of spring, make the logger level to trace and you will be able se see the exact error message. – VGaur Oct 19 '14 at 09:23
  • how exactly do you call it? Share body and headers of your POST message – hi_my_name_is Oct 19 '14 at 12:27

1 Answers1

0

I change the logger level like VGaur ask me to do, and manage to find my problem on other post,

I have a constructor issue : explain here And I have a problem with Json translation that I modified with : here

Community
  • 1
  • 1
afgbloch
  • 1
  • 4