I am setting the Correlation ID while sending the message to MQ. And I need to use the CorrelationID from the COA of the message I pushed for the further processing.
I am setting the correlation ID and sending the message to queue using the below code.
MQMessage message = createMQMessage("12345");
message.write("Some message to push".getBytes());
queue.put(message);
private MQMessage createMQMessage(String corrID){
MQMessage message = new MQMessage();
message.messageFlags = MQConstants.MQMF_SEGMENTATION_ALLOWED;
if (ackQueueName != null) {
message.messageType = MQConstants.MQMT_REQUEST;
message.replyToQueueManagerName = ackQueueManagerName;
message.replyToQueueName = ackQueueName;
message.report = MQConstants.MQRO_COA | MQConstants.MQRO_COD;
message.correlationId = corrID.getBytes();
}
return message;
}
I am reading the replyQueue from another application to get the COA and extract the correlation ID for further processing.
But the correlation ID is in byte[]
format and I used the below method getHexString
to get the string. But all I got is 48 digit Hex format of my correlation ID like
414d5120514d41444556202020202020b5ca0d5b13b3bb20
public static String getHexString(byte[] b) throws Exception {
String result = "";
for (int i=0; i < b.length; i++) {
result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
}
return result;
}
All I need is the approach to convert the 48digit HexString to the Original Correlation ID I set. I tried using the below method to convert, but its giving me the junk data.
public static String hexStringToByteArray(String hex) {
int l = hex.length();
byte[] data = new byte[l/2];
for (int i = 0; i < l; i += 2) {
data[i/2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
+ Character.digit(hex.charAt(i+1), 16));
}
return new String(data);
}