Source Code Cross Referenced for DefaultRouter.java in  » 6.0-JDK-Modules » j2me » gov » nist » siplite » stack » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » gov.nist.siplite.stack 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Portions Copyright  2000-2007 Sun Microsystems, Inc. All Rights
003:         * Reserved.  Use is subject to license terms.
004:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005:         * 
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License version
008:         * 2 only, as published by the Free Software Foundation.
009:         * 
010:         * This program is distributed in the hope that it will be useful, but
011:         * WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * General Public License version 2 for more details (a copy is
014:         * included at /legal/license.txt).
015:         * 
016:         * You should have received a copy of the GNU General Public License
017:         * version 2 along with this work; if not, write to the Free Software
018:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019:         * 02110-1301 USA
020:         * 
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022:         * Clara, CA 95054 or visit www.sun.com if you need additional
023:         * information or have any questions.
024:         */
025:        package gov.nist.siplite.stack;
026:
027:        import gov.nist.siplite.header.*;
028:        import gov.nist.siplite.address.*;
029:        import gov.nist.siplite.header.ViaHeader;
030:
031:        import gov.nist.siplite.message.*;
032:        import gov.nist.siplite.*;
033:        import java.util.*;
034:
035:        /**
036:         * This is the default router. When the implementation wants to forward
037:         * a request and had run out of othe options, then it calls this method
038:         * to figure out where to send the request. The default router implements
039:         * a simple "default routing algorithm" which just forwards to the configured
040:         * proxy address.
041:         */
042:
043:        public class DefaultRouter implements  Router {
044:            /** Default route. */
045:            protected Hop defaultRoute;
046:            /** Current SIP stack context. */
047:            protected SipStack sipStack;
048:
049:            /** Default constructor. */
050:            public DefaultRouter() {
051:            }
052:
053:            /**
054:             * Sets the next hop address.
055:             * @param hopString is a string which is interpreted
056:             * by us in the following fashion :
057:             * host:port/TRANSPORT determines the next hop.
058:             */
059:            public void setNextHop(String hopString)
060:                    throws IllegalArgumentException {
061:                defaultRoute = new Hop(hopString);
062:                defaultRoute.setDefaultRouteFlag();
063:            }
064:
065:            /**
066:             * Return a linked list of addresses corresponding to a requestURI.
067:             * This is called for sending out outbound messages for which we do
068:             * not directly have the request URI. The implementaion function
069:             * is expected to return a linked list of addresses to which the
070:             * request is forwarded. The implementation may use this method
071:             * to perform location searches etc.
072:             *
073:             * @param sipRequest is the message to route.
074:             * @param isDialog target URI is taken from route list inside of dialog,
075:             * else it is taken from request URI
076:             * @return enumeration of next hops
077:             */
078:            public Enumeration getNextHops(Request sipRequest, boolean isDialog)
079:                    throws IllegalArgumentException {
080:                Vector hopList = new Vector();
081:
082:                if (defaultRoute != null) {
083:                    hopList.addElement(defaultRoute);
084:                } else {
085:                    URI requestUri = null;
086:                    String transport = null;
087:                    RouteList rl = sipRequest.getRouteHeaders();
088:
089:                    // When request has no route list,
090:                    // it's destination URI is same as out of dialog
091:                    if (rl == null || rl.isEmpty()) {
092:                        isDialog = false;
093:                    }
094:
095:                    Hop hop;
096:
097:                    // out of dialog - get destination URI from request URI
098:                    if (!isDialog) {
099:                        requestUri = sipRequest.getRequestURI();
100:                        SipURI requestLineUri = (SipURI) sipRequest
101:                                .getRequestLine().getUri();
102:                        if (requestLineUri.hasTransport()) {
103:                            transport = requestLineUri.getTransportParam();
104:                        } else {
105:                            transport = sipStack.getDefaultTransport();
106:                        }
107:
108:                        hop = createHop(requestUri, transport);
109:                        hopList.addElement(hop);
110:                    } else { // inside dialog - get destination URI from first route
111:                        Enumeration el = rl.getElements();
112:                        RouteHeader route;
113:                        while (el.hasMoreElements()) {
114:                            route = (RouteHeader) el.nextElement();
115:                            requestUri = route.getAddress().getURI();
116:                            transport = route.getAddress().getParameter(
117:                                    SIPConstants.GENERAL_TRANSPORT);
118:                            hop = createHop(requestUri, transport);
119:                            hopList.addElement(hop);
120:                        }
121:                    }
122:                }
123:                return hopList.elements();
124:            }
125:
126:            /**
127:             * Creates new Hop for given uri and transport
128:             * 
129:             * @param requestUri next hop address
130:             * @param transport next hop connection transport type
131:             * @return new Hop if requestUri is SipURI
132:             *         otherwise null
133:             */
134:            private Hop createHop(URI requestUri, String transport) {
135:                Hop hop = null;
136:                if (requestUri.isSipURI()) {
137:                    SipURI sipUri = (SipURI) requestUri;
138:                    int port = sipUri.getPort();
139:                    if (port == -1) { // default port
140:                        port = SIPConstants.DEFAULT_NONTLS_PORT;
141:                    }
142:                    hop = new Hop(sipUri.getHost(), port, transport);
143:                }
144:                return hop;
145:            }
146:
147:            /**
148:             * Gets the default hop.
149:             * @return defaultRoute is the default route.
150:             */
151:            public Hop getOutboundProxy() {
152:                return this .defaultRoute;
153:            }
154:
155:            /**
156:             * Sets the outbound proxy.
157:             * @param outboundProxy the new proxy location
158:             */
159:            public void setOutboundProxy(String outboundProxy) {
160:                this .defaultRoute = new Hop(outboundProxy);
161:            }
162:
163:            /**
164:             * Sets the SIP stack context.
165:             * @param sipStack the new SIP stack
166:             */
167:            public void setSipStack(SipStack sipStack) {
168:                this.sipStack = sipStack;
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.