Grails overrides controller redirection method

I am trying to override the default controller redirect method and cannot seem to use the next bit of code.

I created a plugin and I'm trying to use "doWithDynamicMethods" to replace the redirect.

def doWithDynamicMethods = {ctx ->
   application.controllerClasses.each() { controllerClass ->
      replaceRedirectMethod(controllerClass)
   }
}

void replaceRedirectMethod(controllerClass) {
   def oldRedirect = controllerClass.metaClass.pickMethod("redirect", [Map] as Class[])
   controllerClass.metaClass.redirect = { Map args, Map params ->
      // never seems to get here    
   }
}

Do I have a wrong signature or am I missing something? The reason I do this is to change the redirect uri if a certain condition is met, but with logging / printing operators. I see that it starts in "replaceRedirectMethod" when starting / compiling applications, but it doesn’t work. "Enter there when you redirect through the controller after the application starts.

+5
source share
2

, - Map (. org.codehaus.groovy.grails.plugins.web.ControllersGrailsPlugin.registerControllerMethods())

controllerClass.metaClass.redirect = { Map args ->
   // pre-redirect logic
   oldRedirect.invoke delegate, args
   // post-redirect logic
}
+3

, , redirect , :

def watchedResources = [
  "file:./grails-app/controllers/**/*Controller.groovy"]

def onChange = { event ->
  if(!(event.source instanceof Class)) return

  if(application.isArtefactOfType(ControllerArtefactHandler.TYPE, event.source))
  {
    replaceRedirectMethod(application.getArtefact(ControllerArtefactHandler.TYPE,
                                                  event.source.name))
  }
}
0

All Articles