Source Code Cross Referenced for MQConnector.java in  » Testing » grinder » org » rextency » mq » 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 » Testing » grinder » org.rextency.mq 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.rextency.mq;
002:
003:        import java.io.File;
004:        import java.io.FileInputStream;
005:        import java.io.IOException;
006:        import java.net.HttpURLConnection;
007:        import java.util.HashSet;
008:        import java.util.Set;
009:        import java.util.regex.Matcher;
010:        import java.util.regex.Pattern;
011:
012:        import com.ibm.mq.*;
013:        import com.ibm.mq.MQPutMessageOptions;
014:        import org.rextency.mq.MQMsg;
015:
016:        /**
017:         * An MQ Class, for sending MQ messages
018:         *
019:         * @author Phillip Mayhew
020:         * @version $Revision: 3298 $
021:         */
022:        public class MQConnector {
023:
024:            private static Pattern s_pathParser = Pattern
025:                    .compile("([^?#]*)(\\?([^#]*))?(#(.*))?");
026:
027:            private MQQueueManager qmgr;
028:            private MQQueue squ;
029:            private MQQueue rqu;
030:            private int GMO_Options = MQC.MQGMO_WAIT | MQC.MQMO_MATCH_CORREL_ID;
031:            private int GMO_WaitInterval = 120000;
032:
033:            public MQConnector() {
034:
035:            }
036:
037:            public boolean init(String pHostname, String pPort,
038:                    String pChannel, MQMsg msg) {
039:                MQEnvironment.hostname = pHostname;
040:                MQEnvironment.port = Integer.parseInt(pPort);
041:                MQEnvironment.channel = pChannel;
042:                MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
043:                        MQC.TRANSPORT_MQSERIES);
044:
045:                try {
046:                    System.out
047:                            .println("QueueManager: " + msg.getQueueManager());
048:                    System.out
049:                            .println("RequestQueue: " + msg.getRequestQueue());
050:                    System.out.println("ReplyQueue: " + msg.getReplyQueue());
051:
052:                    if ((msg.getQueueManager()).length() > 0)
053:                        qmgr = new MQQueueManager(msg.getQueueManager(),
054:                                MQC.MQCNO_FASTPATH_BINDING);
055:                    else
056:                        return false;
057:
058:                    if ((msg.getRequestQueue()).length() > 0)
059:                        squ = qmgr.accessQueue(msg.getRequestQueue(), msg
060:                                .getOpenOptions());
061:
062:                    if ((msg.getReplyQueue()).length() > 0)
063:                        rqu = qmgr.accessQueue(msg.getReplyQueue(), msg
064:                                .getReadOptions());
065:
066:                }
067:
068:                catch (Exception e) {
069:                    System.out.println("Error in: MQConnector.init(): "
070:                            + e.getMessage());
071:                }
072:
073:                return true;
074:            }
075:
076:            public void SendMessage(MQMsg msg) {
077:                System.out.println("ReplyToQueue: " + msg.getReplyToQueue());
078:                System.out.println("ReplyToQueueManager: "
079:                        + msg.getReplyToQueueManager());
080:                try {
081:                    MQPutMessageOptions pmo = new MQPutMessageOptions();
082:                    MQMessage rqMessage = new MQMessage();
083:
084:                    rqMessage.format = MQC.MQFMT_STRING;
085:                    rqMessage.replyToQueueName = msg.getReplyToQueue();
086:                    rqMessage.replyToQueueManagerName = msg
087:                            .getReplyToQueueManager();
088:                    rqMessage.messageType = MQC.MQMT_REQUEST;
089:                    rqMessage.persistence = MQC.MQPER_NOT_PERSISTENT;
090:
091:                    pmo.options = MQC.MQPMO_NEW_MSG_ID;
092:
093:                    rqMessage.writeString(msg.getMessage());
094:                    squ.put(rqMessage, pmo);
095:
096:                    msg.setCorrelationID(new String(rqMessage.messageId));
097:                    squ.close();
098:                } catch (Exception e) {
099:                    System.out
100:                            .println("Exception occured during MQConnector.SendMessage(): "
101:                                    + e.getMessage());
102:                }
103:            }
104:
105:            public String GetMessage(MQMsg msg) {
106:                String retVal = new String();
107:                try {
108:                    MQGetMessageOptions gmo = new MQGetMessageOptions();
109:                    gmo.options = this .GMO_Options;
110:                    gmo.waitInterval = this .GMO_WaitInterval;
111:
112:                    MQMessage rtMessage = new MQMessage();
113:                    rtMessage.correlationId = (msg.getCorrelationID())
114:                            .getBytes();
115:                    System.out.println("CorrelationID: "
116:                            + byteArrayToHexString((msg.getCorrelationID())
117:                                    .getBytes()));
118:                    rqu.get(rtMessage, gmo);
119:                    retVal = rtMessage.readString(rtMessage.getMessageLength());
120:                    rqu.close();
121:                } catch (Exception e) {
122:                    System.out
123:                            .println("Exception occured during MQConnector.GetMessage(): "
124:                                    + e.getMessage());
125:                }
126:
127:                return retVal;
128:            }
129:
130:            public void finish() {
131:                try {
132:                    qmgr.disconnect();
133:                } catch (Exception e) {
134:                    System.out
135:                            .println("Exception occured during MQConnector.finish(): "
136:                                    + e.getMessage());
137:                }
138:
139:            }
140:
141:            public String toString() {
142:                final StringBuffer result = new StringBuffer("MQMessage");
143:
144:                return result.toString();
145:            }
146:
147:            private String byteArrayToHexString(byte in[]) {
148:                byte ch = 0x00;
149:                int i = 0;
150:
151:                if (in == null || in.length <= 0)
152:                    return null;
153:
154:                String pseudo[] = { "0", "1", "2", "3", "4", "5", "6", "7",
155:                        "8", "9", "A", "B", "C", "D", "E", "F" };
156:
157:                StringBuffer out = new StringBuffer(in.length * 2);
158:
159:                while (i < in.length) {
160:                    ch = (byte) (in[i] & 0xF0); // Strip off high nibble
161:                    ch = (byte) (ch >>> 4); // shift the bits down
162:                    ch = (byte) (ch & 0x0F); // must do this is high order bit is on!
163:                    out.append(pseudo[(int) ch]); // convert the nibble to a String Character
164:                    ch = (byte) (in[i] & 0x0F); // Strip off low nibble 
165:                    out.append(pseudo[(int) ch]); // convert the nibble to a String Character
166:                    i++;
167:                }
168:
169:                String rslt = new String(out);
170:                return rslt;
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.