Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the request URI in Grails?

I've got a simple Grails app with the following RESTful uri...

http://localhost:8080/kennis-api/funds/test/700

The mapping in my URIMappings is

 "/funds/test/$fcode" (controller: "fundCache"){
    action = [GET: "show"]
 }

In my controller, I need to extract the request URI, in this case "/funds/test/700", but invoking request.uri or request.getRequestUri does not work. I tried using request.requestURL, but that gives me

http://localhost:8080/kennis-api/grails/fundCache/show.dispatch

Is there a special member or function from which to get the request uri?

like image 583
raffian Avatar asked Dec 06 '11 21:12

raffian


1 Answers

Its Simple, You need the Original address, that is same as the one where your response will be forwarded, its simply stored in the Request, and can be retrieved by: .

String originalURI = request.forwardURI  
//Do this where request is available, ex: Controllers :)
// Everywhere else you can use RequestContextHolder

.
.
Hope that helps Regards Kushal

like image 180
Kushal Likhi Avatar answered Sep 16 '22 21:09

Kushal Likhi