Spring Integration

=
=20

When Spring's ApplicationContext is provided, GroovyRestlet=
will try to consult Spring context for creating its components. Two =
special attributes are provided for integrating GroovyRestlet =
and Spring.

=20

=20

ofBean: to tell GroovyRestlet that to cre=
ate a component from Spring context by a bean name;

GroovyRestlet will only use AutowireCapableBeanFactory to c=
reate instance indicated by ofClass when Spring context is=
provided. Otherwise it will create an instance of that class using Java re=
flection

=20

=20

=20

=20

Technical detail

=20

GroovyRestlet<=
/h3>=20

As the only entry point of GroovyRestlet, this instance automatically de=
clares a number of global variables in the Groovy context. Users are also b=
e able to provide their special context variables. In order to do that, use=
rs can provide a map of customer context when calling build me=
thod.

=20

=20

groovyRestlet.build(userDefinedContext, scriptURI);

=20

=20

=20

Be careful

=20
Icon=20

=20

This userDefinedContext is only visible for each call o=
f build method. It will be merged into Groovy context and removed after eac=
h calling. And variables of userDefinedContext can overrid=
e values of default context. Be careful when doing this.

=20

=20

=20

RestletBuilder

=20

RestletBuilder is a simple implementation of Groovy's Facto=
ryBuilderSupport. By default, all constructor factories are registered. Use=
rs are able choose which constructors are to be used freely.

=20

To do this programmatically, just set a list of constructor factories af=
ter a build instance is created.

At current moment, you can call global.status(404) to creat=
e a CLIENT_ERROR_NOT_FOUND status.

=20

Constructors

=20

Every constructor is support ofBean and ofClass=
attributes. The value of ofBean must be a Sting.=
ofBean is only effected when a Spring context is provided=
. The value of ofClass can either be a String or an instan=
ce of Java Class.

=20

According to Groovy Builders, c=
onstructors can be nested to each other. In that case, GroovyRestlet will a=
utomatically set up Restlet-specific relationship between parent and child =
instances. But user can disable this feature by setting autoAttach<=
/strong> attribute as false.

=20

In Restlet, the Router.attach method returns a Route instance. In order =
to do some special process on the Route instance, an attribute post=
Attach which refers to a Groovy closure is provided. For example:<=
/p>=20

Another important attribute is uri which indicates a URI Template using =
by Restlet Router.

=20

restlet

=20

The generic constructor for all components of type of Restlet. You can use ofClass attribute to indicate restlet to create an instance of a =
subtype. When doing that, using attribute consArgs to prov=
ide arguments array of corresponding constructor. For example:

Sometimes it is necessary to access the instance of Restlet itself. You =
can do that by appending an additional argument in the closure argument lis=
t. GroovyRestlet will automatically pass the calling instance to the closur=
e as shown in above example.

=20

=20
Icon=20

=20

This handle attribute is only effected when neither ofClass nor ofBean attribute is used.

=20

=20

=20

server

=20

A shortcut to create a Restlet Server. Instance of the nested constructo=
r of a server will become the server's target. If more =
nested constructors are defined, only the last one will be selected.

=20

Attributes:

=20

=20

protocol: the server protocol

=20

protocols: a list of server protocols

=20

address: the address of server

=20

port: the port of server

=20

=20

client

=20

A shortcut to create a Restlet Client.

=20

Attributes:

=20

=20

protocol: the client protocol

=20

protocols: a list of client protocols

=20

=20

component

=20

A shortcut to create a Restlet Component. If no VirtualHost is specified=
, direct children of component constructor will be attached to Component's =
default =
VirtualHost. For example,

application

=
=20

A shortcut to create a Restlet Application. The direct child of applicat=
ion constructor, without attribute autoAttach as fal=
se, will be set as the root of the application instance. If more direct neste=
d constructors are defined, only the last one will be selected.

=20

router

=20

A shortcut to create a Restlet Router. A router constructor can have one=
or more nested children. Each child will be attached to the router by call=
ing Router.attach method.

=20

filter

=20

A shortcut to create a Restlet Filter.

=20

Attributes

=20

=20

before: a closure to be called when Filter.befor=
eHandle is called;

=20

after: a closure to be called when Filter.afterH=
andle is called;

=20

handle: a closure to be called when Filter.doHan=
dle is called;

=20

=20

redirector

=
=20

A shortcut to create a Restlet Redirector.

=20

guard

=20

A shortcut to create a Restlet Guard.

=20

Attributes

=20

=20

scheme: the challenge scheme, will use Chanlleng=
eScheme.valueOf("None") if no scheme is p=
rovided;

=20

realm: the authentication realm

=20

=20

directory

=20

A shortcut to create a Restlet Directory. A directory constructor can no=
t nest child.

=20

Attributes:

=20

=20

root: the root uri of the Directory

=20

=20

resource

=20

A shortcut to create a Restlet Resource. A resource constructor can not =
nest child; and it can be nested in filter and router.