0

I need to send a value like app/role as parameter through rest webservice url from angularjs

In controller.js

var roleName = 'app/role';
checkRole.check({'roleName': roleName}, function(data){}

In model.js

popModel.factory('checkRole', function ($resource) {    
    return  $resource('./rest/checkRole/:roleName',{roleName:'@roleName'},{
        check: {'method':'GET'},
    });
});

The rest webservice call in java

    @GET
    @Path("/checkRole/{roleName}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response checkRole(@Context HttpServletRequest request, @PathParam("roleName") String roleName);

When i pass it i am getting browser console error as

Bad request response from the server.

For normal parameter values like 'Test', 'Solution', 'Application' etc. If i use with / as a parameter no process is done and i am getting error.

Manoj Kumar
  • 41
  • 1
  • 10
  • Tested with your exact code and works fine for me. Angular just encodes the slash. And using Jersey, Jersey decodes it when it comes in. – Paul Samsotha Mar 11 '16 at 07:19

1 Answers1

0

/ is reserved character for GET request. So, you can't use them directly. If you use them, you would get Bad Request Error.

One of the solution can be to encode the URL on client side and decode it on server.

Reference:
Characters allowed in GET parameter
How to handle special characters in url as parameter values?

Community
  • 1
  • 1
Mukesh Sharma
  • 8,914
  • 8
  • 38
  • 55