FileDocCategorySizeDatePackage
DefaultRouter.javaAPI DocphoneME MR2 API (J2ME)6002Wed May 02 18:00:42 BST 2007gov.nist.siplite.stack

DefaultRouter

public class DefaultRouter extends Object implements Router
This is the default router. When the implementation wants to forward a request and had run out of othe options, then it calls this method to figure out where to send the request. The default router implements a simple "default routing algorithm" which just forwards to the configured proxy address.

Fields Summary
protected Hop
defaultRoute
Default route.
protected SipStack
sipStack
Current SIP stack context.
Constructors Summary
public DefaultRouter()
Default constructor.

    
Methods Summary
private HopcreateHop(URI requestUri, java.lang.String transport)
Creates new Hop for given uri and transport

param
requestUri next hop address
param
transport next hop connection transport type
return
new Hop if requestUri is SipURI otherwise null

        Hop hop = null;
        if (requestUri.isSipURI()) {
            SipURI sipUri = (SipURI)requestUri;
            int port = sipUri.getPort();
            if (port == -1) { // default port
                port = SIPConstants.DEFAULT_NONTLS_PORT;
            }
            hop = new Hop(sipUri.getHost(), port, 
                              transport);
        }
        return hop;
    
public java.util.EnumerationgetNextHops(Request sipRequest, boolean isDialog)
Return a linked list of addresses corresponding to a requestURI. This is called for sending out outbound messages for which we do not directly have the request URI. The implementaion function is expected to return a linked list of addresses to which the request is forwarded. The implementation may use this method to perform location searches etc.

param
sipRequest is the message to route.
param
isDialog target URI is taken from route list inside of dialog, else it is taken from request URI
return
enumeration of next hops

        Vector hopList = new Vector();

        if (defaultRoute != null) {
            hopList.addElement(defaultRoute);
        } else {
            URI requestUri = null;
            String transport = null;
            RouteList rl = sipRequest.getRouteHeaders();

            // When request has no route list,
            // it's destination URI is same as out of dialog
            if (rl == null || rl.isEmpty()) {
                isDialog = false;
            }

            Hop hop;

            // out of dialog - get destination URI from request URI
            if (!isDialog) {
                requestUri = sipRequest.getRequestURI();
                SipURI requestLineUri =
                    (SipURI)sipRequest.getRequestLine().getUri();
                if (requestLineUri.hasTransport()) {
                    transport = requestLineUri.getTransportParam();
                } else {
                    transport = sipStack.getDefaultTransport();
                }

                hop = createHop(requestUri, transport);
                hopList.addElement(hop);
            } else { // inside dialog - get destination URI from first route
                Enumeration el = rl.getElements();
                RouteHeader route; 
                while (el.hasMoreElements()) {
                    route = (RouteHeader) el.nextElement();
                    requestUri = route.getAddress().getURI();
                    transport = route.getAddress().
                        getParameter(SIPConstants.GENERAL_TRANSPORT);
                    hop = createHop(requestUri, transport);
                    hopList.addElement(hop);
                }
            }
        }
        return hopList.elements();
    
public HopgetOutboundProxy()
Gets the default hop.

return
defaultRoute is the default route.

 return this.defaultRoute; 
public voidsetNextHop(java.lang.String hopString)
Sets the next hop address.

param
hopString is a string which is interpreted by us in the following fashion : host:port/TRANSPORT determines the next hop.

        defaultRoute = new Hop(hopString);
        defaultRoute.setDefaultRouteFlag();
    
public voidsetOutboundProxy(java.lang.String outboundProxy)
Sets the outbound proxy.

param
outboundProxy the new proxy location

        this.defaultRoute = new Hop(outboundProxy);
    
public voidsetSipStack(SipStack sipStack)
Sets the SIP stack context.

param
sipStack the new SIP stack

        this.sipStack = sipStack;