1 Reply Latest reply on Jul 9, 2009 6:23 AM by mhiggins.matt.smartdestinations.com

    403 Rest service seam 2.1.2 GA

    mhiggins.matt.smartdestinations.com
      I am having trouble building a simple rest service in seam 2.1.2. I can reach the resource and the function is executed as I can see my hibernate query and a simple log line. The server returns a 403 "Access to the requested resource has been denied" I don't have any security configured around the resources. I can get to other resources such as js.  Here is the code for the rest resource.

      @Path("/user")
      @Name("userResource")
      public class UserResource {

           @Logger
           Log log;
           
           @In(create=true)
           UserService userService;
           
           @RequestParameter
           String username;
           
           @RequestParameter
           String password;
           

           @GET
           @Path("/favorites")
           @Produces("text/xml")
           public User getFavorites(){
                User user = getUser();
                log.info("in get favorites");
                return user;
           }

           
           
           private User getUser() {
                User user = userService.findUserByUnameOrEmail(username, username);
                if(userService.validatePassword(user, password)){
                     return user;
                }
                return null;
           }     
      }
        • 1. Re: 403 Rest service seam 2.1.2 GA
          mhiggins.matt.smartdestinations.com

          Looks like you can't use @RequestParameter. I updated my @Path annotations and used @PathParam to get the username and password. I suppose this is more rest like anyway but this was my first experiment.


          my class now looks like this for anyone who has had this problem

          @Path("/user/{username}/{password}")
          @Name("userResource")
          public class UserResource {

               @Logger
               Log log;
               
               @In(create=true)
               UserService userService;
               
               @GET
               @Path("/favorite")
               @Produces("text/xml")
               public Set<Venue> getFavorites(@PathParam("username") String username , @PathParam("password")  String password){
                    User user = userService.findUserByUnameOrEmail(username, username);
                    if(userService.validatePassword(user, password)){
                         return user.getProfile().getFavorites();
                    }
                    return new HashSet<Venue>();
               }

               
               
          }