Source Code Cross Referenced for DialogIdentityTest.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » test » unit » gov » nist » javax » sip » 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 » Java Advanced Imaging » test.unit.gov.nist.javax.sip.stack 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package test.unit.gov.nist.javax.sip.stack;
002:
003:        import java.text.ParseException;
004:        import java.util.ArrayList;
005:        import java.util.Properties;
006:        import java.util.Timer;
007:        import java.util.TimerTask;
008:
009:        import javax.sip.ClientTransaction;
010:        import javax.sip.Dialog;
011:        import javax.sip.DialogState;
012:        import javax.sip.DialogTerminatedEvent;
013:        import javax.sip.IOExceptionEvent;
014:        import javax.sip.InvalidArgumentException;
015:        import javax.sip.ListeningPoint;
016:        import javax.sip.PeerUnavailableException;
017:        import javax.sip.RequestEvent;
018:        import javax.sip.ResponseEvent;
019:        import javax.sip.ServerTransaction;
020:        import javax.sip.SipException;
021:        import javax.sip.SipFactory;
022:        import javax.sip.SipListener;
023:        import javax.sip.SipProvider;
024:        import javax.sip.SipStack;
025:        import javax.sip.Transaction;
026:        import javax.sip.TransactionState;
027:        import javax.sip.TransactionTerminatedEvent;
028:        import javax.sip.address.Address;
029:        import javax.sip.address.AddressFactory;
030:        import javax.sip.address.SipURI;
031:        import javax.sip.header.CSeqHeader;
032:        import javax.sip.header.CallIdHeader;
033:        import javax.sip.header.ContactHeader;
034:        import javax.sip.header.ContentTypeHeader;
035:        import javax.sip.header.FromHeader;
036:        import javax.sip.header.Header;
037:        import javax.sip.header.HeaderFactory;
038:        import javax.sip.header.MaxForwardsHeader;
039:        import javax.sip.header.ToHeader;
040:        import javax.sip.header.ViaHeader;
041:        import javax.sip.message.MessageFactory;
042:        import javax.sip.message.Request;
043:        import javax.sip.message.Response;
044:
045:        import junit.framework.TestCase;
046:
047:        public class DialogIdentityTest extends TestCase {
048:            private static AddressFactory addressFactory;
049:
050:            private static MessageFactory messageFactory;
051:
052:            private static HeaderFactory headerFactory;
053:
054:            private class Shootme implements  SipListener {
055:
056:                private SipStack sipStack;
057:
058:                private static final String myAddress = "127.0.0.1";
059:
060:                private static final int myPort = 5070;
061:
062:                protected ServerTransaction inviteTid;
063:
064:                private Response okResponse;
065:
066:                private Request inviteRequest;
067:
068:                private Dialog dialog;
069:
070:                public static final boolean callerSendsBye = true;
071:
072:                class MyTimerTask extends TimerTask {
073:                    Shootme shootme;
074:
075:                    public MyTimerTask(Shootme shootme) {
076:                        this .shootme = shootme;
077:
078:                    }
079:
080:                    public void run() {
081:                        shootme.sendInviteOK();
082:                    }
083:
084:                }
085:
086:                protected static final String usageString = "java "
087:                        + "examples.shootist.Shootist \n"
088:                        + ">>>> is your class path set to the root?";
089:
090:                public void processRequest(RequestEvent requestEvent) {
091:                    Request request = requestEvent.getRequest();
092:                    ServerTransaction serverTransactionId = requestEvent
093:                            .getServerTransaction();
094:
095:                    System.out.println("\n\nRequest " + request.getMethod()
096:                            + " received at " + sipStack.getStackName()
097:                            + " with server transaction id "
098:                            + serverTransactionId);
099:
100:                    if (request.getMethod().equals(Request.INVITE)) {
101:                        processInvite(requestEvent, serverTransactionId);
102:                    } else if (request.getMethod().equals(Request.ACK)) {
103:                        processAck(requestEvent, serverTransactionId);
104:                    } else if (request.getMethod().equals(Request.BYE)) {
105:                        processBye(requestEvent, serverTransactionId);
106:                    } else if (request.getMethod().equals(Request.CANCEL)) {
107:                        processCancel(requestEvent, serverTransactionId);
108:                    } else {
109:                        try {
110:                            serverTransactionId.sendResponse(messageFactory
111:                                    .createResponse(202, request));
112:
113:                            // send one back
114:                            SipProvider prov = (SipProvider) requestEvent
115:                                    .getSource();
116:                            Request refer = requestEvent.getDialog()
117:                                    .createRequest("REFER");
118:                            requestEvent.getDialog().sendRequest(
119:                                    prov.getNewClientTransaction(refer));
120:
121:                        } catch (SipException e) {
122:                            // TODO Auto-generated catch block
123:                            e.printStackTrace();
124:                        } catch (InvalidArgumentException e) {
125:                            // TODO Auto-generated catch block
126:                            e.printStackTrace();
127:                        } catch (ParseException e) {
128:                            // TODO Auto-generated catch block
129:                            e.printStackTrace();
130:                        }
131:                    }
132:
133:                }
134:
135:                public void processResponse(ResponseEvent responseEvent) {
136:                }
137:
138:                /**
139:                 * Process the ACK request. Send the bye and complete the call flow.
140:                 */
141:                public void processAck(RequestEvent requestEvent,
142:                        ServerTransaction serverTransaction) {
143:                    try {
144:                        System.out.println("shootme: got an ACK! ");
145:                        System.out.println("Dialog State = "
146:                                + dialog.getState());
147:                        SipProvider provider = (SipProvider) requestEvent
148:                                .getSource();
149:                        if (!callerSendsBye) {
150:                            Request byeRequest = dialog
151:                                    .createRequest(Request.BYE);
152:                            ClientTransaction ct = provider
153:                                    .getNewClientTransaction(byeRequest);
154:                            dialog.sendRequest(ct);
155:                        }
156:                    } catch (Exception ex) {
157:                        ex.printStackTrace();
158:                    }
159:
160:                }
161:
162:                /**
163:                 * Process the invite request.
164:                 */
165:                public void processInvite(RequestEvent requestEvent,
166:                        ServerTransaction serverTransaction) {
167:                    SipProvider sipProvider = (SipProvider) requestEvent
168:                            .getSource();
169:                    Request request = requestEvent.getRequest();
170:                    try {
171:                        System.out
172:                                .println("shootme: got an Invite sending Trying");
173:                        // System.out.println("shootme: " + request);
174:                        Response response = messageFactory.createResponse(
175:                                Response.RINGING, request);
176:                        ServerTransaction st = requestEvent
177:                                .getServerTransaction();
178:
179:                        if (st == null) {
180:                            st = sipProvider.getNewServerTransaction(request);
181:                        }
182:                        dialog = st.getDialog();
183:
184:                        st.sendResponse(response);
185:
186:                        this .okResponse = messageFactory.createResponse(
187:                                Response.OK, request);
188:                        Address address = addressFactory
189:                                .createAddress("Shootme <sip:" + myAddress
190:                                        + ":" + myPort + ">");
191:                        ContactHeader contactHeader = headerFactory
192:                                .createContactHeader(address);
193:                        response.addHeader(contactHeader);
194:                        ToHeader toHeader = (ToHeader) okResponse
195:                                .getHeader(ToHeader.NAME);
196:                        toHeader.setTag("4321"); // Application is supposed to set.
197:                        okResponse.addHeader(contactHeader);
198:                        this .inviteTid = st;
199:                        // Defer sending the OK to simulate the phone ringing.
200:                        // Answered in 1 second ( this guy is fast at taking calls)
201:                        this .inviteRequest = request;
202:
203:                        new Timer().schedule(new MyTimerTask(this ), 1000);
204:                    } catch (Exception ex) {
205:                        ex.printStackTrace();
206:                        System.exit(0);
207:                    }
208:                }
209:
210:                private void sendInviteOK() {
211:                    try {
212:                        if (inviteTid.getState() != TransactionState.COMPLETED) {
213:                            System.out
214:                                    .println("shootme: Dialog state before 200: "
215:                                            + inviteTid.getDialog().getState());
216:                            inviteTid.sendResponse(okResponse);
217:                            System.out
218:                                    .println("shootme: Dialog state after 200: "
219:                                            + inviteTid.getDialog().getState());
220:                        }
221:                    } catch (SipException ex) {
222:                        ex.printStackTrace();
223:                    } catch (InvalidArgumentException ex) {
224:                        ex.printStackTrace();
225:                    }
226:                }
227:
228:                /**
229:                 * Process the bye request.
230:                 */
231:                public void processBye(RequestEvent requestEvent,
232:                        ServerTransaction serverTransactionId) {
233:                    SipProvider sipProvider = (SipProvider) requestEvent
234:                            .getSource();
235:                    Request request = requestEvent.getRequest();
236:                    Dialog dialog = requestEvent.getDialog();
237:                    System.out.println("local party = "
238:                            + dialog.getLocalParty());
239:                    try {
240:                        System.out.println("shootme:  got a bye sending OK.");
241:                        Response response = messageFactory.createResponse(200,
242:                                request);
243:                        serverTransactionId.sendResponse(response);
244:                        System.out.println("Dialog State is "
245:                                + serverTransactionId.getDialog().getState());
246:
247:                    } catch (Exception ex) {
248:                        ex.printStackTrace();
249:                        System.exit(0);
250:
251:                    }
252:                }
253:
254:                public void processCancel(RequestEvent requestEvent,
255:                        ServerTransaction serverTransactionId) {
256:                    SipProvider sipProvider = (SipProvider) requestEvent
257:                            .getSource();
258:                    Request request = requestEvent.getRequest();
259:                    try {
260:                        System.out.println("shootme:  got a cancel.");
261:                        if (serverTransactionId == null) {
262:                            System.out.println("shootme:  null tid.");
263:                            return;
264:                        }
265:                        Response response = messageFactory.createResponse(200,
266:                                request);
267:                        serverTransactionId.sendResponse(response);
268:                        if (dialog.getState() != DialogState.CONFIRMED) {
269:                            response = messageFactory.createResponse(
270:                                    Response.REQUEST_TERMINATED, inviteRequest);
271:                            inviteTid.sendResponse(response);
272:                        }
273:
274:                    } catch (Exception ex) {
275:                        ex.printStackTrace();
276:                        System.exit(0);
277:
278:                    }
279:                }
280:
281:                public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
282:                    Transaction transaction;
283:                    if (timeoutEvent.isServerTransaction()) {
284:                        transaction = timeoutEvent.getServerTransaction();
285:                    } else {
286:                        transaction = timeoutEvent.getClientTransaction();
287:                    }
288:                    System.out.println("state = " + transaction.getState());
289:                    System.out.println("dialog = " + transaction.getDialog());
290:                    System.out.println("dialogState = "
291:                            + transaction.getDialog().getState());
292:                    System.out.println("Transaction Time out");
293:                }
294:
295:                public void init() {
296:                    SipFactory sipFactory = null;
297:                    sipStack = null;
298:                    sipFactory = SipFactory.getInstance();
299:                    sipFactory.setPathName("gov.nist");
300:                    Properties properties = new Properties();
301:                    properties.setProperty("javax.sip.STACK_NAME", "shootme");
302:                    // You need 16 for logging traces. 32 for debug + traces.
303:                    // Your code will limp at 32 but it is best for debugging.
304:                    properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL",
305:                            "32");
306:                    properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
307:                            "shootmedebug.txt");
308:                    properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
309:                            "shootmelog.txt");
310:
311:                    try {
312:                        // Create SipStack object
313:                        sipStack = sipFactory.createSipStack(properties);
314:                        System.out.println("sipStack = " + sipStack);
315:                    } catch (PeerUnavailableException e) {
316:                        // could not find
317:                        // gov.nist.jain.protocol.ip.sip.SipStackImpl
318:                        // in the classpath
319:                        e.printStackTrace();
320:                        System.err.println(e.getMessage());
321:                        if (e.getCause() != null)
322:                            e.getCause().printStackTrace();
323:                        System.exit(0);
324:                    }
325:
326:                    try {
327:                        headerFactory = sipFactory.createHeaderFactory();
328:                        addressFactory = sipFactory.createAddressFactory();
329:                        messageFactory = sipFactory.createMessageFactory();
330:                        ListeningPoint lp = sipStack.createListeningPoint(
331:                                "127.0.0.1", myPort, "udp");
332:
333:                        Shootme listener = this ;
334:
335:                        SipProvider sipProvider = sipStack
336:                                .createSipProvider(lp);
337:                        System.out.println("udp provider " + sipProvider);
338:                        sipProvider.addSipListener(listener);
339:
340:                    } catch (Exception ex) {
341:                        System.out.println(ex.getMessage());
342:                        ex.printStackTrace();
343:                        fail("Unexpected exception");
344:                    }
345:
346:                }
347:
348:                public void processIOException(IOExceptionEvent exceptionEvent) {
349:                    System.out.println("IOException");
350:
351:                }
352:
353:                public void processTransactionTerminated(
354:                        TransactionTerminatedEvent transactionTerminatedEvent) {
355:                    if (transactionTerminatedEvent.isServerTransaction())
356:                        System.out
357:                                .println("Transaction terminated event recieved"
358:                                        + transactionTerminatedEvent
359:                                                .getServerTransaction());
360:                    else
361:                        System.out.println("Transaction terminated "
362:                                + transactionTerminatedEvent
363:                                        .getClientTransaction());
364:
365:                }
366:
367:                public void processDialogTerminated(
368:                        DialogTerminatedEvent dialogTerminatedEvent) {
369:                    System.out.println("Dialog terminated event recieved");
370:                    Dialog d = dialogTerminatedEvent.getDialog();
371:                    System.out.println("Local Party = " + d.getLocalParty());
372:
373:                }
374:
375:                public void stop() {
376:                    this .sipStack.stop();
377:                }
378:
379:            }
380:
381:            class Shootist implements  SipListener {
382:
383:                private SipProvider sipProvider;
384:
385:                private SipStack sipStack;
386:
387:                private ContactHeader contactHeader;
388:
389:                private ListeningPoint udpListeningPoint;
390:
391:                private ClientTransaction inviteTid;
392:
393:                private Dialog dialog;
394:
395:                private boolean byeTaskRunning;
396:
397:                class ByeTask extends TimerTask {
398:                    Dialog dialog;
399:
400:                    public ByeTask(Dialog dialog) {
401:                        this .dialog = dialog;
402:                    }
403:
404:                    public void run() {
405:                        try {
406:                            Request byeRequest = this .dialog
407:                                    .createRequest(Request.BYE);
408:                            ClientTransaction ct = sipProvider
409:                                    .getNewClientTransaction(byeRequest);
410:                            dialog.sendRequest(ct);
411:                        } catch (Exception ex) {
412:                            ex.printStackTrace();
413:                            fail("Unexpected exception ");
414:                        }
415:
416:                    }
417:
418:                }
419:
420:                public void processRequest(RequestEvent requestReceivedEvent) {
421:                    Request request = requestReceivedEvent.getRequest();
422:                    ServerTransaction serverTransactionId = requestReceivedEvent
423:                            .getServerTransaction();
424:
425:                    System.out.println("\n\nRequest " + request.getMethod()
426:                            + " received at " + sipStack.getStackName()
427:                            + " with server transaction id "
428:                            + serverTransactionId);
429:
430:                    // We are the UAC so the only request we get is the BYE.
431:                    if (request.getMethod().equals(Request.BYE))
432:                        processBye(request, serverTransactionId);
433:                    else {
434:                        try {
435:                            serverTransactionId.sendResponse(messageFactory
436:                                    .createResponse(202, request));
437:                        } catch (Exception e) {
438:                            e.printStackTrace();
439:                            fail("Unxepcted exception ");
440:                        }
441:                    }
442:
443:                }
444:
445:                public void processBye(Request request,
446:                        ServerTransaction serverTransactionId) {
447:                    try {
448:                        System.out.println("shootist:  got a bye .");
449:                        if (serverTransactionId == null) {
450:                            System.out.println("shootist:  null TID.");
451:                            return;
452:                        }
453:                        Dialog dialog = serverTransactionId.getDialog();
454:                        System.out.println("Dialog State = "
455:                                + dialog.getState());
456:                        Response response = messageFactory.createResponse(200,
457:                                request);
458:                        serverTransactionId.sendResponse(response);
459:                        System.out.println("shootist:  Sending OK.");
460:                        System.out.println("Dialog State = "
461:                                + dialog.getState());
462:
463:                    } catch (Exception ex) {
464:                        fail("Unexpected exception");
465:
466:                    }
467:                }
468:
469:                // Save the created ACK request, to respond to retransmitted 2xx
470:                private Request ackRequest;
471:
472:                public void processResponse(ResponseEvent responseReceivedEvent) {
473:                    System.out.println("Got a response");
474:                    Response response = (Response) responseReceivedEvent
475:                            .getResponse();
476:                    ClientTransaction tid = responseReceivedEvent
477:                            .getClientTransaction();
478:                    CSeqHeader cseq = (CSeqHeader) response
479:                            .getHeader(CSeqHeader.NAME);
480:
481:                    System.out.println("Response received : Status Code = "
482:                            + response.getStatusCode() + " " + cseq);
483:
484:                    if (tid == null) {
485:
486:                        // RFC3261: MUST respond to every 2xx
487:                        if (ackRequest != null && dialog != null) {
488:                            System.out.println("re-sending ACK");
489:                            try {
490:                                dialog.sendAck(ackRequest);
491:                            } catch (SipException se) {
492:                                se.printStackTrace();
493:                                fail("Unxpected exception ");
494:                            }
495:                        }
496:                        return;
497:                    }
498:                    // If the caller is supposed to send the bye
499:                    if (Shootme.callerSendsBye && !byeTaskRunning) {
500:                        byeTaskRunning = true;
501:                        new Timer().schedule(new ByeTask(dialog), 4000);
502:                    }
503:                    System.out
504:                            .println("transaction state is " + tid.getState());
505:                    System.out.println("Dialog = " + tid.getDialog());
506:                    System.out.println("Dialog State is "
507:                            + tid.getDialog().getState());
508:
509:                    assertSame("Checking dialog identity", tid.getDialog(),
510:                            this .dialog);
511:
512:                    try {
513:                        if (response.getStatusCode() == Response.OK) {
514:                            if (cseq.getMethod().equals(Request.INVITE)) {
515:                                System.out.println("Dialog after 200 OK  "
516:                                        + dialog);
517:                                System.out
518:                                        .println("Dialog State after 200 OK  "
519:                                                + dialog.getState());
520:                                Request ackRequest = dialog.createAck(cseq
521:                                        .getSeqNumber());
522:                                System.out.println("Sending ACK");
523:                                dialog.sendAck(ackRequest);
524:
525:                                // JvB: test REFER, reported bug in tag handling
526:                                dialog.sendRequest(sipProvider
527:                                        .getNewClientTransaction(dialog
528:                                                .createRequest("REFER")));
529:
530:                            } else if (cseq.getMethod().equals(Request.CANCEL)) {
531:                                if (dialog.getState() == DialogState.CONFIRMED) {
532:                                    // oops cancel went in too late. Need to hang up the
533:                                    // dialog.
534:                                    System.out
535:                                            .println("Sending BYE -- cancel went in too late !!");
536:                                    Request byeRequest = dialog
537:                                            .createRequest(Request.BYE);
538:                                    ClientTransaction ct = sipProvider
539:                                            .getNewClientTransaction(byeRequest);
540:                                    dialog.sendRequest(ct);
541:
542:                                }
543:
544:                            }
545:                        }
546:                    } catch (Exception ex) {
547:                        ex.printStackTrace();
548:                        System.exit(0);
549:                    }
550:
551:                }
552:
553:                public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
554:
555:                    System.out.println("Transaction Time out");
556:                }
557:
558:                public void sendCancel() {
559:                    try {
560:                        System.out.println("Sending cancel");
561:                        Request cancelRequest = inviteTid.createCancel();
562:                        ClientTransaction cancelTid = sipProvider
563:                                .getNewClientTransaction(cancelRequest);
564:                        cancelTid.sendRequest();
565:                    } catch (Exception ex) {
566:                        ex.printStackTrace();
567:                    }
568:                }
569:
570:                public void init() {
571:                    SipFactory sipFactory = null;
572:                    sipStack = null;
573:                    sipFactory = SipFactory.getInstance();
574:                    sipFactory.setPathName("gov.nist");
575:                    Properties properties = new Properties();
576:                    // If you want to try TCP transport change the following to
577:                    String transport = "udp";
578:                    String peerHostPort = "127.0.0.1:5070";
579:                    properties.setProperty("javax.sip.OUTBOUND_PROXY",
580:                            peerHostPort + "/" + transport);
581:                    // If you want to use UDP then uncomment this.
582:                    properties.setProperty("javax.sip.STACK_NAME", "shootist");
583:
584:                    // The following properties are specific to nist-sip
585:                    // and are not necessarily part of any other jain-sip
586:                    // implementation.
587:                    // You can set a max message size for tcp transport to
588:                    // guard against denial of service attack.
589:                    properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
590:                            "shootistdebug.txt");
591:                    properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
592:                            "shootistlog.txt");
593:
594:                    // Drop the client connection after we are done with the transaction.
595:                    properties.setProperty(
596:                            "gov.nist.javax.sip.CACHE_CLIENT_CONNECTIONS",
597:                            "false");
598:                    // Set to 0 (or NONE) in your production code for max speed.
599:                    // You need 16 (or TRACE) for logging traces. 32 (or DEBUG) for debug + traces.
600:                    // Your code will limp at 32 but it is best for debugging.
601:                    properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL",
602:                            "DEBUG");
603:
604:                    try {
605:                        // Create SipStack object
606:                        sipStack = sipFactory.createSipStack(properties);
607:                        System.out.println("createSipStack " + sipStack);
608:                    } catch (PeerUnavailableException e) {
609:                        // could not find
610:                        // gov.nist.jain.protocol.ip.sip.SipStackImpl
611:                        // in the classpath
612:                        e.printStackTrace();
613:                        System.err.println(e.getMessage());
614:                        System.exit(0);
615:                    }
616:
617:                    try {
618:                        headerFactory = sipFactory.createHeaderFactory();
619:                        addressFactory = sipFactory.createAddressFactory();
620:                        messageFactory = sipFactory.createMessageFactory();
621:                        udpListeningPoint = sipStack.createListeningPoint(
622:                                "127.0.0.1", 5060, "udp");
623:                        sipProvider = sipStack
624:                                .createSipProvider(udpListeningPoint);
625:                        Shootist listener = this ;
626:                        sipProvider.addSipListener(listener);
627:
628:                        String fromName = "BigGuy";
629:                        String fromSipAddress = "here.com";
630:                        String fromDisplayName = "The Master Blaster";
631:
632:                        String toSipAddress = "there.com";
633:                        String toUser = "LittleGuy";
634:                        String toDisplayName = "The Little Blister";
635:
636:                        // create >From Header
637:                        SipURI fromAddress = addressFactory.createSipURI(
638:                                fromName, fromSipAddress);
639:
640:                        Address fromNameAddress = addressFactory
641:                                .createAddress(fromAddress);
642:                        fromNameAddress.setDisplayName(fromDisplayName);
643:                        FromHeader fromHeader = headerFactory.createFromHeader(
644:                                fromNameAddress, "12345");
645:
646:                        // create To Header
647:                        SipURI toAddress = addressFactory.createSipURI(toUser,
648:                                toSipAddress);
649:                        Address toNameAddress = addressFactory
650:                                .createAddress(toAddress);
651:                        toNameAddress.setDisplayName(toDisplayName);
652:                        ToHeader toHeader = headerFactory.createToHeader(
653:                                toNameAddress, null);
654:
655:                        // create Request URI
656:                        SipURI requestURI = addressFactory.createSipURI(toUser,
657:                                peerHostPort);
658:
659:                        // Create ViaHeaders
660:
661:                        ArrayList viaHeaders = new ArrayList();
662:                        String ipAddress = udpListeningPoint.getIPAddress();
663:                        ViaHeader viaHeader = headerFactory.createViaHeader(
664:                                ipAddress, sipProvider.getListeningPoint(
665:                                        transport).getPort(), transport, null);
666:
667:                        // add via headers
668:                        viaHeaders.add(viaHeader);
669:
670:                        // Create ContentTypeHeader
671:                        ContentTypeHeader contentTypeHeader = headerFactory
672:                                .createContentTypeHeader("application", "sdp");
673:
674:                        // Create a new CallId header
675:                        CallIdHeader callIdHeader = sipProvider.getNewCallId();
676:
677:                        // Create a new Cseq header
678:                        CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(
679:                                1L, Request.INVITE);
680:
681:                        // Create a new MaxForwardsHeader
682:                        MaxForwardsHeader maxForwards = headerFactory
683:                                .createMaxForwardsHeader(70);
684:
685:                        // Create the request.
686:                        Request request = messageFactory.createRequest(
687:                                requestURI, Request.INVITE, callIdHeader,
688:                                cSeqHeader, fromHeader, toHeader, viaHeaders,
689:                                maxForwards);
690:                        // Create contact headers
691:                        String host = "127.0.0.1";
692:
693:                        SipURI contactUrl = addressFactory.createSipURI(
694:                                fromName, host);
695:                        contactUrl.setPort(udpListeningPoint.getPort());
696:                        contactUrl.setLrParam();
697:
698:                        // Create the contact name address.
699:                        SipURI contactURI = addressFactory.createSipURI(
700:                                fromName, host);
701:                        contactURI.setPort(sipProvider.getListeningPoint(
702:                                transport).getPort());
703:
704:                        Address contactAddress = addressFactory
705:                                .createAddress(contactURI);
706:
707:                        // Add the contact address.
708:                        contactAddress.setDisplayName(fromName);
709:
710:                        contactHeader = headerFactory
711:                                .createContactHeader(contactAddress);
712:                        request.addHeader(contactHeader);
713:
714:                        // You can add extension headers of your own making
715:                        // to the outgoing SIP request.
716:                        // Add the extension header.
717:                        Header extensionHeader = headerFactory.createHeader(
718:                                "My-Header", "my header value");
719:                        request.addHeader(extensionHeader);
720:
721:                        String sdpData = "v=0\r\n"
722:                                + "o=4855 13760799956958020 13760799956958020"
723:                                + " IN IP4  129.6.55.78\r\n"
724:                                + "s=mysession session\r\n"
725:                                + "p=+46 8 52018010\r\n"
726:                                + "c=IN IP4  129.6.55.78\r\n" + "t=0 0\r\n"
727:                                + "m=audio 6022 RTP/AVP 0 4 18\r\n"
728:                                + "a=rtpmap:0 PCMU/8000\r\n"
729:                                + "a=rtpmap:4 G723/8000\r\n"
730:                                + "a=rtpmap:18 G729A/8000\r\n"
731:                                + "a=ptime:20\r\n";
732:                        byte[] contents = sdpData.getBytes();
733:
734:                        request.setContent(contents, contentTypeHeader);
735:                        // You can add as many extension headers as you
736:                        // want.
737:
738:                        extensionHeader = headerFactory.createHeader(
739:                                "My-Other-Header", "my new header value ");
740:                        request.addHeader(extensionHeader);
741:
742:                        Header callInfoHeader = headerFactory.createHeader(
743:                                "Call-Info", "<http://www.antd.nist.gov>");
744:                        request.addHeader(callInfoHeader);
745:
746:                        // Create the client transaction.
747:                        inviteTid = sipProvider
748:                                .getNewClientTransaction(request);
749:
750:                        // send the request out.
751:                        inviteTid.sendRequest();
752:
753:                        dialog = inviteTid.getDialog();
754:
755:                    } catch (Exception ex) {
756:                        System.out.println(ex.getMessage());
757:                        ex.printStackTrace();
758:                        fail("Unxpected exception ");
759:                    }
760:                }
761:
762:                public void processIOException(IOExceptionEvent exceptionEvent) {
763:                    System.out.println("IOException happened for "
764:                            + exceptionEvent.getHost() + " port = "
765:                            + exceptionEvent.getPort());
766:
767:                }
768:
769:                public void processTransactionTerminated(
770:                        TransactionTerminatedEvent transactionTerminatedEvent) {
771:                    System.out.println("Transaction terminated event recieved");
772:                }
773:
774:                public void processDialogTerminated(
775:                        DialogTerminatedEvent dialogTerminatedEvent) {
776:                    System.out.println("dialogTerminatedEvent");
777:
778:                }
779:
780:                public void stop() {
781:                    this .sipStack.stop();
782:                }
783:            }
784:
785:            public void testDialogIdentity() throws Exception {
786:
787:                Shootist shootist = new Shootist();
788:
789:                Shootme shootme = new Shootme();
790:                shootme.init();
791:
792:                shootist.init();
793:
794:                Thread.sleep(10000);
795:
796:                shootist.stop();
797:                shootme.stop();
798:
799:            }
800:        }
w_w_w_._j__a___va2___s___.___co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.