Due to the IBM migration, the previously utilized connection pool manager is no longer supported. Consequently, I am in the process of identifying an alternative approach for sending messages. It's important to note that the existing code used to send messages as shown below. I have attempted to convert it into equivalent JMS code. However, I'm uncertain whether this conversion is in the correct format or not. When testing on the mainframe side, it results in a '2110 MQRC FORMAT ERROR.' Could you please review and verify the accuracy of this conversion?"
OLD CODE:
MQMessage reqMsg = new MQMessage();
reqMsg.messageId = CMQC.MQMI_NONE;
reqMsg.correlationId = CMQC.MQCI_NEW_SESSION;
reqMsg.userId = racfUserid;
reqMsg.characterSet = CHARSET_IBM500;
reqMsg.persistence = persistence;
// ---- create request message
String result = "";
byte blanks[] = new byte[8];
for (int i=0; i<blanks.length; i++)
blanks[i] = (byte)' ';
reqMsg.clearMessage();
// ---- write MQCIH
reqMsg.writeString ("CIH "); // MQCHAR4 StrucId;
reqMsg.writeInt (2); // MQLONG Version;
reqMsg.writeInt (180); // MQLONG StrucLength;
reqMsg.writeInt (reqMsg.encoding); // MQLONG Encoding;
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = CMQC.MQPMO_NEW_MSG_ID |
CMQC.MQPMO_SET_IDENTITY_CONTEXT |
CMQC.MQPMO_FAIL_IF_QUIESCING;
requestQueue.put (reqMsg, pmo);
//JMS Code
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
Context context = new InitialContext(environment);
ConnectionFactory connectionFactory = (ConnectionFactory) context
.lookup("name");
Destination requestQueue = (Destination) context
.lookup(requestQueueName);
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Destination replyQueue = (Destination) context
.lookup(replyToQueueName);
context.close();
MessageProducer producer = session.createProducer(requestQueue);
BytesMessage message = session.createBytesMessage();
message.setJMSMessageID(MQConstants.MQMI_NONE.toString());
message.setJMSCorrelationIDAsBytes(MQConstants.MQCI_NEW_SESSION);
message.setJMSReplyTo(replyQueue);
message.setStringProperty("JMS_IBM_MQMD_UserIdentifier", racfUserid);
message.setIntProperty("JMS_IBM_MQMD_CodedCharSetId",
byte blanks[] = new byte[8];
for (int i = 0; i < blanks.length; i++)
blanks[i] = (byte) ' ';
// Construct the CIH header as a byte array
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
DataOutputStream outData = new DataOutputStream(outBytes);
outData.writeBytes("CIH "); // MQCHAR strucId
outData.writeInt(2); // MQLONG version
outData.writeInt(180); // MQLONG strucLength
outData.writeInt(messageEncoding); // MQLONG encoding
outData.writeInt(CHARSET_IBM500); // MQLONG CodedCharSetId;
StringBuffer pgmName = new StringBuffer(progName);
for (int i = pgmName.length(); i < 8; i++)
pgmName.append(' ');
outData.writeBytes(pgmName.substring(0, 8));
outData.writeBytes(commArea);
byte[] cihRequestMessage = outBytes.toByteArray();
message.writeBytes(cihRequestMessage);
producer.send(message);
MessageConsumer consumer = session.createConsumer(replyQueue);
Message replyMessage = consumer.receive(replyTimeout * 1000);
I'm confused by what you are doing. Secondly, there is an MQ class called MQCIH that handles CICS messages.
Here's the proper way of doing it:
Update: August 30
You are going down a path very few have gone. I have tried to get IMS/CICS messages to work with JMS but have failed. A JMS message is internally known as an MQRFH2 header.
MQRFH2 and MQCIH headers are called embedded headers. Meaning they exist in front of the message payload and not in a separate structure. So, basically, you are chaining together several embedded headers.
First, you have to set the "format" field of each chained embedded message. MQ/JMS library will set the correct format for the JMS message. But you need to set the format of the MQCIH in the MQRFH2 header. i.e. So MQ knows what to expect in the next part of the chain. And in the MQCIH, you need to set the format of the message payload. i.e. NONE, STRING, etc..
i.e. something like this.
Or possibly this:
Then, you create the MQCIH header:
Finally, you can go down this path but I wouldn't recommend it unless you are extremely knowledgeable of MQ. Personally, I would write the code in Java (not JMS) because it is so much simpler.