Date: Tue, 19 Mar 2024 03:55:44 +0000 (UTC) Message-ID: <1241660101.35.1710820544411@959f4149a2c2> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_34_913943856.1710820544411" ------=_Part_34_913943856.1710820544411 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
In this tutorial, we'll show you how to develop a first SIP Serv= lets application in a few minutes using a Maven Archetype. If you run into = any issue during this tutorial, please feel free to ask for help on the cipango-users list.
Maven is a project management, build and deployment tool developed by th= e Apache foundation. It has become the de-facto standard for Java developme= nt lifecycle management, it is used by most open source projects and is ado= pted also by many software companies.
To install Maven and find out how to use it, a good starting point is:= p>
We'll assume now that you have Maven installed on your system.
Maven archetypes are project templates, somewhat similar to IDE wizards.= They provide a quick and easy way to get a working Maven project with all = the needed dependencies and the required structure. We'll use a SIP Servlet= s specific archetype provided by Cipango to create our first application.= p>
To use a cipango-provided archetype, simply type:
mvn arc= hetype:generate -DarchetypeCatalog=3Dhttp://repository.cipango.org
You should then see an output similar to:
[INFO]= Scanning for projects... [INFO] [INFO] --------------------------------------------------------------------= ---- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------------------------------------------= ---- [INFO] [INFO] >>> maven-archetype-plugin:2.0:generate (default-cli) @ sta= ndalone-pom >>> [INFO] [INFO] <<< maven-archetype-plugin:2.0:generate (default-cli) @ sta= ndalone-pom <<< [INFO] [INFO] --- maven-archetype-plugin:2.0:generate (default-cli) @ standalone-p= om --- [INFO] Generating project in Interactive mode [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.m= aven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: 1: http://repository.cipango.org -> maven-archetype-si= papp (Sample Sip Servlets Application Maven Archetype)
Choose archetype 1, you are then asked to enter the three required field= s for a Maven project. These are:
groupId
: unique identifier amongst an organization or proj=
ect, for instance: org.cipango
artifactId
: it is generally the name that the project is k=
nown by, for instance: my-first-app
versionId
: version of your project. You may leave it empty=
to use default value.You are then asked for the package name, which is simply the package to =
use for the Java sources. By default, it is equal to the groupId.
You have then to confirm and you're done ! The project is being created in=
a directory named after your project name (given artifactId). You should h=
ave now a directory structure similar to this one:
$ tree = my-first-app/ my-first-app/ |-- pom.xml `-- src `-- main |-- java | `-- org | `-- cipango | `-- MainServlet.java |-- resources `-- webapp `-- WEB-INF |-- sip.xml `-- web.xml
The MainServlet.java
is a simple SIP servlet which answers =
to incoming OPTIONS
message with a header indicating the serve=
r version.
The archetype created the Maven project as well as a SIP Application with =
the servlet and deployment descriptors. To build the application, simply cd=
to the created directory and enter:
mvn ins= tall
If you have just installed Maven on your system, do not worry if the fir= st build is rather long. Maven has a very modular architecture and download= s required modules only when needed. As a result, first uses of Maven gener= ally lead to a lot of downloads. Once everything installed, subsequent runs= are way faster.
When the build ends, you should see BUILD SUCCESSFUL
at the=
end of the output. The SIP Application is now built and packaged as a .war=
in the target directory.
You can now deploy the SIP Application in your preferred SIP Servlets co= ntainer. To quickly test it, we'll skip this step and use the Cipango Maven Plugin. It consists i= n a Maven plugin which embeds a Cipango Application Server and allows to ru= n SIP Applications directly from Maven without copying anything. To start i= t, enter:
mvn cip= ango:run
Again, the first execution may takes time as Maven downloads a lot of mo= dules, this is done only once.
The application is now running. The plugin indicates on the standard out= put on which address and port it listens to. For instance, you should see o= n the standard output something like:
2011-0= 4-07 15:13:26.761:INFO::Started UdpConnector@127.0.1.1:5060 2011-04-07 15:13:26.763:INFO::Started TcpConnector@127.0.1.1:5060
To test it, we now have to send it a SIP OPTIONS
message. T=
his can be done using sipsak, a simple multi-platf=
orm tool that allows to perform various tests on SIP servers. Installation =
is very easy and is detailed at
.
Once sipsak has been installed, you are able to send an OPTIONS message as follows:
sipsak = -v -s sip:cipango_address:cipango_port
For instance, as explained above, our plugin runs on 127.0.1.1:506=
0
, sipsak should then be run as:
sipsak = -v -s sip:127.0.1.1:5060
This should yield something like:
SIP/2.= 0 200 OK Via: SIP/2.0/UDP 127.0.1.1:33950;alias;rport=3D37170;branch=3Dz9hG4bK.4c0c8= c9e From: <sip:sipsak@127.0.1.1:33950>;tag=3D78cf6b42 To: <sip:127.0.1.1>;tag=3D72f4d22c Call-ID: 2026859330@127.0.1.1 CSeq: 1 OPTIONS Server: cipango-2.0 Content-Length: 0
The plugin can be configured to scan target/classes
for any=
changes in your Java sources and will automatically reload the modified cl=
asses. To enable this feature, open the pom.xml
file and add a=
<configuration>
tag as follows:
<plug= in> <groupId>org.cipango</groupId> <artifactId>cipango-maven-plugin</artifactId> <version>${cipango.version}</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> </configuration> </plugin>
Restart the cipango plugin and in another window edit the src/main=
/java/org/cipango/MainServlet.java
servlet source code as follows:=
p>
@Overri= de protected void doOptions(SipServletRequest options) throws ServletException= , IOException { SipServletResponse ok =3D options.createResponse(SipServletResponse.SC_= OK); ok.addHeader("Server", serverInfo); ok.addHeader("Foo", "Bar"); // added this line ok.send(); }
Compile the modified servlet:
mvn com= pile
Wait for a few seconds, the plugin should indicate that it has restarted=
the application. Using Sipsak, you can check that the Foo
hea=
der has been added.