Pregunta

I'm simply trying to get userdata via controller service interface But I'm always getting

[WARN] 400 - GET /user/%7Bid%7D (127.0.0.1) 1403 bytes

My Controller:

@Controller
@RequestMapping(value ="/user")
public class AdminSpringController {

@RequestMapping( value = "/{id}", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public @ResponseBody GWTUser getUser(@PathVariable Integer id) throws NotFoundException {
...
}

}

My Service, it's a restygwt interface:

@Path("/user")
public interface UserAdminRestService extends RestService {

@GET
    @Path("/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public void getUser(Integer id, MethodCallback<GWTUser> callback);
}

My servlet:

<servlet>
    <servlet-name>userService</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/classes/servlet/userService-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>userService</servlet-name>   
    <url-pattern>/</url-pattern>
  </servlet-mapping>

My servlet.xml

<context:component-scan base-package="com.app.admin.controller" />

    <tx:annotation-driven />

    <mvc:annotation-driven />

    <!--This tag allows for mapping the DispatcherServlet to "/" (all extensions etc) -->
    <mvc:default-servlet-handler/> 


    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />             
            </list>
        </property>
    </bean>

I Already have a method (user/users which returns all users, it's working fine but I think the problem is with my {id} (parameter variable), because it seems that my service or something parses my {id} as you can see at my error /user/%7Bid%7D. Thx for any help.

¿Fue útil?

Solución

Missing @PathParam("id") in the service interface was the problem.

public void getUser(@PathParam("id") Integer id, MethodCallback<GWTUser> callback);

And for example UPDATE:

@PUT
@Path("/update")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void update(GWTUser user, MethodCallback<UserServiceResponse> callback);

you need to set the RequestBody

@RequestMapping( value = "/update", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
public void update(@RequestBody GWTUser gwtUser) {
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top