Source Code Cross Referenced for TestMultiNotifiers.java in  » 6.0-JDK-Modules » j2me » javax » microedition » sip » 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 » javax.microedition.sip 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package javax.microedition.sip;
028:
029:        import com.sun.midp.i3test.TestCase;
030:        import javax.microedition.io.Connector;
031:        import javax.microedition.sip.SipConnectionNotifier;
032:        import javax.microedition.sip.SipClientConnection;
033:        import java.io.OutputStream;
034:        import java.io.IOException;
035:        import javax.microedition.sip.SipException;
036:
037:        /**
038:         * Test Multiple SipConnectionNotifiers on single host
039:         *
040:         */
041:        public class TestMultiNotifiers extends TestCase implements 
042:                SipServerConnectionListener {
043:
044:            /** Connection notifier. */
045:            SipConnectionNotifier scn1 = null;
046:            /** Connection notifier. */
047:            SipConnectionNotifier scn2 = null;
048:            /** Client connection. */
049:            SipClientConnection scc1 = null;
050:            /** Client connection. */
051:            SipClientConnection scc2 = null;
052:            /** SIP request message from client to server */
053:            String clientMsg = "Client : How are you?";
054:
055:            /**
056:             * Open SipConnectionNotifier(SCN1 and SCN2) on ports 6080 and 5081.
057:             * Open two client connections connecting to SCN1 and SCN2 
058:             */
059:            void setup() {
060:                try {
061:                    // Open SipConnectionNotifier on port 6080
062:                    scn1 = (SipConnectionNotifier) Connector.open("sip:6080");
063:                    assertNotNull("scn1 is null", scn1);
064:                    scn1.setListener(this );
065:                } catch (Exception ex) {
066:                    assertNull("Exception during scn1 open", scn1);
067:                    ex.printStackTrace();
068:                }
069:
070:                try {
071:                    // Open SipConnectionNotifier on port 6081
072:                    scn2 = (SipConnectionNotifier) Connector.open("sip:6081");
073:                    assertNotNull("scn2 is null", scn2);
074:                    scn2.setListener(this );
075:                } catch (Exception ex) {
076:                    assertNull("Exception during scn2 open", scn2);
077:                    ex.printStackTrace();
078:                }
079:
080:                try {
081:                    // Open SIP client connection to the SCN ON PORT 6080
082:                    scc1 = (SipClientConnection) Connector
083:                            .open("sip:sippy.tester@localhost:6080");
084:                    assertNotNull("scc1 is null", scc1);
085:                } catch (Exception ex) {
086:                    assertNull("Exception during scc1 open", scc1);
087:                    ex.printStackTrace();
088:                    cleanup();
089:                }
090:
091:                try {
092:                    // Open SIP client connection to the SCN ON PORT 6081
093:                    scc2 = (SipClientConnection) Connector
094:                            .open("sip:sippy.tester@localhost:5081");
095:                    assertNotNull("scc2 is null", scc2);
096:                } catch (Exception ex) {
097:                    assertNull("Exception during scc2 open", scc2);
098:                    ex.printStackTrace();
099:                    cleanup();
100:                }
101:
102:            }
103:
104:            /**
105:             * Send a SIP INVITE message 
106:             * @param scc SIP client connection
107:             * @param snc SIP Connection Notifier
108:             *
109:             */
110:            public void testInviteMsg(SipClientConnection scc,
111:                    SipConnectionNotifier scn) {
112:
113:                try {
114:                    scc.initRequest("INVITE", scn);
115:                    scc.setHeader("From", "sip:sippy.tester@localhost");
116:                    scc.setHeader("Subject", "Hello...");
117:                    scc.setHeader("Contact", "sip:user@"
118:                            + scn.getLocalAddress() + ":" + scn.getLocalPort());
119:
120:                    // write message body
121:                    scc.setHeader("Content-Type", "text/plain");
122:                    scc.setHeader("Content-Length", Integer.toString(clientMsg
123:                            .length()));
124:                    OutputStream os = scc.openContentOutputStream();
125:                    os.write(clientMsg.getBytes());
126:                    os.close(); // close stream and send the message
127:
128:                    // System.out.println("Inviting..." + scc.getHeader("To"));
129:                } catch (IOException ioe) {
130:                    ioe.printStackTrace();
131:                    cleanup();
132:                    fail("IOException in TestMultiNotifiers");
133:                }
134:
135:            }
136:
137:            /**
138:             * Receive request from client
139:             *
140:             * This method is declared in SipServerConnectionListener
141:             * 
142:             * @param scnLocal Local SIP connection notifier
143:             */
144:            public void notifyRequest(SipConnectionNotifier scnLocal) {
145:                try {
146:                    System.out.println("Local SCN port = "
147:                            + scnLocal.getLocalPort());
148:                } catch (IOException ioe) {
149:                    ioe.printStackTrace();
150:                    fail("IOException in TestMultiNotifiers");
151:                }
152:
153:            }
154:
155:            /**
156:             * Close all connections.
157:             *
158:             */
159:            void cleanup() {
160:                try {
161:                    if (scc1 != null) {
162:                        scc1.close();
163:                    }
164:                    if (scc2 != null) {
165:                        scc2.close();
166:                    }
167:
168:                    if (scn1 != null) {
169:                        scn1.close();
170:                    }
171:                    if (scn2 != null) {
172:                        scn2.close();
173:                    }
174:                } catch (IOException ioe) {
175:                    assertNull("Unexpected IOException during cleanup", ioe);
176:                    ioe.printStackTrace();
177:                }
178:            }
179:
180:            /**
181:             * Tests execute.
182:             *
183:             */
184:            public void runTests() {
185:                declare("Test TestMultiNotifiers ");
186:
187:                setup();
188:
189:                testInviteMsg(scc1, scn1);
190:                synchronized (this ) {
191:                    try {
192:                        wait(500);
193:                    } catch (InterruptedException e) {
194:                        System.out.println("Catch interrupt");
195:                    }
196:                }
197:
198:                testInviteMsg(scc2, scn2);
199:                synchronized (this ) {
200:                    try {
201:                        wait(500);
202:                    } catch (InterruptedException e) {
203:                        System.out.println("Catch interrupt");
204:                    }
205:                }
206:
207:                cleanup();
208:
209:                assertTrue("Failure in TestMultiNotifiers", true);
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.