-
Notifications
You must be signed in to change notification settings - Fork 16
Groovy
Using Groovy to create JAX-RS components
JAX-RS components may be written on Groovy. EverRest supports deploy Groovy scripts as JAX-RS components in runtime. It is not necassery to compile Groovy code just need set of location of Groovy file which contains class that extends subclass of javax.ws.rs.core.Application
.
There is example of web.xml
file:
<context-param>
<param-name>org.everrest.groovy.Application</param-name>
<param-value>org.everrest.example.GroovyApplication</param-value>
</context-param>
<context-param>
<param-name>org.everrest.groovy.root.resources</param-name>
<param-value>file:/home/Andrey/temp/groovy</param-value>
</context-param>
<listener>
<listener-class>org.everrest.core.servlet.EverrestInitializedListener</listener-class>
</listener>
<listener>
<listener-class>org.everrest.groovy.servlet.GroovyEverrestInitializedListener</listener-class>
</listener>
<servlet>
<servlet-name>EverrestServlet</servlet-name>
<servlet-class>org.everrest.core.servlet.EverrestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EverrestServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
It is close to web.xml
in Servlets Integration but contains some specific parameters and web components.
Parameter name | Default value | Description |
---|---|---|
org.everrest.groovy.Application | none | Full qualified name of Groovy or Java class which is subclass of javax.ws.rs.core.Application
|
org.everrest.groovy.root.resources | none | URL(s) that should be used as base URLs (local or remote) for look up Groovy resources (scripts). It is similar as class-path in Java. This URL(s) must be set in form described in URL specification. It is possible to set multiple URLs. In this case they must be set as string with comma (',') as delimiter. |
org.everrest.groovy.scan.components | false | Scan of Groovy classes with @Path , @Provider and @org.everrest.core.Filter annotations. URLs specified by org.everrest.groovy.root.resources parameter will be used as start points for look up. Note: scanning of Groovy components supported only for local file system by default (for URL that starts as file: ). To be able scan URL with different protocols you need implement interface org.everrest.groovy.ScriptFinder and register it in org.everrest.groovy.ScriptFinderFactory by using method addScriptFinder(String protocol, ScriptFinder finder)
|
Listener org.everrest.groovy.servlet.GroovyEverrestInitializedListener
will instantiate class specified in org.everrest.groovy.Application
parameter or look up all scripts that contains classes with JAX-RS annotation and register it in EverRest framework. This listener must be configured after org.everrest.core.servlet.EverrestInitializedListener
.
Example of using Groovy and EverRest can be found at subversion repository, see project everrest/everrest-samples/groovy-book-service
. You can simple run it with command: mvn jetty:run
.
See details how-to try example in README.html in correspond project.