ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexIBM MQ Java / JMSCan not read MQ headers from file using Java

Post new topicReply to topic
Can not read MQ headers from file using Java View previous topic :: View next topic
Author Message
hoangnam214
PostPosted: Sat Jul 02, 2016 4:59 pm Post subject: Can not read MQ headers from file using Java Reply with quote

Newbie

Joined: 02 Jul 2016
Posts: 4
Location: Hanoi, Vietnam

Hi everyone,

I'm very new to IBM MQ.
I'm trying to use Java with libraries from com.ibm.mq.headers.* to read headers from a file.
This file, I made by using RFHUtil tool.

My code throws an exception when it reads this line "MQRFH2 rfh = new MQRFH2(in, CMQC.MQENC_NATIVE, 1208);":
Code:

com.ibm.mq.headers.MQDataException: MQJE001: Completion Code '2', Reason '2195'.
   at com.ibm.mq.headers.MQDataException.getMQDataException(MQDataException.java:331)
   at com.ibm.mq.headers.MQRFH2.read(MQRFH2.java:240)
   at com.ibm.mq.headers.MQRFH2.<init>(MQRFH2.java:151)
   at com.ibm.sterling.MQHeadersReader.main(MQHeadersReader.java:32)
Caused by: java.lang.IndexOutOfBoundsException
   at java.io.DataInputStream.readFully(Unknown Source)
   at com.ibm.mq.headers.internal.DataInputWrapper.readFully(MessageWrapper.java:528)
   at com.ibm.mq.headers.internal.store.ByteStore.readFrom(ByteStore.java:499)
   at com.ibm.mq.headers.internal.Header.read(Header.java:1053)
   at com.ibm.mq.headers.MQRFH2.read(MQRFH2.java:229)
   ... 2 more


In RFHUtil, I set "MQ Message Format" to "MQHRF2", "CCSID" to "1208", add some properties inside "usr" tab like "myfirstheader=abc123".

My Java code is as follows:
Code:

File file = new File("00000673E7_20160613173555000920_ZRN_SHIPMENTS_3B2__FROM_SAP.xml.zip.mq");
InputStream fis = null;

try {
   
   fis = new FileInputStream(file);
   byte[] bytes = new byte[fis.available()];
   fis.read(bytes);
   DataInput in = new DataInputStream(new ByteArrayInputStream(bytes));
   
   MQRFH2 rfh = new MQRFH2(in, CMQC.MQENC_NATIVE, 1208);
   
} catch (MQDataException e1) {
   e1.printStackTrace();
} catch (IOException e2) {
   e2.printStackTrace();
} finally {
   try {
      if (fis != null)
         fis.close();
   } catch (IOException e3) {
      e3.printStackTrace();
   }
}


If I change my code as follows, the program keep iterating forever through "MQHeaderIterator it" and all "it.next()" return null:
Code:

File file = new File("00000673E7_20160613173555000920_ZRN_SHIPMENTS_3B2__FROM_SAP.xml.zip.mq");
InputStream fis = null;

try {
   
   fis = new FileInputStream(file);
   byte[] bytes = new byte[fis.available()];
   fis.read(bytes);
   DataInput in = new DataInputStream(new ByteArrayInputStream(bytes));
   
   MQHeaderIterator it = new MQHeaderIterator(in, "MQHRF2", CMQC.MQENC_NATIVE, 1208);
   while (it.hasNext()) {
      MQHeader header = (MQHeader) it.next();
      if (header != null) {
         System.out.println(header);
      }
   }
   
} catch (IOException e2) {
   e2.printStackTrace();
} finally {
   try {
      if (fis != null)
         fis.close();
   } catch (IOException e3) {
      e3.printStackTrace();
   }
}


Thank you for your help.
Nam
Back to top
View user's profile Send private message Send e-mail
hughson
PostPosted: Sat Jul 02, 2016 6:28 pm Post subject: Reply with quote

Shaman

Joined: 09 May 2013
Posts: 726
Location: Bay of Plenty, New Zealand

I don't understand, why are you reading a file? These interfaces are for reading messages from a queue. Why would they work for a file?
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
fjb_saper
PostPosted: Sat Jul 02, 2016 9:25 pm Post subject: Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19303
Location: LI,NY


Have you looked at the examples and also at
https://www.ibm.com/support/knowledgecenter/en/search/pcf%20examples?scope=SSFKSJ_9.0.0 ??

