Child pages
  • SIP Groovlets

This documentation relates to last stable version of Cipango.
visit the last unstable documentation home.

Skip to end of metadata
Go to start of metadata

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

  1. 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>
    
  2. Add the scripts {requests.groovy}} and responses.groovy in WEB-INF/groovy.
  3. 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
request.addHeader("P-Asserted-Identity", "sip:bob@cipango.voip")
proxy()

response script adding a header and logging

responses.groovy
response.addHeader("Handled-By", "Cipango-Groovy")
println response
  • No labels