Class Groovy


  • public abstract class Groovy
    extends java.lang.Object
    Static methods for specialized Groovy integration.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Groovy.Ratpack
      The definition of a Groovy Ratpack application.
      static class  Groovy.Script
      Methods for working with Groovy scripts as application components.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ratpack.handling.Handler byContent​(ratpack.registry.Registry registry, Closure<?> closure)
      Builds a content negotiating handler.
      static ratpack.handling.Handler byMethod​(ratpack.registry.Registry registry, Closure<?> closure)
      Builds a multi method handler.
      static ratpack.func.Action<ratpack.handling.Chain> chain​(Closure<?> closure)
      Creates a chain action implementation from the given closure.
      static void chain​(ratpack.handling.Chain chain, Closure<?> closure)
      Immediately executes the given closure against the given chain, as a GroovyChain.
      static ratpack.handling.Handler chain​(ratpack.registry.Registry registry, Closure<?> closure)
      Builds a chain, backed by the given registry.
      static ratpack.handling.Handler chain​(ratpack.server.ServerConfig serverConfig, Closure<?> closure)
      Builds a handler chain, with no backing registry.
      static ratpack.handling.Handler chain​(ratpack.server.ServerConfig serverConfig, ratpack.registry.Registry registry, Closure<?> closure)
      Builds a chain, backed by the given registry.
      static ratpack.func.Action<ratpack.handling.Chain> chainAction​(Closure<?> closure)
      Creates a chain action based on the given closure.
      static ratpack.handling.Handler groovyHandler​(Closure<?> closure)
      Creates a handler instance from a closure.
      static MarkupTemplate groovyMarkupTemplate​(java.lang.String id)
      Creates a renderable Groovy based markup template, using no model and the default content type.
      static MarkupTemplate groovyMarkupTemplate​(java.lang.String id, java.lang.String type)
      Creates a renderable Groovy based markup template, using no model.
      static MarkupTemplate groovyMarkupTemplate​(java.lang.String id, java.lang.String type, ratpack.func.Action<? super com.google.common.collect.ImmutableMap.Builder<java.lang.String,​java.lang.Object>> modelBuilder)
      Creates a renderable Groovy based markup template.
      static MarkupTemplate groovyMarkupTemplate​(java.lang.String id, ratpack.func.Action<? super com.google.common.collect.ImmutableMap.Builder<java.lang.String,​java.lang.Object>> modelBuilder)
      Creates a renderable Groovy based markup template, using the default content type.
      static MarkupTemplate groovyMarkupTemplate​(java.util.Map<java.lang.String,​?> model, java.lang.String id)
      Creates a renderable Groovy based markup template, using the default content type.
      static MarkupTemplate groovyMarkupTemplate​(java.util.Map<java.lang.String,​?> model, java.lang.String id, java.lang.String type)
      Creates a renderable Groovy based template.
      static TextTemplate groovyTemplate​(java.lang.String id)
      Creates a renderable Groovy based template, using no model and the default content type.
      static TextTemplate groovyTemplate​(java.lang.String id, java.lang.String type)
      Creates a renderable Groovy based template, using no model.
      static TextTemplate groovyTemplate​(java.util.Map<java.lang.String,​?> model, java.lang.String id)
      Creates a renderable Groovy based template, using the default content type.
      static TextTemplate groovyTemplate​(java.util.Map<java.lang.String,​?> model, java.lang.String id, java.lang.String type)
      Creates a renderable Groovy based template.
      static Markup htmlBuilder​(Closure<?> closure)
      Shorthand for markupBuilder(CharSequence, Charset, Closure) with a content type of "text/html" and "UTF-8" encoding.
      static Markup markupBuilder​(java.lang.CharSequence contentType, java.lang.CharSequence encoding, Closure<?> closure)
      Renderable object for markup built using Groovy's MarkupBuilder.
      static Markup markupBuilder​(java.lang.CharSequence contentType, java.nio.charset.Charset encoding, Closure<?> closure)  
      static void ratpack​(Closure<?> closure)
      Starts a Ratpack app, defined by the given closure.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • ratpack

        public static void ratpack​(@DelegatesTo(value=Ratpack.class,strategy=1)
                                   Closure<?> closure)
        Starts a Ratpack app, defined by the given closure.

        This method is used in Ratpack scripts as the entry point.

         import ratpack.groovy.sql.SqlModule
         import static ratpack.groovy.Groovy.*
        
         ratpack {
           bindings {
             // example of registering a module
             add(new SqlModule())
           }
           handlers {
             // define the application handlers
             get("foo") {
               render "bar"
             }
           }
         }
         

        Standalone Scripts

        This method can be used by standalone scripts to start a Ratpack application. That is, you could save the above content in a file named “ratpack.groovy” (the name is irrelevant), then start the application by running `groovy ratpack.groovy` on the command line.

        Full Applications

        It's also possible to build Groovy Ratpack applications with a traditional class based entry point. The GroovyRatpackMain class provides such an entry point. In such a mode, a script like above is still used to define the application, but the script is no longer the entry point. Ratpack will manage the compilation and execution of the script internally.

        Parameters:
        closure - The definition closure, delegating to Groovy.Ratpack
      • chain

        public static ratpack.handling.Handler chain​(ratpack.server.ServerConfig serverConfig,
                                                     @DelegatesTo(value=GroovyChain.class,strategy=1)
                                                     Closure<?> closure)
                                              throws java.lang.Exception
        Builds a handler chain, with no backing registry.
        Parameters:
        serverConfig - The application server config
        closure - The chain definition
        Returns:
        A handler
        Throws:
        java.lang.Exception - any exception thrown by the given closure
      • chain

        public static ratpack.handling.Handler chain​(@Nullable
                                                     ratpack.server.ServerConfig serverConfig,
                                                     @Nullable
                                                     ratpack.registry.Registry registry,
                                                     @DelegatesTo(value=GroovyChain.class,strategy=1)
                                                     Closure<?> closure)
                                              throws java.lang.Exception
        Builds a chain, backed by the given registry.
        Parameters:
        serverConfig - The application server config
        registry - The registry.
        closure - The chain building closure.
        Returns:
        A handler
        Throws:
        java.lang.Exception - any exception thrown by the given closure
      • chain

        public static ratpack.handling.Handler chain​(ratpack.registry.Registry registry,
                                                     @DelegatesTo(value=GroovyChain.class,strategy=1)
                                                     Closure<?> closure)
                                              throws java.lang.Exception
        Builds a chain, backed by the given registry.
        Parameters:
        registry - The registry.
        closure - The chain building closure.
        Returns:
        A handler
        Throws:
        java.lang.Exception - any exception thrown by the given closure
      • chainAction

        public static ratpack.func.Action<ratpack.handling.Chain> chainAction​(@DelegatesTo(value=GroovyChain.class,strategy=1)
                                                                              Closure<?> closure)
        Creates a chain action based on the given closure.
        Parameters:
        closure - The chain building closure.
        Returns:
        A chain action
      • groovyTemplate

        public static TextTemplate groovyTemplate​(java.lang.String id)
        Creates a renderable Groovy based template, using no model and the default content type.
        Parameters:
        id - The id/name of the template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.lang.String id)
        Creates a renderable Groovy based markup template, using no model and the default content type.
        Parameters:
        id - The id/name of the template
        Returns:
        a template
      • groovyTemplate

        public static TextTemplate groovyTemplate​(java.lang.String id,
                                                  java.lang.String type)
        Creates a renderable Groovy based template, using no model.
        Parameters:
        id - The id/name of the template
        type - The content type of template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.lang.String id,
                                                          java.lang.String type)
        Creates a renderable Groovy based markup template, using no model.
        Parameters:
        id - The id/name of the template
        type - The content type of template
        Returns:
        a template
      • groovyTemplate

        public static TextTemplate groovyTemplate​(java.util.Map<java.lang.String,​?> model,
                                                  java.lang.String id)
        Creates a renderable Groovy based template, using the default content type.
        Parameters:
        model - The template model
        id - The id/name of the template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.util.Map<java.lang.String,​?> model,
                                                          java.lang.String id)
        Creates a renderable Groovy based markup template, using the default content type.
        Parameters:
        model - The template model
        id - The id/name of the template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.lang.String id,
                                                          ratpack.func.Action<? super com.google.common.collect.ImmutableMap.Builder<java.lang.String,​java.lang.Object>> modelBuilder)
        Creates a renderable Groovy based markup template, using the default content type.
        Parameters:
        id - the id/name of the template
        modelBuilder - an action the builds a model map
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.lang.String id,
                                                          java.lang.String type,
                                                          ratpack.func.Action<? super com.google.common.collect.ImmutableMap.Builder<java.lang.String,​java.lang.Object>> modelBuilder)
        Creates a renderable Groovy based markup template.
        Parameters:
        id - the id/name of the template
        type - The content type of template
        modelBuilder - an action the builds a model map
        Returns:
        a template
      • groovyTemplate

        public static TextTemplate groovyTemplate​(java.util.Map<java.lang.String,​?> model,
                                                  java.lang.String id,
                                                  java.lang.String type)
        Creates a renderable Groovy based template.
        Parameters:
        model - The template model
        id - The id/name of the template
        type - The content type of template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.util.Map<java.lang.String,​?> model,
                                                          java.lang.String id,
                                                          java.lang.String type)
        Creates a renderable Groovy based template.
        Parameters:
        model - The template model
        id - The id/name of the template
        type - The content type of template
        Returns:
        a template
      • groovyHandler

        public static ratpack.handling.Handler groovyHandler​(@DelegatesTo(value=GroovyContext.class,strategy=1)
                                                             Closure<?> closure)
        Creates a handler instance from a closure.
        Parameters:
        closure - The closure to convert to a handler
        Returns:
        The created handler
      • chain

        public static void chain​(ratpack.handling.Chain chain,
                                 @DelegatesTo(value=GroovyChain.class,strategy=1)
                                 Closure<?> closure)
                          throws java.lang.Exception
        Immediately executes the given closure against the given chain, as a GroovyChain.
        Parameters:
        chain - the chain to add handlers to
        closure - the definition of handlers to add
        Throws:
        java.lang.Exception - any exception thrown by closure
      • chain

        public static ratpack.func.Action<ratpack.handling.Chain> chain​(@DelegatesTo(value=GroovyChain.class,strategy=1)
                                                                        Closure<?> closure)
                                                                 throws java.lang.Exception
        Creates a chain action implementation from the given closure.
        Parameters:
        closure - the definition of handlers to add
        Returns:
        The created action
        Throws:
        java.lang.Exception - any exception thrown by closure
      • markupBuilder

        public static Markup markupBuilder​(java.lang.CharSequence contentType,
                                           java.lang.CharSequence encoding,
                                           @DelegatesTo(value=groovy.xml.MarkupBuilder.class,strategy=1)
                                           Closure<?> closure)
        Renderable object for markup built using Groovy's MarkupBuilder.
         import static ratpack.groovy.Groovy.markupBuilder
        
         get("some/path") {
           render markupBuilder("text/html", "UTF-8") {
             // MarkupBuilder DSL in here
           }
         }
         
        Parameters:
        contentType - The content type of the markup
        encoding - The character encoding of the markup
        closure - The definition of the markup
        Returns:
        A renderable object (i.e. to be used with the Context.render(Object) method
      • byContent

        public static ratpack.handling.Handler byContent​(ratpack.registry.Registry registry,
                                                         @DelegatesTo(value=GroovyByMethodSpec.class,strategy=1)
                                                         Closure<?> closure)
                                                  throws java.lang.Exception
        Builds a content negotiating handler.
        Parameters:
        registry - the registry to obtain handlers from for by-class lookups
        closure - the spec action
        Returns:
        a content negotiating handler
        Throws:
        java.lang.Exception - any thrown by action
        Since:
        1.5
      • byMethod

        public static ratpack.handling.Handler byMethod​(ratpack.registry.Registry registry,
                                                        @DelegatesTo(value=GroovyByContentSpec.class,strategy=1)
                                                        Closure<?> closure)
                                                 throws java.lang.Exception
        Builds a multi method handler.
        Parameters:
        registry - the registry to obtain handlers from for by-class lookups
        closure - the spec action
        Returns:
        a multi method handler
        Throws:
        java.lang.Exception - any thrown by action
        Since:
        1.5