This documentation relates to last stable version of Cipango.
visit the last unstable documentation home.
SIP Groovlets
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 parameterresponse.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
<sipapp> ... <servlet> <servlet-name>groovy</servlet-name> <servlet-class>org.cipango.groovy.GroovyServlet</servlet-class> <init-param> <param-name>defaultScript</param-name> <param-value>addHeader.groovy</param-value> </init-param> <load-on-startup/> </servlet> </sipapp>
- Add the scripts {requests.groovy}} and
responses.groovy
inWEB-INF/groovy
. - Add
groovy-all-xyz.jar
andcipango-groovy-xyz.jar
intoWEB-INF/lib
.
Implicit variables
The following variables are ready for use in SIP Groovlets:
name |
bound to |
Scope (in which script) |
---|---|---|
request |
the |
request |
params |
Map of all request parameters |
request |
response |
the |
response |
context |
the |
all |
session |
the |
all |
factory |
the |
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
request.addHeader("P-Asserted-Identity", "sip:bob@cipango.voip") proxy()
response script adding a header and logging
response.addHeader("Handled-By", "Cipango-Groovy") println response