Author |
Message
|
ashbhai |
Posted: Fri Jan 19, 2007 7:33 am Post subject: Request your review on the below code... |
|
|
Newbie
Joined: 19 Jan 2007 Posts: 4
|
Hi all,
Request your review on the below code. I am sending a message to be processed by MQ-CICS bridge and reading the response from a dynamic queue. I am adding the required MQCIH headers.
The backend team is able to tell me that the message is being processed But I am getting a MQ error 2033 when I read the response.
Please advice where I am getting it wrong.
Thanks.
Ash
Code: |
import java.io.*;
import java.net.*;
import com.ibm.mq.*;
public class MQTest {
public static void main(String a[]){
int MQ_TIMEOUT = 60000;
int WAIT_TIME = 1;
/*Queue Manager Name and Queue name*/
String QUEUE_MANAGER_ACCOUNT_INQUIRY = "*HCS_TB_BUNDLED";
String REQUEST_QUEUE_ACCOUNT_INQUIRY = "HCS.TOOLBARS.BUNDLED.VIEW";
/*Reply Model queue name and dynamic reply queue name template*/
String modelQName = "HI.NON.PERSISTENT.REPLY.MODEL";
String dynamicQName = "ASH.*";
String replyQName=null;
// Put & Get Options
int openPutOpt = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_INQUIRE;
int openGetOpt = MQC.MQOO_INPUT_SHARED | MQC.MQOO_FAIL_IF_QUIESCING;
int reqLen = 0;
String reqText1 = null;
int repLen = 0;
String repText = null;
MQEnvironment mqenv = new MQEnvironment();
/* Request Queue*/
MQQueue reqQueue1 = null;
/*Response Queue*/
MQQueue respQueue = null;
FileOutputStream traceFile;
try {
System.out.println("MQ Version: " + mqenv.version_notice);
//Enable or disable code tracing
traceFile = new FileOutputStream("C:\\myapp.trace");
mqenv.port = 23302; //MQ Server Port Number
mqenv.hostname = "hostname"; //MQ Server hostname or IP
mqenv.channel = "HCS0A.TB.BUNDLED"; //Channel name
//Adding UserID and password
mqenv.userID="";
mqenv.password="";
mqenv.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
MQQueueManager qm1 = new MQQueueManager(QUEUE_MANAGER_ACCOUNT_INQUIRY);
//Connecting to the Request queue
reqQueue1 = qm1.accessQueue(REQUEST_QUEUE_ACCOUNT_INQUIRY, openPutOpt, null, null, null);
//Connecting to the model queue to get the dynamic response queue name
respQueue = qm1.accessQueue(modelQName, openGetOpt, null, dynamicQName, null);
//Setting the dynamic response queue name
System.out.println("Reply Queue name: " + respQueue.name );
MQPutMessageOptions pmo = new MQPutMessageOptions();
String strCorelID = "AMQ!NEW_SESSION_CORRELID";
//reqText1 = "BBT9GTMVAR1 VEN341 29970001 WCRV2 ACCT#000<AccNo>TBRIN1 29970 WCGAI001 ACCT#000<AccNo> 00100 WCGAI00105000ACCT#000<AccNo> WCATH ACCT#000<AccNo> 00100 WCATH 01650ACCT#000<AccNo> WCMPSA ACCT#000<AccNo> 00100 WCMPSA 15000ACCT#000<AccNo>00000 II0899 WCEZI ACCT#000<AccNo> 00100 WCEZI 00570ACCT#000<AccNo> WCINS ACCT#000<AccNo> 00100 ";
reqText1 = "BBT2GTMVAR1 VEN341 29970001 WCFOC001 CUST#0004121790004200772 29970 WCFOC00114250CUST#00041217900042007720004121790004200772 I045 ";
reqLen = reqText1.length();
System.out.println("Request Message Length without message headers: " + reqLen);
MQMessage putMessage1 = new MQMessage();
//Setting the Reply Q Manager and Reply Q Name in the MQMessage
putMessage1.replyToQueueManagerName="";
putMessage1.replyToQueueName = respQueue.name;
//Setting the message type
putMessage1.messageType=MQC.MQMT_REQUEST;
//Setting the message Correlation ID
putMessage1.correlationId = strCorelID.getBytes();
/* Build the CIH Message header */
putMessage1.format="MQCICS "; //value of MQFMT_CICS
putMessage1.encoding=MQC.MQENC_INTEGER_NORMAL; //Big-endian integers, as in Java
putMessage1.characterSet=819; //Default Char set
putMessage1.writeString("CIH "); //MQCHAR4 StrucId; /* Structure identifier */
putMessage1.writeInt(1); //MQLONG Version; /* Structure version number 1 or 2 */
putMessage1.writeInt(164); //MQLONG StrucLength; /* Length of MQCIH structure V1=164 V2=180 */
putMessage1.writeInt(putMessage1.encoding); //MQLONG Encoding; /* Reserved */
putMessage1.writeInt(putMessage1.characterSet); //MQLONG CodedCharSetId; /* Reserved */
putMessage1.writeString(MQC.MQFMT_STRING); //MQCHAR8 Format; /* MQ Format name */
putMessage1.writeInt(0); //MQLONG Flags; /* Reserved */
putMessage1.writeInt(0); //MQLONG ReturnCode; /* Return code from bridge */
putMessage1.writeInt(0); //MQLONG CompCode; /* MQ completion code or CICS EIBRESP */
putMessage1.writeInt(0); //MQLONG Reason; /* MQ reason or feedback code, or CICS EIBRESP2 */
putMessage1.writeInt(273); //MQLONG UOWControl; /* Unit-of-work control */
putMessage1.writeInt(-2); //MQLONG GetWaitInterval; /* Wait interval for MQGET call issued by bridge */
putMessage1.writeInt(1); //MQLONG LinkType; /* Link type */
//Length of output data set to 30K
putMessage1.writeInt(30720); //MQLONG OutputDataLength; /* Output commarea data length */
putMessage1.writeInt(0); //MQLONG FacilityKeepTime; /* Bridge facility release time */
putMessage1.writeInt(0); //MQLONG ADSDescriptor; /* Send/receive ADS descriptor */
putMessage1.writeInt(0); //MQLONG ConversationalTask; /* Whether task can be conversational */
putMessage1.writeInt(0); //MQLONG TaskEndStatus; /* Status at end of task */
//byte [] temp = new byte[8]; //initialise as required
putMessage1.writeBytes("\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"); //MQBYTE Facility[8]; /* BVT token value */
putMessage1.writeString(" "); //MQCHAR4 Function; /* MQ call name or CICS EIBFN function name */
putMessage1.writeString(" "); //MQCHAR4 AbendCode; /* Abend code */
putMessage1.writeString(" "); //MQCHAR8 Authenticator; /* Password or passticket */
putMessage1.writeString(" "); //MQCHAR8 Reserved1; /* Reserved */
putMessage1.writeString(MQC.MQFMT_STRING); //MQCHAR8 ReplyToFormat; /* MQ format name of reply message */
putMessage1.writeString(" "); //MQCHAR4 RemoteSysId; /* Remote sysid to use */
putMessage1.writeString(" "); //MQCHAR4 RemoteTransId; /* Remote transid to attach */
putMessage1.writeString(" "); //MQCHAR4 TransactionId; /* Transaction to attach */
putMessage1.writeString(" "); //MQCHAR4 FacilityLike; /* Terminal emulated attributes */
putMessage1.writeString(" "); //MQCHAR4 AttentionId; /* AID key */
putMessage1.writeString(" "); //MQCHAR4 StartCode; /* Transaction start code */
putMessage1.writeString(" "); //MQCHAR4 CancelCode; /* Abend transaction code */
putMessage1.writeString(" "); //MQCHAR4 NextTransactionId; /* Next transaction to attach */
putMessage1.writeString(" "); //MQCHAR8 Reserved2; /* Reserved */
putMessage1.writeString(" "); //MQCHAR8 Reserved3; /* Reserved */
//Since we are using CIH header version 1, version 2 fields are not required
/* Start of version 2 fields*/
//putMessage1.writeInt(0); //MQLONG CursorPosition; /* Cursor position */
//putMessage1.writeInt(0); //MQLONG ErrorOffset; /* Error offset */
//putMessage1.writeInt(0); //MQLONG InputItem; /* Input item */
//putMessage1.writeInt(0); //MQLONG Reserved4; /* Reserved */
/* End of version 2 fields */
/* End of CIH message header*/
int headerLen = putMessage1.getMessageLength();
//Version 1 Header length should be 164 bytes
System.out.println("Header Len: " + headerLen);
//Backend program name to execute for processing this message (8 bytes)
putMessage1.writeString("GTMMGR1 ");
//Finally writing the message text after the header, program to execute
putMessage1.writeString(reqText1);
int requestLen = putMessage1.getMessageLength();
//Length of the final message (header + program name+ message text)
System.out.println("Request message length: " + requestLen);
//MQEnvironment.enableTracing(4,traceFile);
//Put message into the queue
reqQueue1.put(putMessage1, pmo);
//MQEnvironment.disableTracing();
System.out.println("Sleeping for 2 sec after send");
Thread.sleep(2000);
System.out.println("Ready to receive the response...");
MQMessage getMessage = new MQMessage();
/* Define get options */
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = MQ_TIMEOUT;
//Getting the response message with the same Correlation ID
getMessage.correlationId=strCorelID.getBytes();
respQueue.get(getMessage, gmo);
int respMsgLen = getMessage.getMessageLength();
// Read the response
String respMsgText = getMessage.readStringOfByteLength(respMsgLen);
System.out.println("Response message length = " + respMsgLen);
System.out.println("Response message is: " + respMsgText);
reqQueue1.close();
respQueue.close();
qm1.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
[/code] |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Jan 19, 2007 7:41 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
2033 means that there isn't a response to process. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
ashbhai |
Posted: Fri Jan 19, 2007 8:01 am Post subject: |
|
|
Newbie
Joined: 19 Jan 2007 Posts: 4
|
But the back end team is telling me that I am not doing the GET operation right. The response message is put in the dynamic queue.
Please guide me.
Thanks
Ash |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Jan 19, 2007 9:12 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You're doing entirely the wrong things with correlationID and messageID. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
ashbhai |
Posted: Fri Jan 19, 2007 9:19 am Post subject: |
|
|
Newbie
Joined: 19 Jan 2007 Posts: 4
|
Hi jefflowrey
Can you please be more specific?
Thanks a lot.
Ash |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Jan 19, 2007 9:20 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Everything you are doing with correlationID is wrong. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
ashbhai |
Posted: Fri Jan 19, 2007 9:33 am Post subject: |
|
|
Newbie
Joined: 19 Jan 2007 Posts: 4
|
Hi jefflowrey
Still not getting you.  |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Jan 19, 2007 10:00 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
1) You are assigning a specific value to the correlation Id of the request message. That's wrong
2) You are assigning a text value to the correlation id of an MQ message. That's wrong.
3) You're assigning the same value to the correlation ID of the request message as you are to the correlation ID of the response message. That's wrong.
4) You're trying to use the correlation ID of the request message to match the correlation ID of the response message. That's wrong.
Every line of code that you have written that references the correlationID field is doing the wrong thing.
What have you read that said you should do things this way? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|