Source Code Cross Referenced for Sender.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » alarm » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.alarm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // "plain/text"
002:        package org.objectweb.alarm;
003:
004:        import java.io.*;
005:        import javax.jms.*;
006:        import javax.servlet.*;
007:        import javax.servlet.http.*;
008:        import javax.naming.Context;
009:        import javax.naming.InitialContext;
010:        import javax.naming.NamingException;
011:        import javax.rmi.PortableRemoteObject;
012:
013:        /**
014:         * This servlet is used to send Alarms on a JMS topic
015:         */
016:        public class Sender extends HttpServlet {
017:
018:            public void doGet(HttpServletRequest req, HttpServletResponse res)
019:                    throws IOException, ServletException {
020:
021:                res.setContentType("text/html");
022:                PrintWriter out = res.getWriter();
023:                String device = req.getParameter("device");
024:                String level = req.getParameter("level");
025:                String message = req.getParameter("message");
026:                String sloop = req.getParameter("number");
027:                String stimeout = req.getParameter("timeout");
028:                int severity;
029:                String error = "";
030:
031:                out
032:                        .write("<html><head><title>Alarm Sender Servlet</title></head><body>");
033:                if (level.startsWith("S")) {
034:                    severity = 1;
035:                } else if (level.startsWith("W")) {
036:                    severity = 2;
037:                } else {
038:                    severity = 3;
039:                }
040:                int loop = (new Integer(sloop)).intValue();
041:                int timeout = (new Integer(stimeout)).intValue();
042:
043:                Context ictx = null;
044:                try {
045:                    ictx = new InitialContext();
046:                } catch (Exception e) {
047:                    error += "Cannot get initial context:" + e;
048:                }
049:
050:                // Lookup JMS resources
051:                TopicConnectionFactory tcf = null;
052:                Topic mytopic = null;
053:                TopicConnection mytc = null;
054:                try {
055:                    // lookup the TopicConnectionFactory through its JNDI name
056:                    tcf = (TopicConnectionFactory) ictx
057:                            .lookup("java:comp/env/jms/TopicFactory");
058:                    // lookup the Topic through its JNDI name
059:                    mytopic = (Topic) ictx
060:                            .lookup("java:comp/env/jms/AlarmTopic");
061:                } catch (NamingException e) {
062:                    error += "Cannot lookup JMS Resources:" + e;
063:                }
064:
065:                // Create Connection
066:                try {
067:                    mytc = tcf.createTopicConnection();
068:                } catch (Exception e) {
069:                    error += "Cannot create JMS Connection:" + e;
070:                }
071:
072:                // Create Session + Publisher
073:                TopicSession session = null;
074:                TopicPublisher tp = null;
075:                try {
076:                    session = mytc.createTopicSession(false,
077:                            Session.AUTO_ACKNOWLEDGE);
078:                    tp = session.createPublisher(mytopic);
079:                } catch (Exception e) {
080:                    error += "Cannot create JMS Publisher:" + e;
081:                }
082:
083:                // publish messages to the topic
084:                try {
085:                    for (int i = 0; i < loop; i++) {
086:                        if (timeout > 0) {
087:                            Thread.currentThread().sleep(1000 * timeout);
088:                        }
089:                        MapMessage mess = session.createMapMessage();
090:                        mess.setInt("Severity", severity);
091:                        mess.setString("From", device);
092:                        mess.setString("Reason", message);
093:                        tp.publish(mess);
094:                    }
095:                } catch (JMSException e) {
096:                    String l = e.getLinkedException().toString();
097:                    error += " Exception while creating or sending message: "
098:                            + e;
099:                    error += " Linked Exception: " + l;
100:                } catch (java.lang.InterruptedException e) {
101:                    out.println("Alarm Generator Interrupted");
102:                }
103:
104:                if (error.equals("")) {
105:                    out.println("Message sent");
106:                } else {
107:                    out.println(error);
108:                }
109:                out
110:                        .println("<p>return to <a href=\"../generator.html\">Alarm Generator</a>");
111:                out.println("<p>go to <a href=\"list.jsp\">Alarm List</a>");
112:
113:                // close connection
114:                try {
115:                    mytc.close();
116:                } catch (Exception e) {
117:                }
118:
119:                out.println("</body>");
120:                out.println("</html>");
121:            }
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.