SIP Servlet 示例之 Call Forward

Posted on Jul 23, 2006

Servlet 将收到的请求转发到指定的 URI.

import java.io.IOException;
import javax.servlet.sip.*;
import javax.servlet.*;

public class CallForward extends SipServlet {
	SipURI m_target = null;

	SipFactory m_sipFactory;

	public void init() throws ServletException {
		m_sipFactory = (SipFactory) getServletContext().getAttribute("javax.servlet.sip.SipFactory");
	
		String forwardURI = (String) getInitParameter("target-uri");
		m_target = (SipURI) m_sipFactory.createURI(forwardURI);
	}

	public void doRequest(SipServletRequest req)
		throws TooManyHopsException {
		log(req.toString());
		// ...
		req.getProxy().proxyTo(m_target);
	}

	public void doResponse(SipServletResponse resp) throws IOException {
		log(resp.toString());
		// ...
	}
}