Source Code Cross Referenced for TestRegisterTCP.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 java.io.InputStream;
032:        import java.io.OutputStream;
033:        import java.io.IOException;
034:        import javax.microedition.sip.*;
035:        import gov.nist.microedition.sip.SipServerConnectionImpl;
036:
037:        /**
038:         * Tests for end-to-end SIP client-server communication
039:         *
040:         */
041:        public class TestRegisterTCP extends TestCase implements 
042:                SipClientConnectionListener, SipServerConnectionListener {
043:
044:            /** Connection notifier. */
045:            SipConnectionNotifier scn = null;
046:            /** Connection notifier. */
047:            SipConnectionNotifier scnAssociated = null;
048:            /** Server connection. */
049:            // SipServerConnection ssc = null;
050:            /** Client connection. */
051:            SipClientConnection scc = null;
052:            /** Boolean flag to indicate that test was successful */
053:            boolean done = false;
054:
055:            /**
056:             * Open the connection and start the thread to call the run
057:             * method.  It waits until the InputStream is open before returning.
058:             */
059:            void setup() {
060:                try {
061:                    // Open SIP server connection and listen to port 9090
062:                    // scn = (SipConnectionNotifier) Connector.open("sip:9090");
063:                    scn = (SipConnectionNotifier) Connector
064:                            .open("sip:9090;transport=tcp");
065:                    // scnAssociated = (SipConnectionNotifier) 
066:                    //      Connector.open("sip:;transport=tcp");
067:                } catch (Exception ex) {
068:                    assertNull("Exception during scn open", scn);
069:                    ex.printStackTrace();
070:                }
071:
072:                assertNotNull("scn is null", scn);
073:
074:                try {
075:                    scn.setListener(this );
076:
077:                    // Open SIP client connection to the local SIP server
078:                    scc = (SipClientConnection) Connector
079:                            .open("sip:sippy.tester@localhost:9090;transport=tcp");
080:
081:                    scc.setListener(this );
082:                } catch (Exception ex) {
083:                    assertNull("Exception during sc open", scc);
084:                    ex.printStackTrace();
085:                    cleanup();
086:                }
087:
088:                assertNotNull("sc is null", scc);
089:
090:            }
091:
092:            /**
093:             * Send a SIP message from user agent client to user agent server
094:             * SipConnectionNotifier queues the incoming requests if the 
095:             * instance of SipServerConnection is not available yet
096:             *
097:             */
098:            public void testSendRegister() {
099:
100:                try {
101:                    // scc.initRequest("REGISTER", scnAssociated);
102:                    scc.initRequest("REGISTER", null);
103:                    scc.send();
104:
105:                } catch (IOException ioe) {
106:                    ioe.printStackTrace();
107:                    cleanup();
108:                    fail("IOException in testSendRegister");
109:                }
110:
111:            }
112:
113:            /**
114:             * Accept a new connection request and process the request from client.
115:             * Send "OK" to client
116:             *
117:             * This method is declared in SipServerConnectionListener
118:             * 
119:             * @param scnLocal Local SIP connection notifier
120:             */
121:            public void notifyRequest(SipConnectionNotifier scnLocal) {
122:                try {
123:                    // block and wait for incoming request.
124:                    // SipServerConnection is establised and returned
125:                    // when new request is received.
126:                    SipServerConnection ssc = scnLocal.acceptAndOpen();
127:                    assertNotNull("ssc is null", ssc);
128:
129:                    if (ssc.getMethod().equals("REGISTER")) {
130:                        ssc.initResponse(200);
131:                        ssc.send();
132:                    }
133:                    ssc.close();
134:                } catch (IOException ioe) {
135:                    assertNull("Unexpected IOException", ioe);
136:                    ioe.printStackTrace();
137:                    cleanup();
138:                }
139:            }
140:
141:            /**
142:             * Received the response from user agent server
143:             *
144:             * This method is declared in SipClientConnectionListener
145:             * 
146:             * @param sccLocal Local SIP Client (UAC)
147:             *
148:             */
149:            public void notifyResponse(SipClientConnection sccLocal) {
150:                try {
151:
152:                    boolean ok = sccLocal.receive(0);
153:
154:                    if (ok) { // response received
155:                        if (sccLocal.getStatusCode() == 200) {
156:                            synchronized (this ) {
157:                                done = true;
158:                                notify();
159:                            }
160:                        }
161:                    }
162:                } catch (Exception ex) {
163:                    // handle Exceptions
164:                    ex.printStackTrace();
165:                }
166:            }
167:
168:            /**
169:             * Close all connections.
170:             *
171:             */
172:            void cleanup() {
173:                // System.out.println("cleanup called");
174:                try {
175:                    if (scc != null) {
176:                        scc.close();
177:                    }
178:
179:                    if (scn != null) {
180:                        scn.close();
181:                    }
182:
183:                    if (scnAssociated != null) {
184:                        scnAssociated.close();
185:                    }
186:                } catch (IOException ioe) {
187:                    assertNull("Unexpected IOException during cleanup", ioe);
188:                    ioe.printStackTrace();
189:                }
190:            }
191:
192:            /**
193:             * Tests execute.
194:             *
195:             */
196:            public void runTests() {
197:                declare("TestRegisterTCP ");
198:
199:                setup();
200:                testSendRegister();
201:
202:                synchronized (this ) {
203:                    while (!done) {
204:                        try {
205:                            wait();
206:                        } catch (InterruptedException e) {
207:                            System.out.println("Catch interrupt");
208:                        }
209:                    }
210:                }
211:
212:                cleanup();
213:
214:                assertTrue("Failure in TestRegisterTCP", done);
215:            }
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.