posts - 32,comments - 8,trackbacks - 0
 

Oops! Bea Sip Server Quick Start Part 2

Purpose

掌握由网页发出sipinvite请求。

Precondition:

http://www.blogjava.net/pixysoft/archive/2007/09/11/144131.html

Quick Start

在上一章,掌握了安装sip serverkapanga,然后写了一个注册的机制。这张写一个网页触发invite的事件,呼叫客户端。

首先建一个dynamic web project,叫做Oops_Sip_02,然后修改WebContent,改为invite,修改properties,把Default output folder改为:Oops_Sip_02/invite/WEB-INF/classes,删除build目录,最后整个项目为:





修改
.classpath文件,增加3个引用:注意这3个引用是你安装目录下的。

<?xml version="1.0" encoding="UTF-8"?>

<classpath>

    
<classpathentry kind="src" path="src"/>

    
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk150_06"/>

    
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>

    
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/wlss/wlss.jar"/>

    
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar" sourcepath="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar"/>

    
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/weblogic.jar"/>

    
<classpathentry kind="output" path="invite/WEB-INF/classes"/>

</classpath>

src目录下面增加2个文件

httpControlServlet

 

import java.io.IOException;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class httpControlServlet extends HttpServlet

{

       
public void doGet(HttpServletRequest request, HttpServletResponse response)

                     
throws ServletException, IOException

       {

              doAction(request, response);

       }

       
public void doPost(HttpServletRequest request, HttpServletResponse response)

                     
throws ServletException, IOException

       {

              doAction(request, response);

       }

       
private void doAction(HttpServletRequest request,

                     HttpServletResponse response) 
throws ServletException, IOException

       {

              String sip 
= request.getParameter("sip");

              sipControlServlet.DoConnection(sip);

              RequestDispatcher rds;

              rds 
= getServletContext().getRequestDispatcher("/index.jsp");

              rds.forward(request, response);

              
return;

       }

}

sipControlServlet

import java.io.IOException;

import javax.servlet.*;

import javax.servlet.sip.*;

import com.bea.wcp.sip.util.TransportUtil;

public class sipControlServlet extends SipServlet

{

    
private static Address myAddress;

    
private static SipFactory factory;

    
public void init(ServletConfig cfg) throws ServletException

    {

        
super.init(cfg);

        factory 
= (SipFactory) getServletContext().getAttribute(

                SipServlet.SIP_FACTORY);

        String uri 
= "sip:oops@localhost:5062";

        myAddress 
= factory.createAddress(uri);

        System.out.println(
"Oops! Sip Server Demo 2");

    }

    
public static void DoConnection(String sip) throws ServletException,

            IOException

    {

        SipApplicationSession appSession 
= factory.createApplicationSession();

        Address to 
= factory.createAddress("sip:" + sip);

        SipServletRequest invite 
= factory.createRequest(appSession, "INVITE",

                myAddress, to);

        invite.send();

        System.out.println(
"Connection successful!");

    }

    
protected void doResponse(SipServletResponse resp) throws ServletException,

            IOException

    {

        resp.createAck().send();

    }

}

在invite/WEB-INF下面建2个文件:

sip.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sip-app

   PUBLIC "-//Java Community Process//DTD SIP Application 1.0//EN"

   "http://www.jcp.org/dtd/sip-app_1_0.dtd"
>

<sip-app>

    
<display-name>Oops Sip Server Quick Start 2</display-name>

    
<distributable />

    
<servlet>

       
<servlet-name>sipControlServlet</servlet-name>

       
<servlet-class>sipControlServlet</servlet-class>

       
<load-on-startup>1</load-on-startup>

    
</servlet>

    
<!-- system user for the run-as element for Registrar -->

    
<security-role>

       
<role-name>system-user</role-name>

    
</security-role>

</sip-app>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_ID" version="2.4"

    xmlns
="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    
<display-name>testsender</display-name>

    
<welcome-file-list>

       
<welcome-file>index.html</welcome-file>

       
<welcome-file>index.htm</welcome-file>

       
<welcome-file>index.jsp</welcome-file>

       
<welcome-file>default.html</welcome-file>

       
<welcome-file>default.htm</welcome-file>

       
<welcome-file>default.jsp</welcome-file>

    
</welcome-file-list>

    
<servlet>

       
<servlet-name>httpControlServlet</servlet-name>

       
<servlet-class>httpControlServlet</servlet-class>

    
</servlet>

    
<servlet-mapping>

       
<servlet-name>httpControlServlet</servlet-name>

       
<url-pattern>/http.oops</url-pattern>

    
</servlet-mapping>

</web-app>

invite目录下添加index.jsp

<html>

<body>

<form name="form_sip" action="http.oops"

    method
="post"><input name="sip" value="user1@192.168.0.130:5061"

    type
="text" style="width: 240px"><input type="submit"></form>

</body>

</html>

最后整个目录变为:



大概解说一下:用户网页输入
sip,传递给后台httpservlet,其调用sipservlet的静态方法,创建一个会话到用户。

现在吧项目部署在bea sip server上面,方法参考前面的文章。然后在浏览器输入:

http://localhost:7001/invite



之后打开
kapanga,在点击网页



完成!

posted on 2007-09-13 08:18 张辰 阅读(771) 评论(1)  编辑  收藏 所属分类: Dr. Oops

FeedBack:
# re: Oops! Bea Sip Server Quick Start Part 2
2008-04-23 06:33 | Guest
Hi,

This article is cool but I can't see the pictures? Can you double check?  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: