Source Code Cross Referenced for Shootist.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.AllowList;
004:        import gov.nist.javax.sip.header.HeaderFactoryImpl;
005:        import gov.nist.javax.sip.header.RequireList;
006:        import gov.nist.javax.sip.header.SupportedList;
007:        import gov.nist.javax.sip.header.ims.*;
008:
009:        import javax.sip.*;
010:        import javax.sip.address.*;
011:        import javax.sip.header.*;
012:        import javax.sip.message.*;
013:
014:        import java.util.*;
015:
016:        /**
017:         * <p>This class is a UAC template.</p>
018:         * <p>Exemplifies the creation and parsing of the SIP P-Headers for IMS</p>
019:         * 
020:         * <p>based on examples.simplecallsetup, by M. Ranganathan</p>
021:         * <p>issued by Miguel Freitas (IT) PT-Inovacao</p>
022:         */
023:
024:        public class Shootist implements  SipListener {
025:
026:            private static SipProvider sipProvider;
027:
028:            private static AddressFactory addressFactory;
029:
030:            private static MessageFactory messageFactory;
031:
032:            private static HeaderFactory headerFactory;
033:
034:            private static SipStack sipStack;
035:
036:            private ContactHeader contactHeader;
037:
038:            private ListeningPoint udpListeningPoint;
039:
040:            private ClientTransaction inviteTid;
041:
042:            private Dialog dialog;
043:
044:            private boolean byeTaskRunning;
045:
046:            class ByeTask extends TimerTask {
047:                Dialog dialog;
048:
049:                public ByeTask(Dialog dialog) {
050:                    this .dialog = dialog;
051:                }
052:
053:                public void run() {
054:                    try {
055:                        Request byeRequest = this .dialog
056:                                .createRequest(Request.BYE);
057:                        ClientTransaction ct = sipProvider
058:                                .getNewClientTransaction(byeRequest);
059:                        dialog.sendRequest(ct);
060:                    } catch (Exception ex) {
061:                        ex.printStackTrace();
062:                        System.exit(0);
063:                    }
064:
065:                }
066:
067:            }
068:
069:            private static final String usageString = "java "
070:                    + "examples.shootist.Shootist \n"
071:                    + ">>>> is your class path set to the root?";
072:
073:            private static void usage() {
074:                System.out.println(usageString);
075:                System.exit(0);
076:
077:            }
078:
079:            public void processRequest(RequestEvent requestReceivedEvent) {
080:                Request request = requestReceivedEvent.getRequest();
081:                ServerTransaction serverTransactionId = requestReceivedEvent
082:                        .getServerTransaction();
083:
084:                System.out.println("\n\nRequest " + request.getMethod()
085:                        + " received at " + sipStack.getStackName()
086:                        + " with server transaction id " + serverTransactionId);
087:
088:                // We are the UAC so the only request we get is the BYE.
089:                if (request.getMethod().equals(Request.BYE))
090:                    processBye(request, serverTransactionId);
091:
092:            }
093:
094:            public void processBye(Request request,
095:                    ServerTransaction serverTransactionId) {
096:                try {
097:                    System.out.println("shootist:  got a bye .");
098:                    if (serverTransactionId == null) {
099:                        System.out.println("shootist:  null TID.");
100:                        return;
101:                    }
102:                    Dialog dialog = serverTransactionId.getDialog();
103:                    System.out.println("Dialog State = " + dialog.getState());
104:                    Response response = messageFactory.createResponse(200,
105:                            request);
106:                    serverTransactionId.sendResponse(response);
107:                    System.out.println("shootist:  Sending OK.");
108:                    System.out.println("Dialog State = " + dialog.getState());
109:
110:                } catch (Exception ex) {
111:                    ex.printStackTrace();
112:                    System.exit(0);
113:
114:                }
115:            }
116:
117:            public void processInviteOK(Response ok, ClientTransaction ct) {
118:
119:                HeaderFactoryImpl headerFactoryImpl = (HeaderFactoryImpl) headerFactory;
120:
121:                try {
122:
123:                    RequireHeader require = null;
124:                    String requireOptionTags = new String();
125:                    ListIterator li = ok.getHeaders(RequireHeader.NAME);
126:                    if (li != null) {
127:                        try {
128:                            while (li.hasNext()) {
129:                                require = (RequireHeader) li.next();
130:                                requireOptionTags = requireOptionTags.concat(
131:                                        require.getOptionTag()).concat(" ");
132:                            }
133:                        } catch (Exception ex) {
134:                            System.out
135:                                    .println("\n(!) Exception getting Require header! - "
136:                                            + ex);
137:                        }
138:                    }
139:
140:                    // this is only to illustrate the usage of this headers
141:                    // send Security-Verify (based on Security-Server) if Require: sec-agree
142:                    SecurityVerifyList secVerifyList = null;
143:                    if (requireOptionTags.indexOf("sec-agree") != -1) {
144:                        ListIterator secServerReceived = ok
145:                                .getHeaders(SecurityServerHeader.NAME);
146:                        if (secServerReceived != null
147:                                && secServerReceived.hasNext()) {
148:                            System.out.println(".: Security-Server received: ");
149:
150:                            while (secServerReceived.hasNext()) {
151:                                SecurityServerHeader security = null;
152:                                try {
153:                                    security = (SecurityServerHeader) secServerReceived
154:                                            .next();
155:                                } catch (Exception ex) {
156:                                    System.out
157:                                            .println("(!) Exception getting Security-Server header : "
158:                                                    + ex);
159:                                }
160:
161:                                try {
162:                                    Iterator parameters = security
163:                                            .getParameterNames();
164:                                    SecurityVerifyHeader newSecVerify = headerFactoryImpl
165:                                            .createSecurityVerifyHeader();
166:                                    newSecVerify.setSecurityMechanism(security
167:                                            .getSecurityMechanism());
168:                                    while (parameters.hasNext()) {
169:                                        String paramName = (String) parameters
170:                                                .next();
171:                                        newSecVerify
172:                                                .setParameter(
173:                                                        paramName,
174:                                                        security
175:                                                                .getParameter(paramName));
176:                                    }
177:
178:                                    System.out.println("   - "
179:                                            + security.toString());
180:
181:                                } catch (Exception ex) {
182:                                    System.out
183:                                            .println("(!) Exception setting the security agreement!"
184:                                                    + ex);
185:                                    ex.getStackTrace();
186:                                }
187:
188:                            }
189:                        }
190:                        System.out
191:                                .println(".: Security-Verify built and added to response...");
192:                    }
193:
194:                    ackRequest = dialog.createRequest(Request.ACK);
195:
196:                    if (secVerifyList != null && !secVerifyList.isEmpty()) {
197:                        RequireHeader requireSecAgree = headerFactory
198:                                .createRequireHeader("sec-agree");
199:                        ackRequest.setHeader(requireSecAgree);
200:
201:                        ackRequest.setHeader(secVerifyList);
202:                    }
203:
204:                    System.out.println("Sending ACK");
205:                    dialog.sendAck(ackRequest);
206:
207:                } catch (Exception ex) {
208:                    System.out.println("(!) Exception sending ACK to 200 OK "
209:                            + "response to INVITE : " + ex);
210:                }
211:            }
212:
213:            // Save the created ACK request, to respond to retransmitted 2xx
214:            private Request ackRequest;
215:
216:            public void processResponse(ResponseEvent responseReceivedEvent) {
217:                System.out.println("Got a response");
218:                Response response = (Response) responseReceivedEvent
219:                        .getResponse();
220:                ClientTransaction tid = responseReceivedEvent
221:                        .getClientTransaction();
222:                CSeqHeader cseq = (CSeqHeader) response
223:                        .getHeader(CSeqHeader.NAME);
224:
225:                System.out.println("Response received : Status Code = "
226:                        + response.getStatusCode() + " " + cseq);
227:
228:                if (tid == null) {
229:
230:                    // RFC3261: MUST respond to every 2xx
231:                    if (ackRequest != null && dialog != null) {
232:                        System.out.println("re-sending ACK");
233:                        try {
234:                            dialog.sendAck(ackRequest);
235:                        } catch (SipException se) {
236:                            se.printStackTrace();
237:                        }
238:                    }
239:                    return;
240:                }
241:                // If the caller is supposed to send the bye
242:                if (Shootme.callerSendsBye && !byeTaskRunning) {
243:                    byeTaskRunning = true;
244:                    new Timer().schedule(new ByeTask(dialog), 2000);
245:                }
246:                System.out.println("transaction state is " + tid.getState());
247:                System.out.println("Dialog = " + tid.getDialog());
248:                System.out.println("Dialog State is "
249:                        + tid.getDialog().getState());
250:
251:                try {
252:                    if (response.getStatusCode() == Response.OK) {
253:                        if (cseq.getMethod().equals(Request.INVITE)) {
254:                            processInviteOK(response, tid);
255:
256:                            /*
257:                            ackRequest = dialog.createRequest(Request.ACK);
258:                            System.out.println("Sending ACK");
259:                            dialog.sendAck(ackRequest);
260:                             */
261:
262:                        } else if (cseq.getMethod().equals(Request.CANCEL)) {
263:                            if (dialog.getState() == DialogState.CONFIRMED) {
264:                                // oops cancel went in too late. Need to hang up the
265:                                // dialog.
266:                                System.out
267:                                        .println("Sending BYE -- cancel went in too late !!");
268:                                Request byeRequest = dialog
269:                                        .createRequest(Request.BYE);
270:                                ClientTransaction ct = sipProvider
271:                                        .getNewClientTransaction(byeRequest);
272:                                dialog.sendRequest(ct);
273:
274:                            }
275:
276:                        }
277:                    }
278:                } catch (Exception ex) {
279:                    ex.printStackTrace();
280:                    System.exit(0);
281:                }
282:
283:            }
284:
285:            public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
286:
287:                System.out.println("Transaction Time out");
288:            }
289:
290:            public void sendCancel() {
291:                try {
292:                    System.out.println("Sending cancel");
293:                    Request cancelRequest = inviteTid.createCancel();
294:                    ClientTransaction cancelTid = sipProvider
295:                            .getNewClientTransaction(cancelRequest);
296:                    cancelTid.sendRequest();
297:                } catch (Exception ex) {
298:                    ex.printStackTrace();
299:                }
300:            }
301:
302:            public void init() {
303:                SipFactory sipFactory = null;
304:                sipStack = null;
305:                sipFactory = SipFactory.getInstance();
306:                sipFactory.setPathName("gov.nist");
307:                Properties properties = new Properties();
308:                // If you want to try TCP transport change the following to
309:                String transport = "udp";
310:                String peerHostPort = "127.0.0.1:5070";
311:                properties.setProperty("javax.sip.OUTBOUND_PROXY", peerHostPort
312:                        + "/" + transport);
313:                // If you want to use UDP then uncomment this.
314:                properties.setProperty("javax.sip.STACK_NAME", "shootist");
315:
316:                // The following properties are specific to nist-sip
317:                // and are not necessarily part of any other jain-sip
318:                // implementation.
319:                // You can set a max message size for tcp transport to
320:                // guard against denial of service attack.
321:                properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
322:                        "shootistdebug.txt");
323:                properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
324:                        "shootistlog.txt");
325:
326:                // Drop the client connection after we are done with the transaction.
327:                properties.setProperty(
328:                        "gov.nist.javax.sip.CACHE_CLIENT_CONNECTIONS", "false");
329:                // Set to 0 (or NONE) in your production code for max speed.
330:                // You need 16 (or TRACE) for logging traces. 32 (or DEBUG) for debug + traces.
331:                // Your code will limp at 32 but it is best for debugging.
332:                properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL",
333:                        "TRACE");
334:
335:                try {
336:                    // Create SipStack object
337:                    sipStack = sipFactory.createSipStack(properties);
338:                    System.out.println("createSipStack " + sipStack);
339:                } catch (PeerUnavailableException e) {
340:                    // could not find
341:                    // gov.nist.jain.protocol.ip.sip.SipStackImpl
342:                    // in the classpath
343:                    e.printStackTrace();
344:                    System.err.println(e.getMessage());
345:                    System.exit(0);
346:                }
347:
348:                try {
349:                    headerFactory = sipFactory.createHeaderFactory();
350:                    addressFactory = sipFactory.createAddressFactory();
351:                    messageFactory = sipFactory.createMessageFactory();
352:                    udpListeningPoint = sipStack.createListeningPoint(
353:                            "127.0.0.1", 5060, "udp");
354:                    sipProvider = sipStack.createSipProvider(udpListeningPoint);
355:                    Shootist listener = this ;
356:                    sipProvider.addSipListener(listener);
357:
358:                    String fromName = "BigGuy";
359:                    String fromSipAddress = "here.com";
360:                    String fromDisplayName = "The Master Blaster";
361:
362:                    String toSipAddress = "there.com";
363:                    String toUser = "LittleGuy";
364:                    String toDisplayName = "The Little Blister";
365:
366:                    // create >From Header
367:                    SipURI fromAddress = addressFactory.createSipURI(fromName,
368:                            fromSipAddress);
369:
370:                    Address fromNameAddress = addressFactory
371:                            .createAddress(fromAddress);
372:                    fromNameAddress.setDisplayName(fromDisplayName);
373:                    FromHeader fromHeader = headerFactory.createFromHeader(
374:                            fromNameAddress, "12345");
375:
376:                    // create To Header
377:                    SipURI toAddress = addressFactory.createSipURI(toUser,
378:                            toSipAddress);
379:                    Address toNameAddress = addressFactory
380:                            .createAddress(toAddress);
381:                    toNameAddress.setDisplayName(toDisplayName);
382:                    ToHeader toHeader = headerFactory.createToHeader(
383:                            toNameAddress, null);
384:
385:                    // create Request URI
386:                    SipURI requestURI = addressFactory.createSipURI(toUser,
387:                            peerHostPort);
388:
389:                    // Create ViaHeaders
390:
391:                    ArrayList viaHeaders = new ArrayList();
392:                    ViaHeader viaHeader = headerFactory.createViaHeader(
393:                            "127.0.0.1", sipProvider.getListeningPoint(
394:                                    transport).getPort(), transport, null);
395:
396:                    // add via headers
397:                    viaHeaders.add(viaHeader);
398:
399:                    // Create ContentTypeHeader
400:                    ContentTypeHeader contentTypeHeader = headerFactory
401:                            .createContentTypeHeader("application", "sdp");
402:
403:                    // Create a new CallId header
404:                    CallIdHeader callIdHeader = sipProvider.getNewCallId();
405:
406:                    // Create a new Cseq header
407:                    CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L,
408:                            Request.INVITE);
409:
410:                    // Create a new MaxForwardsHeader
411:                    MaxForwardsHeader maxForwards = headerFactory
412:                            .createMaxForwardsHeader(70);
413:
414:                    // Create the request.
415:                    Request request = messageFactory.createRequest(requestURI,
416:                            Request.INVITE, callIdHeader, cSeqHeader,
417:                            fromHeader, toHeader, viaHeaders, maxForwards);
418:                    // Create contact headers
419:                    String host = "127.0.0.1";
420:
421:                    SipURI contactUrl = addressFactory.createSipURI(fromName,
422:                            host);
423:                    contactUrl.setPort(udpListeningPoint.getPort());
424:                    contactUrl.setLrParam();
425:
426:                    // Create the contact name address.
427:                    SipURI contactURI = addressFactory.createSipURI(fromName,
428:                            host);
429:                    contactURI.setPort(sipProvider.getListeningPoint(transport)
430:                            .getPort());
431:
432:                    Address contactAddress = addressFactory
433:                            .createAddress(contactURI);
434:
435:                    // Add the contact address.
436:                    contactAddress.setDisplayName(fromName);
437:
438:                    contactHeader = headerFactory
439:                            .createContactHeader(contactAddress);
440:                    request.addHeader(contactHeader);
441:
442:                    // You can add extension headers of your own making
443:                    // to the outgoing SIP request.
444:                    // Add the extension header.
445:                    Header extensionHeader = headerFactory.createHeader(
446:                            "My-Header", "my header value");
447:                    request.addHeader(extensionHeader);
448:
449:                    /* ++++++++++++++++++++++++++++++++++++++++++++
450:                     *                IMS headers
451:                     * ++++++++++++++++++++++++++++++++++++++++++++  
452:                     */
453:
454:                    // work-around for IMS headers
455:                    HeaderFactoryImpl headerFactoryImpl = new HeaderFactoryImpl();
456:
457:                    // Allow header
458:                    /*
459:                    AllowHeader allowHeader = 
460:                    	headerFactory.createAllowHeader(Request.INVITE + "," +  
461:                    			Request.PRACK + "," + 
462:                    			Request.UPDATE);
463:                    request.addHeader(allowHeader);
464:                     */
465:                    AllowHeader allow1 = headerFactory
466:                            .createAllowHeader(Request.INVITE);
467:                    request.addHeader(allow1);
468:                    AllowHeader allow2 = headerFactory
469:                            .createAllowHeader(Request.PRACK);
470:                    request.addHeader(allow2);
471:                    AllowHeader allow3 = headerFactory
472:                            .createAllowHeader(Request.UPDATE);
473:                    request.addHeader(allow3);
474:
475:                    // Supported
476:                    /*
477:                    SupportedHeader supportedHeader =
478:                    	headerFactory.createSupportedHeader("100rel" + "," +
479:                    			"precondition");
480:                    request.addHeader(supportedHeader);
481:                     */
482:                    SupportedHeader supported1 = headerFactory
483:                            .createSupportedHeader("100rel");
484:                    request.addHeader(supported1);
485:                    SupportedHeader supported2 = headerFactory
486:                            .createSupportedHeader("preconditions");
487:                    request.addHeader(supported2);
488:                    SupportedHeader supported3 = headerFactory
489:                            .createSupportedHeader("path");
490:                    request.addHeader(supported3);
491:
492:                    // Require
493:                    /*
494:                    RequireHeader requireHeader =
495:                    	headerFactory.createRequireHeader("sec-agree"+ "," +
496:                    	"precondition");
497:                    request.addHeader(requireHeader);
498:                     */
499:                    RequireHeader require1 = headerFactory
500:                            .createRequireHeader("sec-agree");
501:                    request.addHeader(require1);
502:                    RequireHeader require2 = headerFactory
503:                            .createRequireHeader("preconditions");
504:                    request.addHeader(require2);
505:
506:                    // Security-Client
507:                    SecurityClientHeader secClient = headerFactoryImpl
508:                            .createSecurityClientHeader();
509:                    secClient.setSecurityMechanism("ipsec-3gpp");
510:                    secClient.setAlgorithm("hmac-md5-96");
511:                    secClient.setEncryptionAlgorithm("des-cbc");
512:                    secClient.setSPIClient(10000);
513:                    secClient.setSPIServer(10001);
514:                    secClient.setPortClient(5063);
515:                    secClient.setPortServer(4166);
516:                    request.addHeader(secClient);
517:
518:                    // P-Access-Network-Info
519:                    PAccessNetworkInfoHeader accessInfo = headerFactoryImpl
520:                            .createPAccessNetworkInfoHeader();
521:                    accessInfo.setAccessType("3GPP-UTRAN-TDD");
522:                    accessInfo.setUtranCellID3GPP("0123456789ABCDEF");
523:                    request.addHeader(accessInfo);
524:
525:                    // Privacy
526:                    PrivacyHeader privacy = headerFactoryImpl
527:                            .createPrivacyHeader("header");
528:                    request.addHeader(privacy);
529:                    PrivacyHeader privacy2 = headerFactoryImpl
530:                            .createPrivacyHeader("user");
531:                    request.addHeader(privacy2);
532:
533:                    // P-Preferred-Identity
534:                    PPreferredIdentityHeader preferredID = headerFactoryImpl
535:                            .createPPreferredIdentityHeader(fromNameAddress);
536:                    request.addHeader(preferredID);
537:
538:                    /*
539:                     * TEST
540:                     */
541:                    // this is only to illustrate the usage of this headers
542:
543:                    // P-Called-Party-ID
544:                    // only to test
545:                    PCalledPartyIDHeader calledPartyID = headerFactoryImpl
546:                            .createPCalledPartyIDHeader(toNameAddress);
547:                    request.addHeader(calledPartyID);
548:
549:                    // P-Visited-Network-ID
550:                    PVisitedNetworkIDHeader visitedNetworkID1 = headerFactoryImpl
551:                            .createPVisitedNetworkIDHeader();
552:                    visitedNetworkID1.setVisitedNetworkID(fromSipAddress
553:                            .substring(fromSipAddress.indexOf("@") + 1));
554:                    PVisitedNetworkIDHeader visitedNetworkID2 = headerFactoryImpl
555:                            .createPVisitedNetworkIDHeader();
556:                    visitedNetworkID2.setVisitedNetworkID(toSipAddress
557:                            .substring(toSipAddress.indexOf("@") + 1));
558:                    request.addHeader(visitedNetworkID1);
559:                    request.addHeader(visitedNetworkID2);
560:
561:                    // P-Associated-URI
562:                    PAssociatedURIHeader associatedURI1 = headerFactoryImpl
563:                            .createPAssociatedURIHeader(toNameAddress);
564:                    PAssociatedURIHeader associatedURI2 = headerFactoryImpl
565:                            .createPAssociatedURIHeader(fromNameAddress);
566:                    request.addHeader(associatedURI1);
567:                    request.addHeader(associatedURI2);
568:
569:                    // P-Asserted-Identity
570:                    PAssertedIdentityHeader assertedID = headerFactoryImpl
571:                            .createPAssertedIdentityHeader(addressFactory
572:                                    .createAddress(toAddress));
573:                    request.addHeader(assertedID);
574:
575:                    TelURL tel = addressFactory.createTelURL("+1-201-555-0123");
576:                    Address telAddress = addressFactory.createAddress(tel);
577:                    toNameAddress.setDisplayName(toDisplayName);
578:                    PAssertedIdentityHeader assertedID2 = headerFactoryImpl
579:                            .createPAssertedIdentityHeader(telAddress);
580:                    request.addHeader(assertedID2);
581:
582:                    // P-Charging-Function-Addresses
583:                    PChargingFunctionAddressesHeader chargAddr = headerFactoryImpl
584:                            .createPChargingFunctionAddressesHeader();
585:                    chargAddr
586:                            .addChargingCollectionFunctionAddress("test1.ims.test");
587:                    chargAddr.addEventChargingFunctionAddress("testevent");
588:                    request.addHeader(chargAddr);
589:
590:                    // P-Charging-Vector
591:                    PChargingVectorHeader chargVect = headerFactoryImpl
592:                            .createChargingVectorHeader("icid");
593:                    chargVect.setICIDGeneratedAt("icidhost");
594:                    chargVect.setOriginatingIOI("origIOI");
595:                    chargVect.setTerminatingIOI("termIOI");
596:                    request.addHeader(chargVect);
597:
598:                    // P-Media-Authorization
599:                    PMediaAuthorizationHeader mediaAuth1 = headerFactoryImpl
600:                            .createPMediaAuthorizationHeader("13579bdf");
601:                    PMediaAuthorizationHeader mediaAuth2 = headerFactoryImpl
602:                            .createPMediaAuthorizationHeader("02468ace");
603:                    request.addHeader(mediaAuth1);
604:                    request.addHeader(mediaAuth2);
605:
606:                    // Path header
607:                    PathHeader path1 = headerFactoryImpl
608:                            .createPathHeader(fromNameAddress);
609:                    PathHeader path2 = headerFactoryImpl
610:                            .createPathHeader(toNameAddress);
611:                    request.addHeader(path1);
612:                    request.addHeader(path2);
613:
614:                    /*
615:                     * test clone() and equal()
616:                     */
617:                    /*
618:                    SecurityClientHeader secClientClone =
619:                    	(SecurityClientHeader) secClient.clone();
620:                    System.out.println(" --> Security-Client clone = " 
621:                    		+ secClientClone.toString());
622:                    System.out.println("    equals? " 
623:                    		+ secClientClone.equals(secClient));
624:
625:                    PAccessNetworkInfo paniClone =
626:                    	(PAccessNetworkInfo) accessInfo.clone();
627:                    System.out.println(" --> P-Access-Network-Info clone = " 
628:                    		+ paniClone.toString());
629:                    System.out.println("    equals? " 
630:                    		+ paniClone.equals(accessInfo));
631:                    
632:                    Privacy privacyClone =
633:                    	(Privacy) privacy.clone();
634:                    System.out.println(" --> Privacy clone = " 
635:                    		+ privacyClone.toString());
636:                    System.out.println("    equals? " 
637:                    		+ privacyClone.equals(privacy));
638:                    
639:                    PPreferredIdentity preferredIDClone =
640:                    	(PPreferredIdentity) preferredID.clone();
641:                    System.out.println(" --> P-Preferred-Identity clone = " 
642:                    		+ preferredIDClone.toString());
643:                    System.out.println("    equals? " 
644:                    		+ preferredIDClone.equals(preferredID));
645:                    
646:                    PCalledPartyID calledPartyIDClone =
647:                    	(PCalledPartyID) calledPartyID.clone();
648:                    System.out.println(" --> P-Called-Party-ID clone = " 
649:                    		+ calledPartyIDClone.toString());
650:                    System.out.println("    equals? " 
651:                    		+ calledPartyIDClone.equals(calledPartyID));
652:                    
653:                    PVisitedNetworkIDList visNetListClone =
654:                    	(PVisitedNetworkIDList) visNetList.clone();
655:                    System.out.println(" --> P-Visited-Network-ID list clone = " 
656:                    		+ visNetListClone.toString());
657:                    System.out.println("    equals? " 
658:                    		+ visNetListClone.equals(visNetList));
659:                    System.out.println("    equals? " 
660:                    		+ visNetListClone.equals(visitedNetworkID1));
661:                    
662:                    PAssociatedURIList associatedListClone =
663:                    	(PAssociatedURIList) associatedList.clone();
664:                    System.out.println(" --> P-Associated-URI list clone = " 
665:                    		+ associatedListClone.toString());
666:                    System.out.println("    equals? " 
667:                    		+ associatedListClone.equals(associatedList));
668:                    
669:                    PAssertedIdentity assertedIDClone =
670:                    	(PAssertedIdentity) assertedID.clone();
671:                    System.out.println(" --> P-Asserted-Identity clone = " 
672:                    		+ assertedIDClone.toString());
673:                    System.out.println("    equals? " 
674:                    		+ assertedIDClone.equals(assertedID));
675:                    
676:                    PChargingFunctionAddresses chargAddrClone =
677:                    	(PChargingFunctionAddresses) chargAddr.clone();
678:                    System.out.println(" --> P-Charging-Function-Addresses clone = " 
679:                    		+ chargAddrClone.toString());
680:                    System.out.println("    equals? " 
681:                    		+ chargAddrClone.equals(chargAddr));
682:                    
683:                    PChargingVector chargVectClone =
684:                    	(PChargingVector) chargVect.clone();
685:                    System.out.println(" --> P-Charging-Vector clone = " 
686:                    		+ chargVectClone.toString());
687:                    System.out.println("    equals? " 
688:                    		+ chargVectClone.equals(chargVect));
689:                    
690:                    PMediaAuthorizationList mediaAuthListClone =
691:                    	(PMediaAuthorizationList) mediaAuthList.clone();
692:                    System.out.println(" --> P-Media-Authorization list clone = " 
693:                    		+ mediaAuthListClone.toString());
694:                    System.out.println("    equals? " 
695:                    		+ mediaAuthListClone.equals(mediaAuthList));
696:                    
697:                    PathList pathListClone =
698:                    	(PathList) pathList.clone();
699:                    System.out.println(" --> Path list clone = " 
700:                    		+ pathListClone.toString());
701:                    System.out.println("    equals? " 
702:                    		+ pathListClone.equals(pathList));
703:                    System.out.println("    pathClone -> path1 equals? " 
704:                    		+ pathListClone.equals(path1));
705:                    System.out.println("    path1 -> path2 equals? " 
706:                    		+ path1.equals(path2));
707:                    
708:                     */
709:
710:                    //////////////////////////////////////////////////
711:
712:                    String sdpData = "v=0\r\n"
713:                            + "o=4855 13760799956958020 13760799956958020"
714:                            + " IN IP4  129.6.55.78\r\n"
715:                            + "s=mysession session\r\n"
716:                            + "p=+46 8 52018010\r\n"
717:                            + "c=IN IP4  129.6.55.78\r\n"
718:                            + "t=0 0\r\n"
719:                            + "m=audio 6022 RTP/AVP 0 4 18\r\n"
720:
721:                            // bandwith
722:                            + "b=AS:25.4\r\n"
723:                            // precondition mechanism
724:                            + "a=curr:qos local none\r\n"
725:                            + "a=curr:qos remote none\r\n"
726:                            + "a=des:qos mandatory local sendrec\r\n"
727:                            + "a=des:qos none remote sendrec\r\n"
728:
729:                            + "a=rtpmap:0 PCMU/8000\r\n"
730:                            + "a=rtpmap:4 G723/8000\r\n"
731:                            + "a=rtpmap:18 G729A/8000\r\n" + "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.getNewClientTransaction(request);
748:
749:                    // send the request out.
750:                    inviteTid.sendRequest();
751:
752:                    dialog = inviteTid.getDialog();
753:
754:                } catch (Exception ex) {
755:                    System.out.println(ex.getMessage());
756:                    ex.printStackTrace();
757:                    usage();
758:                }
759:            }
760:
761:            public static void main(String args[]) {
762:                new Shootist().init();
763:
764:            }
765:
766:            public void processIOException(IOExceptionEvent exceptionEvent) {
767:                System.out.println("IOException happened for "
768:                        + exceptionEvent.getHost() + " port = "
769:                        + exceptionEvent.getPort());
770:
771:            }
772:
773:            public void processTransactionTerminated(
774:                    TransactionTerminatedEvent transactionTerminatedEvent) {
775:                System.out.println("Transaction terminated event recieved");
776:            }
777:
778:            public void processDialogTerminated(
779:                    DialogTerminatedEvent dialogTerminatedEvent) {
780:                System.out.println("dialogTerminatedEvent");
781:
782:            }
783:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.