groovy.servlet
Class GroovyServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended bygroovy.servlet.GroovyServlet
All Implemented Interfaces:
ResourceConnector, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class GroovyServlet
extends javax.servlet.http.HttpServlet
implements ResourceConnector

This servlet will run Groovy scripts as Groovlets. Groovlets are scripts with these objects implicit in their scope:

Your script sources can be placed either in your web application's normal web root (allows for subdirectories) or in /WEB-INF/groovy/* (also allows subdirectories).

To make your web application more groovy, you must add the GroovyServlet to your application's web.xml configuration using any mapping you like, so long as it follows the pattern *.* (more on this below). Here is the web.xml entry:

    
      Groovy
      groovy.servlet.GroovyServlet
    

    
      Groovy
      *.groovy
    
 

The URL pattern does not require the "*.groovy" mapping. You can, for example, make it more Struts-like but groovy by making your mapping "*.gdo".

Whatever your mapping, the GroovyServlet will check to see if your URL ends with ".groovy" and, if it does not, it will strip your mapping and append ".groovy".

NOTE! The GroovyServlet only handles mappings of the *.* type, not the path-like type of /groovy/*

Author:
Sam Pullara, Mark Turansky (markturansky at hotmail.com), Guillaume Laforge
See Also:
Serialized Form

Field Summary
static java.lang.String GROOVY_EXTENSION
          A constant for ".groovy" which gets appended to script paths as needed.
private static GroovyScriptEngine gse
          The script engine executing the Groovy scripts for this servlet
private static java.lang.ClassLoader parent
          The classloader associated with this servlet
private  javax.servlet.ServletContext sc
          The context in which this servlet is executing
 
Fields inherited from class javax.servlet.http.HttpServlet
 
Fields inherited from class javax.servlet.GenericServlet
 
Constructor Summary
GroovyServlet()
           
 
Method Summary
private  java.lang.String getGroovyScriptPath(javax.servlet.http.HttpServletRequest request)
          From the HttpServletRequest, parse the groovy script path using the URL, adding the extension ".groovy" as needed.
 java.net.URLConnection getResourceConnection(java.lang.String name)
          Interface method for ResourceContainer.
 javax.servlet.ServletContext getServletContext()
          Returns the ServletContext for this servlet
 void init(javax.servlet.ServletConfig config)
          Initialize the GroovyServlet.
 void service(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          Handle web requests to the GroovyServlet
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROOVY_EXTENSION

public static final java.lang.String GROOVY_EXTENSION
A constant for ".groovy" which gets appended to script paths as needed.

See Also:
Constant Field Values

sc

private javax.servlet.ServletContext sc
The context in which this servlet is executing


parent

private static java.lang.ClassLoader parent
The classloader associated with this servlet


gse

private static GroovyScriptEngine gse
The script engine executing the Groovy scripts for this servlet

Constructor Detail

GroovyServlet

public GroovyServlet()
Method Detail

getServletContext

public javax.servlet.ServletContext getServletContext()
Returns the ServletContext for this servlet

Specified by:
getServletContext in interface javax.servlet.ServletConfig

init

public void init(javax.servlet.ServletConfig config)
Initialize the GroovyServlet.

Specified by:
init in interface javax.servlet.Servlet

getResourceConnection

public java.net.URLConnection getResourceConnection(java.lang.String name)
                                             throws ResourceException
Interface method for ResourceContainer. This is used by the GroovyScriptEngine.

Specified by:
getResourceConnection in interface ResourceConnector
Throws:
ResourceException

service

public void service(javax.servlet.ServletRequest request,
                    javax.servlet.ServletResponse response)
             throws javax.servlet.ServletException,
                    java.io.IOException
Handle web requests to the GroovyServlet

Specified by:
service in interface javax.servlet.Servlet
Throws:
javax.servlet.ServletException
java.io.IOException

getGroovyScriptPath

private java.lang.String getGroovyScriptPath(javax.servlet.http.HttpServletRequest request)
From the HttpServletRequest, parse the groovy script path using the URL, adding the extension ".groovy" as needed.



Copyright © 2003-2005 The Codehaus. All Rights Reserved.