一個簡單的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 伺服器,就可以跑通上面的標準信令流程了