Eclipse EricssonSDS中實現簡單的Proxy 伺服器

來源:互聯網
上載者:User

一個簡單的Proxy 伺服器的功能實現,摘自http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rsip_servclass1.html

 

 

protected void doInvite(SipServletRequest request)<br />throws ServletException, IOException {<br />try {<br />if (request.isInitial() == true)<br />{<br />//This should cause the sip session to be created. This sample only uses the session on receiving<br />//a BYE but the Tivoli performance viewer can be used to track the creation of calls by viewing the<br />//active session count.<br />Integer state = new Integer(INVITE_RECEIVED);<br />SipSession session = request.getSession();<br />session.setAttribute(STATE_KEY, state);<br /> //log("SimpleProxy: doInvite: setting attribute");<br />Proxy proxy = request.getProxy();<br />SipFactory sipFactory = (SipFactory) getServletContext().getAttribute(SIP_FACTORY);<br /> if (sipFactory == null) {<br /> throw new ServletException("No SipFactory in context");<br /> }<br /> String callingNumber = request.getTo().toString();<br /> if (callingNumber != null)<br /> {<br /> String destStr = format_lookup(callingNumber);<br /> URI dest = sipFactory.createURI(destStr);<br /> //log("SimpleProxy: doInvite: Proxying to dest URI = " + dest.toString());<br /> if (((SipURI)request.getRequestURI()).getTransportParam() != null)<br /> ((SipURI)dest).setTransportParam(((SipURI)request.getRequestURI()).getTransportParam());<br /> proxy.setRecordRoute(true);<br />proxy.proxyTo(dest);<br /> }<br />else {<br /> //log("SimpleProxy: doInvite: Request is invalid. Did not contain a To: field.");<br />SipServletResponse sipresponse = request.createResponse(400);<br />sipresponse.send();<br />}<br />}<br />else<br />{<br /> //log("SimpleProxy: doInvite: target refresh, let container handle invite");<br />super.doInvite(request);<br />}<br />}<br />catch (Exception e){<br />e.printStackTrace();<br />}<br />}<br />protected String format_lookup(String toFormat){<br />int start_index = toFormat.indexOf('<') + 1;<br />int end_index = toFormat.indexOf('>');<br />if(start_index == 0){<br />//don't worry about it<br />}<br />if(end_index == -1){<br />end_index = toFormat.length();<br />}<br />return toFormat.substring(start_index, end_index);<br />}

 

另外,推薦http://tech-invite.com/Ti-sip-service-1.html,全是標準信令流程啊~口水...

 

使用這個Proxy 伺服器,就可以跑通上面的標準信令流程了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.