Overview
Groovy is an agile dynamic language for the Java Platform.
Cipango team has developped an extension to be able to write SIP Servlets application using Groovy scripts.
This extension use two Groovy scripts:
- One for handling javax.servlet.sip.SipServletRequest. If the init parameter <code>request.script</code> is set, then the script is relative to /WEB-INF/groovy/. Else the default location /WEB-INF/groovy/requests.groovy is used.
- One for handling javax.servlet.sip.SipServletResponse. If the init parameter response.script is set, then the script is relative to /WEB-INF/groovy/. Else the default location /WEB-INF/groovy/responses.groovy is used.
Configuration
Setting up SIP groovlets
- Put the following in your sip.xml:
sip.xml
- Add the scripts {requests.groovy}} and responses.groovy in WEB-INF/groovy.
- Add groovy-all-xyz.jar and cipango-groovy-xyz.jar into WEB-INF/lib.
Implicit variables
The following variables are ready for use in SIP Groovlets:
| name | bound to | Scope (in which script) |
|---|---|---|
| request | the SipServletRequest object | request |
| params | Map of all request parameters | request |
| response | the SipServletResponse object | response |
| context | the ServletContext object | all |
| session | the SipSession object | all |
| factory | the SipFactory object | all |
Methods
| name | shorthand to | Scope (in which script) |
|---|---|---|
| proxy() | request.getProxy().proxyTo(request.getRequestURI()); | request |
| proxy(String uri) | proxy(sipFactory.createURI()); | request |
| proxy(URI) | request.getProxy().proxyTo(uri); | request |
| sendResponse(int status) | request.createResponse(status).send(); | request |
| sendResponse(int status, String reason) | request.createResponse(status, reason).send(); | request |
| pushRoute(String route) | request.pushRoute(sipFactory.createAddress(route)); | request |
Examples
request script adding a header and proxy the request
requests.groovy
response script adding a header and logging
responses.groovy
Labels:
None
