Oops! Bea Sip Server Quick Start Part 1
Purpose
掌握bea sip server 3.0
就是bea公司推出的一个sip的服务器,适合下一代电信网络。
首先声明一下,这个quick start比较有难度,我调了1个多小时才出来。很多很无聊的细节要注意!
Precondition:
sipserver300_win32.exe 328 MB (这个有点难度,可能需要去bea主页下载,还要申请)
kapanga 一个sip电话:http://www.kapanga.net/ip/download.cfm
Quick Start
Bea Sip Server 安装
首先当然是安装sipserver 3.0。很简单,根据提示没有问题,不过要注意,不要使用中文文件夹、不要过长的文件夹。
然后在sip server里面建立一个自己的domain,也很简单,不过要注意,要使用java jdk 1.5,不要使用其他的,否则有问题。然后在ie输入:
http://localhost:7001/console
就可以看到登录框!输入用户名和密码就可以进入:
Kapanga sip 电话安装
然后安装kapanga,需要配置,如图:
Username: user1
Display name: user1
Default URL: user1@192.168.0.130
注意,这个ip在运行 – cmd – ipconfig看到
Domain/realm: 192.168.0.130
sip proxy: 192.168.0.130:5060
outbound proxy: 192.168.0.130:5060
选择register
Local udp sip port: 5061
Eclipse 开发
然后关掉Kapanga,打开eclipse,新建一个项目Dynamic web project叫做Oops_Sip_01。注意以下设置:
然后确认之后生成项目目录。选择 project – properties – java build path – source,把default output folder修改为Oops_Sip_01/web/WEB-INF/classes。
确认后删除掉build目录,可以看到如下的结构
打开.classpath文件,修改如下,即引用了3个类,来自bea的sipserver,这个看大家的安装目录确定。
<?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/jdk1.6.0_02" />
<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="web/WEB-INF/classes" />
</classpath>
在web " WEB-INF " lib目录下面添加以下jar文件,这些文件都可以在eclipse / plugin 里面和下载了jstl.jar文件包里面找到。没有的问我。
在web " WEB-INF"下添加文件夹tlds,添加以下文件:
在src目录下面添加3个java文件:
DisplayURIServlet 这里getRequestDispatcher("/index.jsp");很关键!
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class DisplayURIServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
session.setAttribute("user", UserController.Instance().GetList());
response.setContentType("text/html; charset=gb2312");
RequestDispatcher rds;
rds = getServletContext().getRequestDispatcher("/index.jsp");
rds.forward(request, response);
return;
}
}
Registration
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.sip.*;
public final class Registration extends SipServlet
{
public void init(ServletConfig sc) throws ServletException
{
super.init(sc);
System.out.println("Oops! First Sip Application!");
}
// 把用户保存起来
public void doRegister(SipServletRequest req) throws IOException,
ServletParseException
{
UserController.Instance().AddUser((SipURI) req.getTo().getURI());
SipServletResponse res = req.createResponse(200);
res.send();
}
}
UserController
import java.util.ArrayList;
import java.util.List;
import javax.servlet.sip.*;
public class UserController
{
List<SipURI> userList = new ArrayList<SipURI>();
private static UserController instance;
public static UserController Instance()
{
if (instance == null)
instance = new UserController();
return instance;
}
public void AddUser(SipURI url)
{
if (userList.contains(url))
return;
userList.add(url);
}
public List<SipURI> GetList()
{
return userList;
}
}
在web下面添加index.jsp文件
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<c:choose>
<c:when test="${empty sessionScope.user}">
Oops!No user!</c:when>
<c:otherwise>
<c:out value="${user}"/>
</c:otherwise>
</c:choose>
</body>
</html>
修改web/WEB-INF目录下的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>caonima</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>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
<servlet>
<servlet-name>user</servlet-name>
<servlet-class>
DisplayURIServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>user</servlet-name>
<url-pattern>/sip.oops</url-pattern>
</servlet-mapping>
</web-app>
在web/WEB-INF/目录下面添加2个xml文件:
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! First SIP Servlet</display-name>
<distributable/>
<servlet>
<servlet-name>registrar</servlet-name>
<servlet-class>Registration</servlet-class>
<load-on-startup>1</load-on-startup>
<!-- system user -->
<run-as>
<role-name>system-user</role-name>
</run-as>
</servlet>
<servlet-mapping>
<servlet-name>registrar</servlet-name>
<pattern>
<equal>
<var>request.method</var>
<value>REGISTER</value>
</equal>
</pattern>
</servlet-mapping>
<!-- system user for the run-as element for Registrar -->
<security-role>
<role-name>system-user</role-name>
</security-role>
</sip-app>
weblogic.xml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<run-as-role-assignment>
<role-name>system-user</role-name>
<run-as-principal-name>weblogic</run-as-principal-name>
</run-as-role-assignment>
</weblogic-web-app>
Ok!!完成了项目开发。整体目录如下:
选择project – clean命令编译项目
Sip Server部署
现在启动sip server,然后进入deployment页面:
点击lock & edit,然后可以点击install,来到你的项目位置,选择之后一直next到finish
激活你的部署:
同时在sip的Console可以看到一条语句:
然后选择你的项目,Start – serving all request,然后确定就好了!
打开ie,输入:http://localhost:7001/web/index.jsp,可以看到:
现在运行Kapanga,一定要注意设置,按照上面的设置:
然后再回到ie,输入:http://localhost:7001/web/sip.oops,可以看到:
一项艰巨的quick start完成!
posted on 2007-09-11 02:12
张辰 阅读(838)
评论(0) 编辑 收藏 所属分类:
Dr. Oops