快速业务通道

使用SIP Servlet为Java EE添加语音功能 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-16
rvletRequest request, HttpServletResponse response)    throws ServletException, IOException {      String callA = null;      String callB = null;      Getting the contacts from request parameters      String[] contacts = request.getParameterValues("CONTACT");      if ( contacts.length < 2 ) {        return;      }      callA = contacts[0];      callB = contacts[1];      Using the SipFactory object to create a SipApplicationSession      SipApplicationSession as = sf.createApplicationSession();      Using the SipFactory object to create a "To" and "From" Address objects      Address to = sf.createAddress(callB);      Address from = sf.createAddress(callA);      Creating a SipServletRequest using the SipFactory and the SipApplicationSessionObjects created. Note that      INVITE is being sent as if UserA is inviting UserB.      SipServletRequest sipReq = sf.createRequest(as, "INVITE", from, to);       logger.log(Level.FINE, "SipCallSetupServlet sipRequest = " + sipReq.toString());      Set an attribute in SipServletRequest to indicate that this is an initial INVITE      sipReq.setAttribute("CALL","INITIAL");      // set servlet to invoke by response      Getting a SipSession from the Request created      SipSession s = sipReq.getSession();       This is the key part. We set name of the servlet that would handler the response for the       Request being sent. Here b2b is the name of the SIP Servlet that would handle the response       to this request.      s.setHandler("b2b");      // lets send invite to B ...       Sending the request      sipReq.send();    }

使用SIP Servlet为Java EE添加语音功能(6)

时间:2011-07-18 Prasad Subramanian

B2BCallServlet.java

这个 SIP Servlet 接收并处理针对 SipCallSetupServlet 发送的 INVITE 请求的响应。该 servlet 处理响应头部和正文,获取 SDP,并 向其他用户代理发送另一个 INVITE 请求和 SDP 元数据。接收到来自其他用户的带有成功响应代码的响应之后,该 servlet 在两个用户之间 建立呼叫。

public class B2BCallServlet extends SipServlet {    SipFactory               sf        = null;    ServletContext             ctx       = null;    public void init(ServletConfig config) throws ServletException {      super.init(config);      ctx = config.getServletContext();        Get the SipFactory from the ServletContext        sf = (SipFactory) ctx.getAttribute(SipServlet.SIP_FACTORY);        ts = (TimerService) ctx.getAttribute(SipServlet.TIMER_SERVICE);    }    protected void doResponse(SipServletResponse resp) throws ServletException, IOException {      get the SipApplicationSession and SipServletRequest from the response      SipApplicationSession sas = resp.getApplicationSession(true);      SipServletRequest origReq = resp

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号