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


001:        package examples.publish;
002:
003:        import javax.sip.*;
004:        import javax.sip.address.*;
005:        import javax.sip.header.*;
006:        import javax.sip.message.*;
007:        import java.util.*;
008:
009:        //ifdef SIMULATION
010:        /*
011:         import sim.java.*;
012:         //endif
013:         */
014:
015:        /**
016:         * This class is a UAC template. Shootist is the guy that shoots and shootme 
017:         * is the guy that gets shot.
018:         *
019:         *@author M. Ranganathan
020:         */
021:
022:        public class Subscriber implements  SipListener {
023:
024:            private static SipProvider sipProvider;
025:            private static AddressFactory addressFactory;
026:            private static MessageFactory messageFactory;
027:            private static HeaderFactory headerFactory;
028:            private static SipStack sipStack;
029:            private ContactHeader contactHeader;
030:
031:            protected ClientTransaction subscribeTid;
032:
033:            protected static final String usageString = "java "
034:                    + "examples.subsnotify.Subscriber \n"
035:                    + ">>>> is your class path set to the root?";
036:
037:            private static void usage() {
038:                System.out.println(usageString);
039:                System.exit(0);
040:
041:            }
042:
043:            public void processRequest(RequestEvent requestReceivedEvent) {
044:                Request request = requestReceivedEvent.getRequest();
045:                ServerTransaction serverTransactionId = requestReceivedEvent
046:                        .getServerTransaction();
047:
048:                System.out.println("\n\nRequest " + request.getMethod()
049:                        + " received at " + sipStack.getStackName()
050:                        + " with server transaction id " + serverTransactionId);
051:
052:                if (request.getMethod().equals(Request.NOTIFY))
053:                    processNotify(request, serverTransactionId);
054:
055:            }
056:
057:            public void processNotify(Request request,
058:                    ServerTransaction serverTransactionId) {
059:                try {
060:                    System.out.println("subscriber:  got a notify .");
061:                    if (serverTransactionId == null) {
062:                        System.out.println("subscriber:  null TID.");
063:                        return;
064:                    }
065:                    Dialog dialog = serverTransactionId.getDialog();
066:                    System.out.println("Dialog State = " + dialog.getState());
067:                    Response response = messageFactory.createResponse(200,
068:                            request);
069:                    serverTransactionId.sendResponse(response);
070:                    SubscriptionStateHeader subscriptionState = (SubscriptionStateHeader) request
071:                            .getHeader(SubscriptionStateHeader.NAME);
072:                    // Subscription is terminated.
073:                    if (subscriptionState.getState().equals(
074:                            SubscriptionStateHeader.TERMINATED)) {
075:                        dialog.delete();
076:                    }
077:
078:                } catch (Exception ex) {
079:                    ex.printStackTrace();
080:                    System.exit(0);
081:
082:                }
083:            }
084:
085:            public void processResponse(ResponseEvent responseReceivedEvent) {
086:                System.out.println("Got a response");
087:                Response response = (Response) responseReceivedEvent
088:                        .getResponse();
089:                Transaction tid = responseReceivedEvent.getClientTransaction();
090:
091:                System.out
092:                        .println("Response received with client transaction id "
093:                                + tid + ":\n" + response);
094:                if (tid == null) {
095:                    System.out.println("Stray response -- dropping ");
096:                    return;
097:                }
098:                System.out.println("transaction state is " + tid.getState());
099:                System.out.println("Dialog = " + tid.getDialog());
100:                System.out.println("Dialog State is "
101:                        + tid.getDialog().getState());
102:
103:            }
104:
105:            public void init() {
106:                SipFactory sipFactory = null;
107:                sipStack = null;
108:                sipProvider = null;
109:                sipFactory = SipFactory.getInstance();
110:                sipFactory.setPathName("gov.nist");
111:                Properties properties = new Properties();
112:                String transport = "udp";
113:                properties.setProperty("javax.sip.OUTBOUND_PROXY",
114:                        "127.0.0.1:5070/" + transport);
115:                properties.setProperty("javax.sip.STACK_NAME", "subscriber");
116:                properties.setProperty("javax.sip.MAX_MESSAGE_SIZE", "1048576");
117:                properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
118:                        "subscriberdebug.txt");
119:                properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
120:                        "subscriberlog.txt");
121:                // Drop the client connection after we are done with the transaction.
122:                properties.setProperty(
123:                        "gov.nist.javax.sip.CACHE_CLIENT_CONNECTIONS", "false");
124:                // Set to 0 in your production code for max speed.
125:                // You need  16 for logging traces. 32 for debug + traces.
126:                // Your code will limp at 32 but it is best for debugging.
127:                properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
128:
129:                try {
130:                    // Create SipStack object
131:                    sipStack = sipFactory.createSipStack(properties);
132:                    System.out.println("createSipStack " + sipStack);
133:                } catch (PeerUnavailableException e) {
134:                    // could not find
135:                    // gov.nist.jain.protocol.ip.sip.SipStackImpl
136:                    // in the classpath
137:                    e.printStackTrace();
138:                    System.err.println(e.getMessage());
139:                    System.exit(0);
140:                }
141:
142:                try {
143:                    headerFactory = sipFactory.createHeaderFactory();
144:                    addressFactory = sipFactory.createAddressFactory();
145:                    messageFactory = sipFactory.createMessageFactory();
146:                    ListeningPoint lp = sipStack.createListeningPoint(
147:                            "127.0.0.1", 5060, "udp");
148:                    sipProvider = sipStack.createSipProvider(lp);
149:                    Subscriber listener = this ;
150:                    sipProvider.addSipListener(listener);
151:                    lp = sipStack
152:                            .createListeningPoint("127.0.0.1", 5060, "tcp");
153:                    SipProvider sipProvider1 = sipStack.createSipProvider(lp);
154:                    sipProvider1.addSipListener(listener);
155:                    String fromName = "BigGuy";
156:                    String fromSipAddress = "here.com";
157:                    String fromDisplayName = "The Master Blaster";
158:
159:                    String toSipAddress = "there.com";
160:                    String toUser = "LittleGuy";
161:                    String toDisplayName = "The Little Blister";
162:
163:                    // create >From Header
164:                    SipURI fromAddress = addressFactory.createSipURI(fromName,
165:                            fromSipAddress);
166:
167:                    Address fromNameAddress = addressFactory
168:                            .createAddress(fromAddress);
169:                    fromNameAddress.setDisplayName(fromDisplayName);
170:                    FromHeader fromHeader = headerFactory.createFromHeader(
171:                            fromNameAddress, "12345");
172:
173:                    // create To Header
174:                    SipURI toAddress = addressFactory.createSipURI(toUser,
175:                            toSipAddress);
176:                    Address toNameAddress = addressFactory
177:                            .createAddress(toAddress);
178:                    toNameAddress.setDisplayName(toDisplayName);
179:                    ToHeader toHeader = headerFactory.createToHeader(
180:                            toNameAddress, null);
181:
182:                    // create Request URI
183:                    SipURI requestURI = addressFactory.createSipURI(toUser,
184:                            toSipAddress);
185:
186:                    // Create ViaHeaders
187:
188:                    ArrayList viaHeaders = new ArrayList();
189:                    int port = sipProvider.getListeningPoint("udp").getPort();
190:                    ViaHeader viaHeader = headerFactory.createViaHeader(
191:                            "127.0.0.1", port, transport, null);
192:
193:                    // add via headers
194:                    viaHeaders.add(viaHeader);
195:
196:                    // Create a new CallId header
197:                    CallIdHeader callIdHeader = sipProvider.getNewCallId();
198:
199:                    // Create a new Cseq header
200:                    CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L,
201:                            Request.SUBSCRIBE);
202:
203:                    // Create a new MaxForwardsHeader
204:                    MaxForwardsHeader maxForwards = headerFactory
205:                            .createMaxForwardsHeader(70);
206:
207:                    // Create the request.
208:                    Request request = messageFactory.createRequest(requestURI,
209:                            Request.SUBSCRIBE, callIdHeader, cSeqHeader,
210:                            fromHeader, toHeader, viaHeaders, maxForwards);
211:                    // Create contact headers
212:                    String host = lp.getIPAddress();
213:
214:                    SipURI contactUrl = addressFactory.createSipURI(fromName,
215:                            host);
216:                    contactUrl.setPort(lp.getPort());
217:
218:                    // Create the contact name address.
219:                    SipURI contactURI = addressFactory.createSipURI(fromName,
220:                            host);
221:                    contactURI.setPort(sipProvider.getListeningPoint("udp")
222:                            .getPort());
223:
224:                    Address contactAddress = addressFactory
225:                            .createAddress(contactURI);
226:
227:                    // Add the contact address.
228:                    contactAddress.setDisplayName(fromName);
229:
230:                    contactHeader = headerFactory
231:                            .createContactHeader(contactAddress);
232:                    request.addHeader(contactHeader);
233:
234:                    // Create the client transaction.
235:                    listener.subscribeTid = sipProvider
236:                            .getNewClientTransaction(request);
237:
238:                    // send the request out.
239:                    listener.subscribeTid.sendRequest();
240:
241:                } catch (Exception ex) {
242:                    System.out.println(ex.getMessage());
243:                    ex.printStackTrace();
244:                    usage();
245:                }
246:            }
247:
248:            public static void main(String args[]) {
249:                new Subscriber().init();
250:
251:            }
252:
253:            public void processIOException(IOExceptionEvent exceptionEvent) {
254:                System.out.println("io exception event recieved");
255:            }
256:
257:            public void processTransactionTerminated(
258:                    TransactionTerminatedEvent transactionTerminatedEvent) {
259:                System.out.println("transaction terminated");
260:
261:            }
262:
263:            public void processDialogTerminated(
264:                    DialogTerminatedEvent dialogTerminatedEvent) {
265:                System.out.println("dialog terminated event	recieved");
266:            }
267:
268:            public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
269:
270:                System.out.println("Transaction Time out");
271:            }
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.