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


001:        package test.load.subsnotify;
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:        /**
010:         * This class is a UAS template.
011:         * 
012:         * @author M. Ranganathan
013:         */
014:
015:        public class Notifier implements  SipListener {
016:
017:            private static AddressFactory addressFactory;
018:
019:            private static MessageFactory messageFactory;
020:
021:            private static HeaderFactory headerFactory;
022:
023:            private static SipStack sipStack;
024:
025:            private static final int myPort = 5070;
026:
027:            protected ServerTransaction inviteTid;
028:
029:            private SipProvider sipProvider;
030:
031:            class MyTimerTask extends TimerTask {
032:                Notifier notify;
033:
034:                public MyTimerTask(Notifier notify1) {
035:                    notify = notify1;
036:
037:                }
038:
039:                public void run() {
040:
041:                }
042:
043:            }
044:
045:            protected static final String usageString = "java " + "notifier \n"
046:                    + ">>>> is your class path set to the root?";
047:
048:            private static void usage() {
049:                System.out.println(usageString);
050:                System.exit(0);
051:
052:            }
053:
054:            public void processRequest(RequestEvent requestEvent) {
055:                Request request = requestEvent.getRequest();
056:                ServerTransaction serverTransactionId = requestEvent
057:                        .getServerTransaction();
058:
059:                System.out.println("\n\nRequest " + request.getMethod()
060:                        + " received at " + sipStack.getStackName()
061:                        + " with server transaction id " + serverTransactionId);
062:
063:                if (request.getMethod().equals(Request.SUBSCRIBE)) {
064:                    ServerTransaction st = processSubscribe(requestEvent,
065:                            serverTransactionId);
066:                    // This could be a retransmission for a Server Transaction 
067:                    // associated with Dialog that we have already deleted.
068:                    if (st.getDialog().getState() != DialogState.TERMINATED) {
069:                        sendNotify(st.getDialog());
070:                    }
071:                }
072:
073:            }
074:
075:            public void sendNotify(Dialog dialog) {
076:
077:                try {
078:
079:                    Request request = dialog.createRequest(Request.NOTIFY);
080:
081:                    // Create a new MaxForwardsHeader
082:                    MaxForwardsHeader maxForwards = headerFactory
083:                            .createMaxForwardsHeader(70);
084:                    request.setHeader(maxForwards);
085:
086:                    // Create contact headers
087:                    String host = "127.0.0.1";
088:
089:                    SipURI contactUrl = addressFactory.createSipURI(null, host);
090:                    contactUrl.setLrParam();
091:                    contactUrl.setPort(sipProvider.getListeningPoint("udp")
092:                            .getPort());
093:
094:                    Address contactAddress = addressFactory
095:                            .createAddress(contactUrl);
096:
097:                    request.setHeader(headerFactory
098:                            .createContactHeader(contactAddress));
099:
100:                    EventHeader eventHeader = null;
101:                    eventHeader = headerFactory.createEventHeader("reg");
102:                    request.addHeader(eventHeader);
103:
104:                    SubscriptionStateHeader subscriptionStateHeader = headerFactory
105:                            .createSubscriptionStateHeader("active");
106:                    subscriptionStateHeader.setExpires(200);
107:                    request.addHeader(subscriptionStateHeader);
108:
109:                    ClientTransaction ct = sipProvider
110:                            .getNewClientTransaction(request);
111:                    dialog.sendRequest(ct);
112:
113:                    // send the request out.
114:
115:                } catch (Exception ex) {
116:                    System.out.println(ex.getMessage());
117:                    ex.printStackTrace();
118:                    usage();
119:                }
120:
121:            }
122:
123:            public void processResponse(ResponseEvent responseEvent) {
124:            }
125:
126:            public ServerTransaction processSubscribe(
127:                    RequestEvent requestEvent,
128:                    ServerTransaction serverTransactionId) {
129:                SipProvider sipProvider = (SipProvider) requestEvent
130:                        .getSource();
131:                Request request = requestEvent.getRequest();
132:                try {
133:                    System.out
134:                            .println("notifier:  got a subscribe. sending OK.");
135:                    Response response = messageFactory.createResponse(200,
136:                            request);
137:                    if (serverTransactionId == null) {
138:                        serverTransactionId = sipProvider
139:                                .getNewServerTransaction(request);
140:                    }
141:
142:                    ExpiresHeader expires = (ExpiresHeader) request
143:                            .getHeader(ExpiresHeader.NAME);
144:                    response.addHeader(request.getHeader(ExpiresHeader.NAME));
145:                    response.addHeader(request.getHeader(EventHeader.NAME));
146:                    ToHeader toHeader = (ToHeader) response
147:                            .getHeader(ToHeader.NAME);
148:                    if (toHeader.getTag() == null) {
149:                        String tag = new Long(new java.util.Random().nextLong())
150:                                .toString();
151:                        toHeader.setTag(tag);
152:                    }
153:                    serverTransactionId.sendResponse(response);
154:                    System.out.println("Dialog State is "
155:                            + serverTransactionId.getDialog().getState());
156:                    if (expires.getExpires() == 0) {
157:                        System.out.println("Deleting Dialog ");
158:                        serverTransactionId.getDialog().delete();
159:                    }
160:                    return serverTransactionId;
161:                } catch (Exception ex) {
162:                    ex.printStackTrace();
163:                    System.exit(0);
164:
165:                }
166:                return null;
167:            }
168:
169:            public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
170:                Transaction transaction;
171:                if (timeoutEvent.isServerTransaction()) {
172:                    transaction = timeoutEvent.getServerTransaction();
173:                } else {
174:                    transaction = timeoutEvent.getClientTransaction();
175:                }
176:                System.out.println("state = " + transaction.getState());
177:                System.out.println("dialog = " + transaction.getDialog());
178:                System.out.println("dialogState = "
179:                        + transaction.getDialog().getState());
180:                System.out.println("Transaction Time out");
181:            }
182:
183:            public void init() {
184:                SipFactory sipFactory = null;
185:                sipStack = null;
186:                sipFactory = SipFactory.getInstance();
187:                sipFactory.setPathName("gov.nist");
188:                Properties properties = new Properties();
189:                String transport = "udp";
190:                String peerHostPort = "127.0.0.1:5060";
191:                properties.setProperty("javax.sip.OUTBOUND_PROXY", peerHostPort
192:                        + "/" + transport);
193:                properties.setProperty("javax.sip.STACK_NAME", "notifier");
194:                // You need 16 for logging traces. 32 for debug + traces.
195:                // Your code will limp at 32 but it is best for debugging.
196:                properties
197:                        .setProperty("gov.nist.javax.sip.TRACE_LEVEL", "NONE");
198:                properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
199:                        "shootmedebug.txt");
200:                properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
201:                        "shootmelog.txt");
202:                properties.setProperty(
203:                        "gov.nist.javax.sip.MAX_LISTENER_RESPONSE_TIME", "20");
204:
205:                try {
206:                    // Create SipStack object
207:                    sipStack = sipFactory.createSipStack(properties);
208:                    System.out.println("sipStack = " + sipStack);
209:                } catch (PeerUnavailableException e) {
210:                    // could not find
211:                    // gov.nist.jain.protocol.ip.sip.SipStackImpl
212:                    // in the classpath
213:                    e.printStackTrace();
214:                    System.err.println(e.getMessage());
215:                    if (e.getCause() != null)
216:                        e.getCause().printStackTrace();
217:                    System.exit(0);
218:                }
219:
220:                try {
221:                    headerFactory = sipFactory.createHeaderFactory();
222:                    addressFactory = sipFactory.createAddressFactory();
223:                    messageFactory = sipFactory.createMessageFactory();
224:                    ListeningPoint lp = sipStack.createListeningPoint(
225:                            "127.0.0.1", myPort, "udp");
226:
227:                    Notifier listener = this ;
228:
229:                    sipProvider = sipStack.createSipProvider(lp);
230:                    System.out.println("udp provider " + sipProvider);
231:                    sipProvider.addSipListener(listener);
232:
233:                } catch (Exception ex) {
234:                    System.out.println(ex.getMessage());
235:                    ex.printStackTrace();
236:                    usage();
237:                }
238:
239:            }
240:
241:            public static void main(String args[]) {
242:                new Notifier().init();
243:            }
244:
245:            public void processIOException(IOExceptionEvent exceptionEvent) {
246:                System.out.println("IOException");
247:
248:            }
249:
250:            public void processTransactionTerminated(
251:                    TransactionTerminatedEvent transactionTerminatedEvent) {
252:                System.out.println("Transaction terminated event recieved");
253:
254:            }
255:
256:            public void processDialogTerminated(
257:                    DialogTerminatedEvent dialogTerminatedEvent) {
258:                System.out.println("Dialog terminated event recieved");
259:
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.