Pigasus
Pigasus

Reputation: 130

Groovy REST URL mapping containing forward slashes

I have a REST service in Groovy on Grails; basic service that takes data and transforms it. It works fine except when the data being passed in has forward or back slashes. In those cases the browser tries to navigate to a directory based on the data:

localhost/traverse/map/321 64 fourth <<< this works fine
localhost/traverse/map/321/64/fourth <<< tries to find localhost/traverse/map/321/64/fourth and throws an http status 404

My urlmapping:

"map/$id" (controller: "map", action: "transform", formats=['text/plain'], method: "GET")

My controller. aside from the class declaration and class import nothing else going on:

def transform = {
  //println params.id
  if (param.id) {
    DataMap dm = new DataMap();
    render dm.hostNodeLookup(params.id)
  }
}

Most of the data that will be passed to the REST service will have slashes and the number of slashes per "data being passed in" will vary from 1-N but I haven't been able to figure out how to escape/parse/other wise get around that issue. I've read up on this site but I didn't find it too helpful for this problem.

I do not have access to the web server to adjust encoding or how browsers render URL mappings and strings. The data doesn't get to the controller so I haven't been able to parse out the strings there. Anyone have ideas?

Upvotes: 1

Views: 527

Answers (1)

Pigasus
Pigasus

Reputation: 130

After reading this post I tried it and it worked like a charm.

In the urlmapping file I added this ** to the id variable:

"map/$id**" (controller: "map", action: "transform", formats=['text/plain'], method: "GET")

Upvotes: 1

Related Questions