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


001:        package examples.ims;
002:
003:        import gov.nist.javax.sip.header.HeaderFactoryImpl;
004:        import gov.nist.javax.sip.header.ims.*;
005:
006:        import javax.sip.*;
007:        import javax.sip.address.*;
008:        import javax.sip.header.*;
009:        import javax.sip.message.*;
010:        import java.util.*;
011:
012:        /**
013:         * <p>This class is a UAS template.</p>
014:         * <p>Exemplifies the creation and parsing of the SIP P-Headers for IMS</p>
015:         * 
016:         * <p>based on examples.simplecallsetup, by M. Ranganathan</p>
017:         * <p>issued by Miguel Freitas (IT) PT-Inovacao</p>
018:         */
019:
020:        public class Shootme implements  SipListener {
021:
022:            private static AddressFactory addressFactory;
023:
024:            private static MessageFactory messageFactory;
025:
026:            private static HeaderFactory headerFactory;
027:
028:            private static SipStack sipStack;
029:
030:            private static final String myAddress = "127.0.0.1";
031:
032:            private static final int myPort = 5070;
033:
034:            protected ServerTransaction inviteTid;
035:
036:            private Response okResponse;
037:
038:            private Request inviteRequest;
039:
040:            private Dialog dialog;
041:
042:            public static final boolean callerSendsBye = true;
043:
044:            class MyTimerTask extends TimerTask {
045:                Shootme shootme;
046:
047:                public MyTimerTask(Shootme shootme) {
048:                    this .shootme = shootme;
049:
050:                }
051:
052:                public void run() {
053:                    shootme.sendInviteOK();
054:                }
055:
056:            }
057:
058:            protected static final String usageString = "java "
059:                    + "examples.shootist.Shootist \n"
060:                    + ">>>> is your class path set to the root?";
061:
062:            private static void usage() {
063:                System.out.println(usageString);
064:                System.exit(0);
065:
066:            }
067:
068:            public void processRequest(RequestEvent requestEvent) {
069:                Request request = requestEvent.getRequest();
070:                ServerTransaction serverTransactionId = requestEvent
071:                        .getServerTransaction();
072:
073:                System.out.println("\n\nRequest " + request.getMethod()
074:                        + " received at " + sipStack.getStackName()
075:                        + " with server transaction id " + serverTransactionId);
076:
077:                if (request.getMethod().equals(Request.INVITE)) {
078:                    processInvite(requestEvent, serverTransactionId);
079:                } else if (request.getMethod().equals(Request.ACK)) {
080:                    processAck(requestEvent, serverTransactionId);
081:                } else if (request.getMethod().equals(Request.BYE)) {
082:                    processBye(requestEvent, serverTransactionId);
083:                } else if (request.getMethod().equals(Request.CANCEL)) {
084:                    processCancel(requestEvent, serverTransactionId);
085:                }
086:
087:            }
088:
089:            public void processResponse(ResponseEvent responseEvent) {
090:            }
091:
092:            /**
093:             * Process the ACK request. Send the bye and complete the call flow.
094:             */
095:            public void processAck(RequestEvent requestEvent,
096:                    ServerTransaction serverTransaction) {
097:                try {
098:                    System.out.println("shootme: got an ACK! ");
099:                    System.out.println("Dialog State = " + dialog.getState());
100:                    SipProvider provider = (SipProvider) requestEvent
101:                            .getSource();
102:                    if (!callerSendsBye) {
103:                        Request byeRequest = dialog.createRequest(Request.BYE);
104:                        ClientTransaction ct = provider
105:                                .getNewClientTransaction(byeRequest);
106:                        dialog.sendRequest(ct);
107:                    }
108:                } catch (Exception ex) {
109:                    ex.printStackTrace();
110:                }
111:
112:            }
113:
114:            /**
115:             * Process the invite request.
116:             */
117:            public void processInvite(RequestEvent requestEvent,
118:                    ServerTransaction serverTransaction) {
119:                SipProvider sipProvider = (SipProvider) requestEvent
120:                        .getSource();
121:                Request request = requestEvent.getRequest();
122:
123:                /* ++++++++++++++++++++++++++++++++++++++++++++
124:                 *                IMS headers
125:                 * ++++++++++++++++++++++++++++++++++++++++++++  
126:                 */
127:
128:                // work-around for IMS headers
129:                //HeaderFactoryImpl headerFactoryImpl = new HeaderFactoryImpl();
130:                HeaderFactoryImpl headerFactoryImpl = (HeaderFactoryImpl) headerFactory;
131:
132:                // check headers Allow, Require and Supported
133:
134:                // Allow header
135:                ListIterator li = null;
136:                AllowHeader allow = null;
137:                String allowMethods = new String(); // all the methods in Allow Header
138:                li = request.getHeaders(AllowHeader.NAME); // get all the allow methods
139:                // creates an Allow header for each method
140:
141:                try {
142:                    while (li.hasNext()) // concatenate the method of each Allow header in one string
143:                    {
144:                        allow = (AllowHeader) li.next();
145:                        allowMethods = allowMethods.concat(allow.getMethod())
146:                                .concat(" ");
147:                    }
148:                } catch (Exception ex) {
149:                    System.out
150:                            .println("\n(!) Exception getting Allow header! - "
151:                                    + ex);
152:                }
153:
154:                /*
155:                // Allow: PRACK ??
156:                if (allowMethods.indexOf(Request.PRACK) != -1) 
157:                	System.out.println("\n*** UAC allows PRACK method ");
158:                else
159:                	System.out.println("\n*** UAC does NOT allow PRACK method ");
160:                 */
161:
162:                // Require header
163:                RequireHeader require = null;
164:                String requireOptionTags = new String();
165:                li = null;
166:                li = request.getHeaders(RequireHeader.NAME);
167:                try {
168:                    while (li.hasNext()) {
169:                        require = (RequireHeader) li.next();
170:                        requireOptionTags = requireOptionTags.concat(
171:                                require.getOptionTag()).concat(" ");
172:                    }
173:                } catch (Exception ex) {
174:                    System.out
175:                            .println("\n(!) Exception getting Require header! - "
176:                                    + ex);
177:                }
178:
179:                /*
180:                // Require: 100rel ??
181:                if (requireOptionTags.indexOf("100rel") != -1) 
182:                	System.out.println("\n*** UAC requires \"100rel\"");
183:                else
184:                	System.out.println("\n*** UAC does NOT require \"100rel\"");
185:                // Require: precondition ??
186:                if (requireOptionTags.indexOf("precondition") != -1) 
187:                	System.out.println("\n*** UAC requires \"precondition\"");
188:                else
189:                	System.out.println("\n*** UAC does NOT require \"precondition\"");
190:                // Require: sec-agree ??
191:                if (requireOptionTags.indexOf("sec-agree") != -1) 
192:                	System.out.println("\n*** UAC requires \"sec-agree\"");
193:                else
194:                	System.out.println("\n*** UAC does NOT require \"sec-agree\"");
195:                 */
196:
197:                // Supported header
198:                SupportedHeader supported = null;
199:                String supportedOptionTags = new String();
200:                li = request.getHeaders(SupportedHeader.NAME);
201:                try {
202:                    while (li.hasNext()) {
203:                        supported = (SupportedHeader) li.next();
204:                        supportedOptionTags = supportedOptionTags.concat(
205:                                supported.getOptionTag()).concat(" ");
206:                    }
207:                } catch (NullPointerException ex) {
208:                    System.out
209:                            .println("\n(!) Exception getting Supported header! - "
210:                                    + ex);
211:                }
212:
213:                /*
214:                // Supported: 100rel ??
215:                if (supportedOptionTags.indexOf("100rel") != -1) 
216:                	System.out.println("\n*** UAC supports \"100rel\"");
217:                else
218:                	System.out.println("\n*** UAC does NOT support \"100rel\"");
219:                
220:                // Supported: precondition ??
221:                if (supportedOptionTags.indexOf("precondition") != -1) 
222:                	System.out.println("\n*** UAC supports \"precondition\"");
223:                else
224:                	System.out.println("\n*** UAC does NOT support \"precondition\"");
225:                 */
226:
227:                // check P-Headers
228:                // check P-Called-Party-ID
229:                PCalledPartyIDHeader calledParty;
230:                try {
231:                    calledParty = (PCalledPartyIDHeader) request
232:                            .getHeader(PCalledPartyIDHeader.NAME);
233:
234:                    if (calledParty != null) {
235:                        System.out.println(".: P-Called-Party-ID = "
236:                                + calledParty.getAddress().toString());
237:                    } else
238:                        System.out
239:                                .println(".: NOT received P-Called-Party-ID ! ");
240:
241:                } catch (Exception ex) {
242:                    System.out
243:                            .println("(!) Exception getting P-Called-Party-ID header! - "
244:                                    + ex);
245:                }
246:
247:                // check P-Associated-URI
248:                ListIterator associatedURIList;
249:                try {
250:                    associatedURIList = request
251:                            .getHeaders(PAssociatedURIHeader.NAME);
252:                    if (associatedURIList != null) {
253:                        System.out.print(".: P-Associated-URI = ");
254:                        while (associatedURIList.hasNext()) {
255:                            PAssociatedURIHeader associatedURI = (PAssociatedURIHeader) associatedURIList
256:                                    .next();
257:
258:                            System.out.print(associatedURI.getAssociatedURI()
259:                                    .toString());
260:                            if (associatedURIList.hasNext())
261:                                System.out.print(", ");
262:
263:                        }
264:                    } else
265:                        System.out
266:                                .println(".: NOT received P-Associated-URI ! ");
267:
268:                    System.out.print("\n");
269:                } catch (Exception ex) {
270:                    System.out
271:                            .println("(!) Exception getting P-Associated-URI header! - "
272:                                    + ex);
273:                }
274:
275:                // check P-Access-Network-Info 
276:                PAccessNetworkInfoHeader accessInfo = null;
277:                try {
278:                    accessInfo = (PAccessNetworkInfoHeader) request
279:                            .getHeader(PAccessNetworkInfoHeader.NAME);
280:                    if (accessInfo != null) {
281:                        System.out
282:                                .print(".: P-Access-Network-Info: Access Type = "
283:                                        + accessInfo.getAccessType());
284:
285:                        if (accessInfo.getAccessType().equalsIgnoreCase(
286:                                PAccessNetworkInfoHeader.GGGPP_UTRAN_TDD)) // 3GPP-UTRAN-TDD
287:                            System.out.print(" - Cell ID = "
288:                                    + accessInfo.getUtranCellID3GPP());
289:                    } else
290:                        System.out
291:                                .println(".: NOT received P-Access-Network-Info ! ");
292:
293:                    System.out.println("");
294:                } catch (Exception ex) {
295:                    System.out
296:                            .println("(!) Exception getting P-Access-Network-Info header! - "
297:                                    + ex);
298:                }
299:
300:                // check if .clone() and .equals() is working
301:                if (accessInfo != null) {
302:                    PAccessNetworkInfo accessInfoClone = (PAccessNetworkInfo) accessInfo
303:                            .clone();
304:
305:                    System.out.println("--> clone = "
306:                            + accessInfoClone.toString());
307:                    System.out.println("--> equals? "
308:                            + accessInfoClone.equals(accessInfo));
309:                }
310:
311:                // check P-Visited-Network-ID
312:                ListIterator visitedNetList;
313:                try {
314:                    visitedNetList = request
315:                            .getHeaders(PVisitedNetworkIDHeader.NAME);
316:                    if (visitedNetList != null) {
317:                        System.out.print(".: P-Visited-Network-ID = ");
318:                        while (visitedNetList.hasNext()) {
319:                            PVisitedNetworkIDHeader visitedID = (PVisitedNetworkIDHeader) visitedNetList
320:                                    .next();
321:                            System.out.print(visitedID.getVisitedNetworkID());
322:                            if (visitedNetList.hasNext())
323:                                System.out.print(", ");
324:                        }
325:                        System.out.print("\n");
326:                    } else
327:                        System.out
328:                                .print(".: NOT received P-Visited-Network-ID ! ");
329:                } catch (Exception ex) {
330:                    System.out
331:                            .println("(!) Exception getting P-Visited-Network-ID header! - "
332:                                    + ex);
333:                }
334:
335:                // check Privacy
336:                ListIterator privacyList;
337:                try {
338:                    privacyList = request.getHeaders(PrivacyHeader.NAME);
339:                    if (privacyList != null && privacyList.hasNext()) {
340:                        System.out.print(".: Privacy = ");
341:                        while (privacyList.hasNext()) {
342:                            PrivacyHeader privacy = (PrivacyHeader) privacyList
343:                                    .next();
344:                            System.out.print(privacy.getPrivacy());
345:                            if (privacyList.hasNext())
346:                                System.out.print("; ");
347:                        }
348:                        System.out.println("");
349:                    } else
350:                        System.out.println(".: NOT received Privacy ! ");
351:                }
352:
353:                catch (Exception ex) {
354:                    System.out
355:                            .println("(!) Exception getting Privacy header! - "
356:                                    + ex);
357:                }
358:
359:                // check P-Preferred-Identity
360:                PPreferredIdentityHeader preferredID;
361:                try {
362:                    preferredID = (PPreferredIdentityHeader) request
363:                            .getHeader(PPreferredIdentityHeader.NAME);
364:                    if (preferredID != null) {
365:                        System.out.println(".: P-Preferred-Identity = "
366:                                + preferredID.getAddress().toString());
367:                    } else
368:                        System.out
369:                                .println(".: NOT received P-Preferred-Identity ! ");
370:                } catch (Exception ex) {
371:                    System.out
372:                            .println("(!) Exception getting P-Preferred-Identity header! - "
373:                                    + ex);
374:                }
375:
376:                /*
377:                 * TEST
378:                 */
379:                // this is only to illustrate the usage of this headers
380:
381:                // P-Asserted-Identity
382:                ListIterator assertedIDList;
383:                try {
384:                    assertedIDList = request
385:                            .getHeaders(PAssertedIdentityHeader.NAME);
386:                    if (assertedIDList != null && assertedIDList.hasNext()) {
387:                        System.out.print(".: P-Asserted-Identity = ");
388:                        while (assertedIDList.hasNext()) {
389:                            PAssertedIdentityHeader assertedID = (PAssertedIdentityHeader) assertedIDList
390:                                    .next();
391:                            System.out
392:                                    .print(assertedID.getAddress().toString());
393:                            if (assertedIDList.hasNext())
394:                                System.out.print(", ");
395:                        }
396:                        System.out.println("");
397:                    } else
398:                        System.out
399:                                .println(".: NOT received P-Asserted-Identity... ");
400:                } catch (Exception ex) {
401:                    System.out
402:                            .println("(!) Exception getting P-Asserted-Identity header! - "
403:                                    + ex);
404:                }
405:
406:                // P-Charging-Function-Addresses
407:                PChargingFunctionAddressesHeader chargAddr;
408:                try {
409:                    chargAddr = (PChargingFunctionAddressesHeader) request
410:                            .getHeader(PChargingFunctionAddressesHeader.NAME);
411:
412:                    if (chargAddr != null) {
413:                        Iterator param = chargAddr.getParameterNames();
414:
415:                        System.out.print(".: P-Charging-Function-Addresses = ");
416:
417:                        if (param != null) {
418:                            while (param.hasNext()) {
419:                                String paramName = (String) param.next();
420:                                System.out.print(paramName + "="
421:                                        + chargAddr.getParameter(paramName));
422:                                if (param.hasNext())
423:                                    System.out.print(", ");
424:                            }
425:                        }
426:                        System.out.println("");
427:                    } else
428:                        System.out
429:                                .println(".: NOT containing P-Charging-Function-Addresses... ");
430:                } catch (Exception ex) {
431:                    System.out
432:                            .println("(!) Exception getting P-Charging-Function-Addresses header! - "
433:                                    + ex);
434:                }
435:
436:                // P-Charging-Vector
437:                PChargingVectorHeader chargVect;
438:                try {
439:                    chargVect = (PChargingVectorHeader) request
440:                            .getHeader(PChargingVectorHeader.NAME);
441:                    if (chargVect != null) {
442:                        Iterator param = chargVect.getParameterNames();
443:
444:                        System.out.print(".: P-Charging-Vector = ");
445:
446:                        if (param != null && param.hasNext()) {
447:                            while (param.hasNext()) {
448:                                String paramName = (String) param.next();
449:                                System.out.print(paramName + "="
450:                                        + chargVect.getParameter(paramName));
451:                                if (param.hasNext())
452:                                    System.out.print(", ");
453:                            }
454:                        }
455:                        System.out.println("");
456:                    } else
457:                        System.out
458:                                .println(".: NOT containing P-Charging-Vector... ");
459:                } catch (Exception ex) {
460:                    System.out
461:                            .println("(!) Exception getting P-Charging-Vector header! - "
462:                                    + ex);
463:                }
464:
465:                // P-Media-Authorization
466:                ListIterator mediaAuthList;
467:                try {
468:                    mediaAuthList = request
469:                            .getHeaders(PMediaAuthorizationHeader.NAME);
470:
471:                    if (mediaAuthList != null) {
472:                        System.out.print(".: P-Media-Authorization = ");
473:                        while (mediaAuthList.hasNext()) {
474:                            PMediaAuthorizationHeader mediaAuth = (PMediaAuthorizationHeader) mediaAuthList
475:                                    .next();
476:                            System.out.print(mediaAuth.getToken());
477:                            if (mediaAuthList.hasNext())
478:                                System.out.print(", ");
479:                        }
480:                        System.out.println("");
481:                    } else
482:                        System.out
483:                                .println(".: NOT containing P-Media-Authorization... ");
484:                } catch (Exception ex) {
485:                    System.out
486:                            .println("(!) Exception getting P-Media-Authorization header! - "
487:                                    + ex);
488:                }
489:
490:                // Security-Client header
491:                ListIterator secClientList;
492:                try {
493:                    secClientList = request
494:                            .getHeaders(SecurityClientHeader.NAME);
495:
496:                    if (secClientList != null) {
497:                        while (secClientList.hasNext()) {
498:                            System.out.println(".: "
499:                                    + ((SecurityClientHeader) secClientList
500:                                            .next()).toString());
501:                        }
502:                    } else
503:                        System.out
504:                                .println(".: NOT containing Security-Client header... ");
505:                } catch (Exception ex) {
506:                    System.out
507:                            .println("(!) Exception getting Security-Client header! - "
508:                                    + ex);
509:                }
510:
511:                // this is only to illustrate the usage of this headers
512:                // send Security-Server if Require: sec-agree
513:                SecurityServerList secServerList = null;
514:                if (requireOptionTags.indexOf("sec-agree") != -1) {
515:                    secServerList = new SecurityServerList();
516:                    try {
517:                        SecurityServerHeader secServer1 = headerFactoryImpl
518:                                .createSecurityClientHeader();
519:                        secServer1.setSecurityMechanism("ipsec-3gpp");
520:                        secServer1.setAlgorithm("hmac-md5-96");
521:                        secServer1.setEncryptionAlgorithm("des-cbc");
522:                        secServer1.setSPIClient(10000);
523:                        secServer1.setSPIServer(10001);
524:                        secServer1.setPortClient(5063);
525:                        secServer1.setPortServer(4166);
526:                        secServer1.setPreference(0.1f);
527:
528:                        SecurityServerHeader secServer2 = headerFactoryImpl
529:                                .createSecurityClientHeader();
530:                        secServer2.setSecurityMechanism("ipsec-3gpp");
531:                        secServer2.setAlgorithm("hmac-md5-96");
532:                        secServer2.setEncryptionAlgorithm("des-cbc");
533:                        secServer2.setSPIClient(20000);
534:                        secServer2.setSPIServer(20001);
535:                        secServer2.setPortClient(5073);
536:                        secServer2.setPortServer(4286);
537:                        secServer2.setPreference(0.5f);
538:
539:                        request.addHeader(secServer1);
540:                        request.addHeader(secServer2);
541:
542:                    } catch (Exception ex) {
543:                        System.out
544:                                .println("(!) Exception adding Security-Server header : "
545:                                        + ex);
546:                    }
547:
548:                }
549:
550:                // check Path header
551:                ListIterator<Header> pathList = (ListIterator<Header>) request
552:                        .getHeaders(PathHeader.NAME);
553:                if (pathList != null && pathList.hasNext()) {
554:                    System.out.print(".: Path received : ");
555:                    while (pathList.hasNext()) {
556:                        PathHeader path = (PathHeader) pathList.next();
557:                        if (path != null)
558:                            System.out.print(path.getAddress().toString());
559:                        if (pathList.hasNext())
560:                            System.out.print(", ");
561:                    }
562:                    System.out.println("");
563:                }
564:
565:                /////////////////////////////////////////
566:
567:                try {
568:                    System.out.println("shootme: got an Invite sending Trying");
569:                    // System.out.println("shootme: " + request);
570:                    Response response = messageFactory.createResponse(
571:                            Response.TRYING, request);
572:                    ServerTransaction st = requestEvent.getServerTransaction();
573:
574:                    if (st == null) {
575:                        st = sipProvider.getNewServerTransaction(request);
576:                    }
577:                    dialog = st.getDialog();
578:
579:                    st.sendResponse(response);
580:
581:                    this .okResponse = messageFactory.createResponse(
582:                            Response.OK, request);
583:                    Address address = addressFactory
584:                            .createAddress("Shootme <sip:" + myAddress + ":"
585:                                    + myPort + ">");
586:                    ContactHeader contactHeader = headerFactory
587:                            .createContactHeader(address);
588:                    response.addHeader(contactHeader);
589:                    ToHeader toHeader = (ToHeader) okResponse
590:                            .getHeader(ToHeader.NAME);
591:                    toHeader.setTag("4321"); // Application is supposed to set.
592:                    okResponse.addHeader(contactHeader);
593:                    this .inviteTid = st;
594:                    // Defer sending the OK to simulate the phone ringing.
595:                    // Answered in 1 second ( this guy is fast at taking calls)
596:                    this .inviteRequest = request;
597:
598:                    // add Security-Server header
599:                    if (secServerList != null && !secServerList.isEmpty()) {
600:                        RequireHeader requireHeader = headerFactory
601:                                .createRequireHeader("sec-agree");
602:                        this .okResponse.setHeader(requireHeader);
603:
604:                        this .okResponse.setHeader(secServerList);
605:                    }
606:
607:                    new Timer().schedule(new MyTimerTask(this ), 1000);
608:                } catch (Exception ex) {
609:                    ex.printStackTrace();
610:                    System.exit(0);
611:                }
612:            }
613:
614:            private void sendInviteOK() {
615:                try {
616:                    if (inviteTid.getState() != TransactionState.COMPLETED) {
617:                        System.out.println("shootme: Dialog state before 200: "
618:                                + inviteTid.getDialog().getState());
619:                        inviteTid.sendResponse(okResponse);
620:                        System.out.println("shootme: Dialog state after 200: "
621:                                + inviteTid.getDialog().getState());
622:                    }
623:                } catch (SipException ex) {
624:                    ex.printStackTrace();
625:                } catch (InvalidArgumentException ex) {
626:                    ex.printStackTrace();
627:                }
628:            }
629:
630:            /**
631:             * Process the bye request.
632:             */
633:            public void processBye(RequestEvent requestEvent,
634:                    ServerTransaction serverTransactionId) {
635:                SipProvider sipProvider = (SipProvider) requestEvent
636:                        .getSource();
637:                Request request = requestEvent.getRequest();
638:                Dialog dialog = requestEvent.getDialog();
639:                System.out.println("local party = " + dialog.getLocalParty());
640:                try {
641:                    System.out.println("shootme:  got a bye sending OK.");
642:                    Response response = messageFactory.createResponse(200,
643:                            request);
644:                    serverTransactionId.sendResponse(response);
645:                    System.out.println("Dialog State is "
646:                            + serverTransactionId.getDialog().getState());
647:
648:                } catch (Exception ex) {
649:                    ex.printStackTrace();
650:                    System.exit(0);
651:
652:                }
653:            }
654:
655:            public void processCancel(RequestEvent requestEvent,
656:                    ServerTransaction serverTransactionId) {
657:                SipProvider sipProvider = (SipProvider) requestEvent
658:                        .getSource();
659:                Request request = requestEvent.getRequest();
660:                try {
661:                    System.out.println("shootme:  got a cancel.");
662:                    if (serverTransactionId == null) {
663:                        System.out.println("shootme:  null tid.");
664:                        return;
665:                    }
666:                    Response response = messageFactory.createResponse(200,
667:                            request);
668:                    serverTransactionId.sendResponse(response);
669:                    if (dialog.getState() != DialogState.CONFIRMED) {
670:                        response = messageFactory.createResponse(
671:                                Response.REQUEST_TERMINATED, inviteRequest);
672:                        inviteTid.sendResponse(response);
673:                    }
674:
675:                } catch (Exception ex) {
676:                    ex.printStackTrace();
677:                    System.exit(0);
678:
679:                }
680:            }
681:
682:            public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
683:                Transaction transaction;
684:                if (timeoutEvent.isServerTransaction()) {
685:                    transaction = timeoutEvent.getServerTransaction();
686:                } else {
687:                    transaction = timeoutEvent.getClientTransaction();
688:                }
689:                System.out.println("state = " + transaction.getState());
690:                System.out.println("dialog = " + transaction.getDialog());
691:                System.out.println("dialogState = "
692:                        + transaction.getDialog().getState());
693:                System.out.println("Transaction Time out");
694:            }
695:
696:            public void init() {
697:                SipFactory sipFactory = null;
698:                sipStack = null;
699:                sipFactory = SipFactory.getInstance();
700:                sipFactory.setPathName("gov.nist");
701:                Properties properties = new Properties();
702:                properties.setProperty("javax.sip.STACK_NAME", "shootme");
703:                // You need 16 for logging traces. 32 for debug + traces.
704:                // Your code will limp at 32 but it is best for debugging.
705:                properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
706:                properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
707:                        "shootmedebug.txt");
708:                properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
709:                        "shootmelog.txt");
710:
711:                try {
712:                    // Create SipStack object
713:                    sipStack = sipFactory.createSipStack(properties);
714:                    System.out.println("sipStack = " + sipStack);
715:                } catch (PeerUnavailableException e) {
716:                    // could not find
717:                    // gov.nist.jain.protocol.ip.sip.SipStackImpl
718:                    // in the classpath
719:                    e.printStackTrace();
720:                    System.err.println(e.getMessage());
721:                    if (e.getCause() != null)
722:                        e.getCause().printStackTrace();
723:                    System.exit(0);
724:                }
725:
726:                try {
727:                    headerFactory = sipFactory.createHeaderFactory();
728:                    addressFactory = sipFactory.createAddressFactory();
729:                    messageFactory = sipFactory.createMessageFactory();
730:                    ListeningPoint lp = sipStack.createListeningPoint(
731:                            "127.0.0.1", myPort, "udp");
732:
733:                    Shootme listener = this ;
734:
735:                    SipProvider sipProvider = sipStack.createSipProvider(lp);
736:                    System.out.println("udp provider " + sipProvider);
737:                    sipProvider.addSipListener(listener);
738:
739:                } catch (Exception ex) {
740:                    System.out.println(ex.getMessage());
741:                    ex.printStackTrace();
742:                    usage();
743:                }
744:
745:            }
746:
747:            public static void main(String args[]) {
748:                new Shootme().init();
749:            }
750:
751:            public void processIOException(IOExceptionEvent exceptionEvent) {
752:                System.out.println("IOException");
753:
754:            }
755:
756:            public void processTransactionTerminated(
757:                    TransactionTerminatedEvent transactionTerminatedEvent) {
758:                if (transactionTerminatedEvent.isServerTransaction())
759:                    System.out
760:                            .println("Transaction terminated event recieved"
761:                                    + transactionTerminatedEvent
762:                                            .getServerTransaction());
763:                else
764:                    System.out
765:                            .println("Transaction terminated "
766:                                    + transactionTerminatedEvent
767:                                            .getClientTransaction());
768:
769:            }
770:
771:            public void processDialogTerminated(
772:                    DialogTerminatedEvent dialogTerminatedEvent) {
773:                System.out.println("Dialog terminated event recieved");
774:                Dialog d = dialogTerminatedEvent.getDialog();
775:                System.out.println("Local Party = " + d.getLocalParty());
776:
777:            }
778:
779:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.