Source Code Cross Referenced for Shootme.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » test » tck » msgflow » callflows » router » 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 » Java Advanced Imaging » test.tck.msgflow.callflows.router 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Conditions Of Use 
003:         * 
004:         * This software was developed by employees of the National Institute of
005:         * Standards and Technology (NIST), and others. 
006:         * This software is has been contributed to the public domain. 
007:         * As a result, a formal license is not needed to use the software.
008:         * 
009:         * This software is provided "AS IS."  
010:         * NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
011:         * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
012:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
013:         * AND DATA ACCURACY.  NIST does not warrant or make any representations
014:         * regarding the use of the software or the results thereof, including but
015:         * not limited to the correctness, accuracy, reliability or usefulness of
016:         * the software.
017:         * 
018:         * 
019:         */
020:        package test.tck.msgflow.callflows.router;
021:
022:        import javax.sip.*;
023:        import javax.sip.address.*;
024:        import javax.sip.header.*;
025:        import javax.sip.message.*;
026:
027:        import org.apache.log4j.Logger;
028:
029:        import test.tck.TestHarness;
030:        import test.tck.msgflow.callflows.ProtocolObjects;
031:
032:        import java.util.*;
033:
034:        /**
035:         * This class is a UAC template.
036:         * 
037:         * @author M. Ranganathan
038:         */
039:
040:        public class Shootme implements  SipListener {
041:
042:            private static SipProvider sipProvider;
043:
044:            private static AddressFactory addressFactory;
045:
046:            private static MessageFactory messageFactory;
047:
048:            private static HeaderFactory headerFactory;
049:
050:            private static SipStack sipStack;
051:
052:            private static final String myAddress = "127.0.0.1";
053:
054:            protected ServerTransaction inviteTid;
055:
056:            private Dialog dialog;
057:
058:            private String toTag;
059:
060:            private String transport;
061:
062:            private boolean inviteReceived;
063:
064:            public static final int myPort = 5080;
065:
066:            private static Logger logger = Logger.getLogger("test.tck");
067:
068:            public Shootme(ProtocolObjects protObjects) {
069:                addressFactory = protObjects.addressFactory;
070:                messageFactory = protObjects.messageFactory;
071:                headerFactory = protObjects.headerFactory;
072:                sipStack = protObjects.sipStack;
073:                transport = protObjects.transport;
074:            }
075:
076:            public void processRequest(RequestEvent requestEvent) {
077:                Request request = requestEvent.getRequest();
078:                ServerTransaction serverTransactionId = requestEvent
079:                        .getServerTransaction();
080:
081:                logger.info("\n\nRequest " + request.getMethod()
082:                        + " received at " + sipStack.getStackName()
083:                        + " with server transaction id " + serverTransactionId);
084:
085:                if (request.getMethod().equals(Request.INVITE)) {
086:                    processInvite(requestEvent, serverTransactionId);
087:                } else if (request.getMethod().equals(Request.ACK)) {
088:                    processAck(requestEvent, serverTransactionId);
089:                } else if (request.getMethod().equals(Request.BYE)) {
090:                    processBye(requestEvent, serverTransactionId);
091:                }
092:
093:            }
094:
095:            public void processResponse(ResponseEvent responseEvent) {
096:            }
097:
098:            /**
099:             * Process the ACK request. Send the bye and complete the call flow.
100:             */
101:            public void processAck(RequestEvent requestEvent,
102:                    ServerTransaction serverTransaction) {
103:
104:                try {
105:                    logger.info("shootme: got an ACK! Sending  a BYE");
106:                    logger.info("Dialog State = " + dialog.getState());
107:                    Dialog dialog = serverTransaction.getDialog();
108:                    AbstractRouterTestCase.assertTrue("Dialog mismatch",
109:                            dialog == this .dialog);
110:                    SipProvider provider = (SipProvider) requestEvent
111:                            .getSource();
112:                    AbstractRouterTestCase.assertTrue("Provider mismatch",
113:                            sipProvider == provider);
114:                    Request byeRequest = dialog.createRequest(Request.BYE);
115:                    ClientTransaction ct = provider
116:                            .getNewClientTransaction(byeRequest);
117:                    dialog.sendRequest(ct);
118:                } catch (Exception ex) {
119:                    TestHarness.fail(ex.getMessage());
120:                }
121:
122:            }
123:
124:            /**
125:             * Process the invite request.
126:             */
127:            public void processInvite(RequestEvent requestEvent,
128:                    ServerTransaction serverTransaction) {
129:                inviteReceived = true;
130:                SipProvider sipProvider = (SipProvider) requestEvent
131:                        .getSource();
132:                Request request = requestEvent.getRequest();
133:                try {
134:                    logger.info("shootme: got an Invite sending Trying");
135:                    // logger.info("shootme: " + request);
136:                    Response response = messageFactory.createResponse(
137:                            Response.TRYING, request);
138:                    ServerTransaction st = requestEvent.getServerTransaction();
139:
140:                    if (st == null) {
141:                        st = sipProvider.getNewServerTransaction(request);
142:                    }
143:                    dialog = st.getDialog();
144:
145:                    st.sendResponse(response);
146:
147:                    // reliable provisional response.
148:
149:                    Response okResponse = messageFactory.createResponse(
150:                            Response.OK, request);
151:                    ToHeader toHeader = (ToHeader) okResponse
152:                            .getHeader(ToHeader.NAME);
153:                    this .toTag = "4321";
154:                    toHeader.setTag(toTag); // Application is supposed to set.
155:                    this .inviteTid = st;
156:                    Address address = addressFactory
157:                            .createAddress("Shootme <sip:" + myAddress + ":"
158:                                    + myPort + ">");
159:                    ContactHeader contactHeader = headerFactory
160:                            .createContactHeader(address);
161:                    okResponse.addHeader(contactHeader);
162:
163:                    logger.info("sending response.");
164:
165:                    st.sendResponse(okResponse);
166:
167:                    // new Timer().schedule(new MyTimerTask(this), 100);
168:                } catch (Exception ex) {
169:                    TestHarness.fail(ex.getMessage());
170:
171:                }
172:            }
173:
174:            /**
175:             * Process the bye request.
176:             */
177:            public void processBye(RequestEvent requestEvent,
178:                    ServerTransaction serverTransactionId) {
179:                Request request = requestEvent.getRequest();
180:                try {
181:                    logger.info("shootme:  got a bye sending OK.");
182:                    Response response = messageFactory.createResponse(200,
183:                            request);
184:                    serverTransactionId.sendResponse(response);
185:                    logger.info("Dialog State is "
186:                            + serverTransactionId.getDialog().getState());
187:
188:                } catch (Exception ex) {
189:                    TestHarness.fail(ex.getMessage());
190:                    System.exit(0);
191:
192:                }
193:            }
194:
195:            public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
196:                Transaction transaction;
197:                if (timeoutEvent.isServerTransaction()) {
198:                    transaction = timeoutEvent.getServerTransaction();
199:                } else {
200:                    transaction = timeoutEvent.getClientTransaction();
201:                }
202:                logger.info("state = " + transaction.getState());
203:                logger.info("dialog = " + transaction.getDialog());
204:                logger.info("dialogState = "
205:                        + transaction.getDialog().getState());
206:                logger.info("Transaction Time out");
207:            }
208:
209:            public SipProvider createProvider() throws Exception {
210:                ListeningPoint lp = sipStack.createListeningPoint("127.0.0.1",
211:                        myPort, transport);
212:
213:                sipProvider = sipStack.createSipProvider(lp);
214:                logger.info(transport + " SIP provider " + sipProvider);
215:
216:                return sipProvider;
217:            }
218:
219:            public void processIOException(IOExceptionEvent exceptionEvent) {
220:                logger.info("IOException");
221:
222:            }
223:
224:            public void processTransactionTerminated(
225:                    TransactionTerminatedEvent transactionTerminatedEvent) {
226:                logger.info("Transaction terminated event recieved");
227:
228:            }
229:
230:            public void processDialogTerminated(
231:                    DialogTerminatedEvent dialogTerminatedEvent) {
232:                logger.info("Dialog terminated event recieved");
233:
234:            }
235:
236:            public void checkState() {
237:                TestHarness.assertTrue(inviteReceived);
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.