⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basereaderrouter.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
字号:
/******************************************************************************** Product of NIST/ITL Advanced Networking Technologies Division (ANTD).        ********************************************************************************/package gov.nist.examples.bps.reader.router;import javax.sip.message.*;import javax.sip.address.*;import javax.sip.header.*;import javax.sip.*;import java.util.*;import gov.nist.examples.bps.reader.*;/** This is a proxy 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. *@version  JAIN-SIP-1.1**@author M. Ranganathan <mranga@nist.gov>  <br/>*@author Olvier Deruelle <deruelle@nist.gov>  <br/>**<a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>**/public class BaseReaderRouter implements Router {        protected BaseReaderHop defaultRoute;    protected SipStack stack;	            /**         * Constructor.         */    public BaseReaderRouter(SipStack sipStack, String def) {        BaseReaderDebug.println	 ("BaseReader, the default route is: "+def);        if (def !=null)            this.defaultRoute = new BaseReaderHop(def);	this.stack = sipStack;    }        public BaseReaderHop getNextHop(ListIterator routes) 	throws IllegalArgumentException{        try{            while (routes.hasNext() ) {                RouteHeader  routeHeader = (RouteHeader) routes.next();                Address routeAddress=routeHeader.getAddress();                SipURI sipURI=(SipURI)routeAddress.getURI();                               String host = sipURI.getHost();                String transport = sipURI.getTransportParam();                int port = sipURI.getPort();                if (port == -1) {                    port = 5060;                }                if (transport==null) transport="UDP";                                                BaseReaderHop hop = new BaseReaderHop(host,port,transport);                BaseReaderDebug.println("BaseReader, getNextHop(), " +                "The request has at least one route, we use the first one"+                ": "+host+":"+port+"/"+transport);                return hop;                            }            return null;        }        catch(Exception e) {            throw new IllegalArgumentException(e.getMessage());        }    }                private boolean checkPort(int port) {        Iterator lps=stack.getListeningPoints();        if (lps==null) return false;        while(lps.hasNext()) {            ListeningPoint lp=(ListeningPoint)lps.next();            if (lp.getPort()==port) return true;        }        return false;    }                    /**         * Return  addresses for default proxy to forward the request to.         * The list is organized in the following priority.	 * If the request contains a Route Header it is used to construct	 * the first element of the list.         * If the requestURI refers directly to a host, the host and port         * information are extracted from it and made the next hop on the         * list. 	 * If the default route has been specified, then it is used	 * to construct the next element of the list.         *@param method is the method of the request.         *@param requestURI is the request URI of the request.         */    public ListIterator getNextHops(Request request)    throws IllegalArgumentException {	LinkedList nextHops=new LinkedList();        ListIterator routes = request.getHeaders(RouteHeader.NAME);           //  BaseReaderDebug.println("BaseReader, request:\n"+request.toString());                   // new Exception("ProxyRouter exception").printStackTrace();                 if (routes!=null) {            Hop nextHop=getNextHop(routes);            if (nextHop!=null) {                nextHops.add(nextHop);                return nextHops.listIterator();            }        }                      URI requestURI=request.getRequestURI();        if (requestURI instanceof SipURI) {            String mAddr=((SipURI)requestURI).getMAddrParam();            if ( mAddr!=null){                try {                    String mAddrTransport=((SipURI)requestURI).                    getTransportParam();                    if (mAddrTransport==null) mAddrTransport="UDP";                    int mAddrPort=((SipURI)requestURI).getPort();                    if (mAddrPort==-1) mAddrPort=5060;                                        BaseReaderHop mAddrHop=new BaseReaderHop                    (mAddr,mAddrPort,mAddrTransport);                    if (mAddrHop!=null) {                        nextHops.add(mAddrHop);                        BaseReaderDebug.println                        ("BaseReader, getNextHops(), " +                        " the hop added: Request URI maddr parameter:"+                        " host:"+mAddr+                        " port:"+mAddrPort+                        " transport:"+mAddrTransport);                        return nextHops.listIterator();                    }                                    }                catch(Exception e) {                    throw new IllegalArgumentException                    ("ERROR, BaseReader, pb to add the maddr hop");                }            }            else {                                SipURI sipURI=(SipURI)requestURI;                String host = sipURI.getHost();                int port = sipURI.getPort();                if (port == -1) {                    port = 5060;                }                String transport = sipURI.getTransportParam();                if (transport==null) transport="UDP";                                BaseReaderHop requestURIHop = new BaseReaderHop(host,port,transport);                nextHops.add(requestURIHop);                BaseReaderDebug.println                ("BaseReader, getNextHops(), " +                " the hop added: host:"+requestURIHop.getHost()+                " port:"+requestURIHop.getPort()+                " transport:"+requestURIHop.getTransport());                return nextHops.listIterator();                            }        }        else {              BaseReaderDebug.println                    ("BaseReader, getNextHops(), the request URI is not a SipURI:"+                    " unable to build a hop.");        }                if (defaultRoute != null ) {            nextHops.add(defaultRoute);            BaseReaderDebug.println                    ("BaseReader, getNextHops(), we added the hop (default route): "+                    "host:"+defaultRoute.getHost()+                    " port:"+defaultRoute.getPort()+                    " transport:"+defaultRoute.getTransport());        }                return nextHops.listIterator();    }            /** Get the default hop.         *@return defaultRoute is the default route.         */    public Hop getOutboundProxy() 		{ return  this.defaultRoute; }       }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -