Thomas Buckley
Thomas Buckley

Reputation: 6056

Redirect service requests to another server

I've created a filter so that I can intercept all controller actions and forward the request to a different server. I need to temporarily redirect based on user-agent.

So I have the following in http://www.mysite1.com

class DealsFilters {

    def filters = {
    all(controller: '*', action: '*') {
        before = {
                if (someConditionHere)
                {
                    redirect(url:"http://www.mysite2/")
                    return
                }               
        }
    }       
}

What I am wondering is will the request and all it params be correctly passed to mysite2?
i.e. mysite1 acts as a service and receives requests to get user data, update deals, add new users, etc...

mysite2 is a new version of mysite1 (mysite1 will be decommisioned after mysite2 has been tested).

Is it as simple as a redirect?

Thanks

Upvotes: 3

Views: 2166

Answers (2)

Thomas Buckley
Thomas Buckley

Reputation: 6056

I'm using grails 1.3.7 as pointed out to lucke84 (I should have stated this in original question).

Found following link gave me most of the answer:
Best practice for redirecting from one web domain to another in Grails?

redirect(url:"http://localhost:8080${request.forwardURI}?${request.queryString}",params:params)

Upvotes: 3

lucke84
lucke84

Reputation: 4636

The documentation says that if you perform a redirect with the url parameter, your url should contain all the information needed to send the new request.

I guess you should recreate your url, more or less like this:

redirect(base: 'http://www.mysite2/', controller: params.controller, action: params.action, params: params)

Not tested, but it should work for most of the cases. Let me know :)

Upvotes: 1

Related Questions