Class GroovyChainAction

  • All Implemented Interfaces:
    Action<Chain>, GroovyChain, Chain

    public abstract class GroovyChainAction
    extends java.lang.Object
    implements GroovyChain, Action<Chain>
    A convenience super class for a standalone implementation of a Action<GroovyChain>.

    Subclasses implement the execute() method, and implicitly program against the GroovyChain DSL.

    
     import ratpack.groovy.handling.GroovyChainAction
     import ratpack.groovy.test.embed.GroovyEmbeddedApp
    
     class Handlers extends GroovyChainAction {
       public void execute() throws Exception {
         path { render "root" }
         prefix("foo") {
           path("bar") { render "foobar" }
         }
       }
     }
    
     GroovyEmbeddedApp.of {
       handlers new Handlers()
     } test {
       assert getText() == "root"
       assert getText("foo/bar") == "foobar"
     }
     
    • Constructor Detail

      • GroovyChainAction

        public GroovyChainAction()
    • Method Detail

      • execute

        public abstract void execute()
                              throws java.lang.Exception
        Defines the handler chain.
        Throws:
        java.lang.Exception - any
      • execute

        public final void execute​(Chain chain)
                           throws java.lang.Exception
        Invokes execute() while setting the given chain as the implicit receiver.
        Specified by:
        execute in interface Action<Chain>
        Parameters:
        chain - the handler chain
        Throws:
        java.lang.Exception - any
      • all

        public GroovyChain all​(Handler handler)
        Adds the given handler to this.
        Specified by:
        all in interface Chain
        Specified by:
        all in interface GroovyChain
        Parameters:
        handler - the handler to add
        Returns:
        this
      • getServerConfig

        public ServerConfig getServerConfig()
        The server config of the application that this chain is being created for.
        Specified by:
        getServerConfig in interface Chain
        Returns:
        The server config of the application that this chain is being created for.