Why are you creating a HeaderIterator when what you should be doing is creating a HeaderList, updating its chaining and then maybe iterating through its headers??...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
hoangnam214
PostPosted: Sun Jul 03, 2016 11:12 pm Post subject: Reply with quote

Newbie

Joined: 02 Jul 2016
Posts: 4
Location: Hanoi, Vietnam

hughson wrote:
I don't understand, why are you reading a file? These interfaces are for reading messages from a queue. Why would they work for a file?


I was required to write Java Task Service code for Sterling (Eg: http://www.worldofintegration.com/category/sterling-integrator/service/java-task-service)
The input of Java Task Service code that I can take is InputStream but not MQMessage.
It's the reason why I'm trying to read from a file. (Refer: http://www.ibm.com/support/knowledgecenter/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q030960_.htm)
Back to top
View user's profile Send private message Send e-mail
hoangnam214
PostPosted: Sun Jul 03, 2016 11:21 pm Post subject: Reply with quote

Newbie

Joined: 02 Jul 2016
Posts: 4
Location: Hanoi, Vietnam

fjb_saper wrote:

Have you looked at the examples and also at
https://www.ibm.com/support/knowledgecenter/en/search/pcf%20examples?scope=SSFKSJ_9.0.0 ??

Why are you creating a HeaderIterator when what you should be doing is creating a HeaderList, updating its chaining and then maybe iterating through its headers??...

My purpose is to extract the headers and body from the input file.
I've tried HeaderList instead of HeaderIterator:
Code:
MQHeaderList myHeaderList = new MQHeaderList(in, "MQHRF2", CMQC.MQENC_NATIVE, 1208);

But when I ran the program, it threw an exception as follows:
Code:

Exception in thread "main" java.lang.NullPointerException
   at com.ibm.mq.headers.MQHeaderList.read(MQHeaderList.java:324)
   at com.ibm.mq.headers.MQHeaderList.read(MQHeaderList.java:302)
   at com.ibm.mq.headers.MQHeaderList.read(MQHeaderList.java:283)
   at com.ibm.mq.headers.MQHeaderList.<init>(MQHeaderList.java:158)
   at com.ibm.sterling.MQHeadersReader.main(MQHeadersReader.java:78)

Back to top
View user's profile Send private message Send e-mail
hughson
PostPosted: Mon Jul 04, 2016 3:22 am Post subject: Reply with quote

Shaman

Joined: 09 May 2013
Posts: 726
Location: Bay of Plenty, New Zealand

These interfaces are not designed for reading from a file. Therefore it is not a surprise that they do not work. You have to write some other code, you cannot use these interfaces to do what you are trying to do.
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
fjb_saper
PostPosted: Mon Jul 04, 2016 9:39 am Post subject: Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19303
Location: LI,NY

So what you're after is not the Message, or the header list per se, but the message content. Instead of downloading the message to file using RFHUtil, which is not the same as serializing an MQMessage... you should look at retrieving a message and accessing its payload...
Then you can use that payload to try your google translation API.

And don't forget to use UTF-8.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
hoangnam214
PostPosted: Sun Jul 17, 2016 12:59 am Post subject: Reply with quote

Newbie

Joined: 02 Jul 2016
Posts: 4
Location: Hanoi, Vietnam

Thank you fjb_saper and hughson,

I have done extracting the RFH2 headers.

Following to your advises, I tried using RFHUtil tool to put the message to a queue, then wrote Java code to get that message from my queue.

I notice an important thing that I must specify MQGMO_PROPERTIES_FORCE_MQRFH2 open option when getting the message. Otherwise, all headers will be loss.

Best regards,
Nam
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Sun Jul 17, 2016 4:10 am Post subject: Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19303
Location: LI,NY

Try using MQGMO_PROPERTIES_IN_HANDLE and accessing them as message properties...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
hughson
PostPosted: Sun Jul 17, 2016 9:43 pm Post subject: Reply with quote

Shaman

Joined: 09 May 2013
Posts: 726
Location: Bay of Plenty, New Zealand

hoangnam214 wrote:
I notice an important thing that I must specify MQGMO_PROPERTIES_FORCE_MQRFH2 open option when getting the message. Otherwise, all headers will be loss.

Alternatively you can use the queue attribute PROPCTL(FORCE), but it is better to do it in the application.

Cheers
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ Java / JMSCan not read MQ headers from file using Java
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.