The SIP container can accept from the SIP proxy a list of outbound interfaces and expose it to any SIP application.
Multihoming allows you to have a single application communicate with different user agent clients (UAC) and user agent servers (UAS) on different networks.
The application queries the SIP container to determine the list of available outbound interfaces using standard procedures defined by JSR 289. This is done through a context attribute that is maintained in the container (through protocol exchanges with all the available SIP proxies). This attribute is javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES, which is defined to be javax.servlet.sip.outboundInterfaces. This attribute contains all the available interfaces. The sample code in the Example section shows how to access the attribute from the application.
After the interfaces on each SIP proxy are configured, follow the steps in the procedure to control the routing of outbound messages. If more than one proxy is being used, it is important that each proxy be configured identically.
When an application does not specify an interface to use for sending outbound requests, the default interfaces are used by the proxy. It is recommended that you set the default interfaces for every protocol. See step 5 for more information.
The administrator can optionally set three SIP proxy custom properties that define the chain name that define the appropriate interface to use if the SIP application does not call the setOutboundInterface method. If these custom properties are not set and the setOutboundInterface method is not used, the interface that will be used for outbound requests cannot be definitively determined.
The following procedure applies to a topology that contains a single proxy setup for multihomed hosting with more than one network interface.
....
import javax.servlet.sip.SipServlet;
import javax.servlet.sip.SipSession;
....
protected void doInvite(SipServletRequest req1) throws ServletException, IOException
{
...
// This block of code handles setting of the outbound interface.
SipSession sipSession = req1.getSession();
javax.servlet.ServletContext context = getServletContext();
java.util.List list = (java.util.List)context.getAttribute(javax.servlet.sip.SipServlet.
OUTBOUND_INTERFACES);
SipURI uri = getProtocolInterface ("udp", list);
if (uri != null)
{
InetSocketAddress inetSocketAddr = new InetSocketAddress(uri.getHost(), uri.getPort());
sipSession .setOutboundInterface(inetSocketAddr);
}
...
}
// This method simply pulls out the first interface in the list for the specified protocol
private SipURI getProtocolInterface(String transport, List outboundInterfaceList)
{
SipURI uri = null;
Iterator iterator = outboundInterfaceList.iterator();
while (iterator.hasNext())
{
SipURI tempUri = (SipURI)iterator.next();
if (tempUri.getTransportParam().equals(transport) == true)
{
uri = tempUri;
break;
}
}
return (uri);
}