Screening list:alice@server.test
呼叫流程:
Servlet在doRequest方法中检查UA的URI是否在Screening列表中,如果在,返回603 DECLINE响应。
import java.io.IOException;
import java.util.*;
import javax.servlet.sip.*;
import javax.servlet.*;
public class CallScreen extends SipServlet {
Collection m_screenings;
SipFactory m_sipFactory;
public void init() throws ServletException {
m_screenings = new Vector();
m_sipFactory = (SipFactory) getServletContext().getAttribute(
"javax.servlet.sip.SipFactory");
Enumeration names = getInitParameterNames();
if (names == null) {
return;
}
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (name.startsWith("screening-uri")) {
String screeningURI = (String) getInitParameter(name);
try {
SipURI uri = (SipURI) m_sipFactory.createURI(screeningURI);
m_screenings.add(uri);
}
catch (ServletException e) {
}
}
}
}
public void doRequest(SipServletRequest req) throws IOException {
SipURI from = (SipURI) req.getFrom().getURI();
Iterator uris = m_screenings.iterator();
while (uris.hasNext()) {
SipURI uri = (SipURI) uris.next();
if (uri.getHost().equals(from.getHost())) {
SipServletResponse resp = req
.createResponse(SipServletResponse.SC_DECLINE);
try {
resp.send();
}
catch (java.io.IOException e) {
}
return;
}
}
log(req.toString());
// ...
}
public void doResponse(SipServletResponse resp) throws IOException {
log(resp.toString());
// ...
}
}