Author |
Message
|
DevNYC1 |
Posted: Wed Jul 24, 2013 8:07 am Post subject: Accessing Text Message inside Java Compute Node |
|
|
Apprentice
Joined: 22 Aug 2012 Posts: 32
|
This is a very simple question, I am sure, but I am struggling to make this simple thing work. In my flow the 1st node is MQInput that reads the plain text message from the Q which is sent to the JCN node.
Previously, I worked with the XML messages and the MQInput's domain was XMLNSC so I could do something like this to retrieve the XML:
Code: |
MbElement inBody = getMessage().getRootElement().getLastChild();
String message = inBody.toString();
|
Since I am now working with the text message I set the MQInput domain to MRM. The above code does not work properly for the simple text messages.
Any thoughts? |
|
Back to top |
|
 |
lancelotlinc |
Posted: Wed Jul 24, 2013 8:23 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Your post is very vague. You leave out details like version numbers for toolkit and runtime, what message set you are using with MRM, and the output of your Trace nodes in your flow. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
DevNYC1 |
Posted: Wed Jul 24, 2013 8:59 am Post subject: |
|
|
Apprentice
Joined: 22 Aug 2012 Posts: 32
|
lancelotlinc wrote: |
Your post is very vague. You leave out details like version numbers for toolkit and runtime, what message set you are using with MRM, and the output of your Trace nodes in your flow. |
Sorry, here are all the details you requested.
1) Version 7.1
2) I am not using a message set
3) My current flow (I simplified it) is as follows:
MQInput-->JCN--->MQOutput and that's it.
I want to make sure I can read the contents of the text file that is placed on the Queue in the Java Compute Node into the String variable so I can do additional processing. I will add complexity once that piece is working.
I did not add any Trace nodes since the problem is not that I am getting an exception, but that the following:
Code: |
MbElement swiftMessage = inBody.getLastChild();
Log.logger.info("Message Body: " + inBody.toString()); |
returns:
07/24/13 12:54:13 TEST_JAVA_PROG 126 INFO : Message Body: MbElement( type: 3000000 name: OriginalLength value: -1 ) |
|
Back to top |
|
 |
lancelotlinc |
Posted: Wed Jul 24, 2013 9:04 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
DevNYC1 wrote: |
lancelotlinc wrote: |
Your post is very vague. You leave out details like version numbers for toolkit and runtime, what message set you are using with MRM, and the output of your Trace nodes in your flow. |
Sorry, here are all the details you requested.
1) Version 7.1
2) I am not using a message set
3) My current flow (I simplified it) is as follows:
MQInput-->JCN--->MQOutput and that's it.
I want to make sure I can read the contents of the text file that is placed on the Queue in the Java Compute Node into the String variable so I can do additional processing. I will add complexity once that piece is working.
I did not add any Trace nodes since the problem is not that I am getting an exception, but that the following:
Code: |
MbElement swiftMessage = inBody.getLastChild();
Log.logger.info("Message Body: " + inBody.toString()); |
returns:
07/24/13 12:54:13 TEST_JAVA_PROG 126 INFO : Message Body: MbElement( type: 3000000 name: OriginalLength value: -1 ) |
There is no such version as 7.1.
We need your toolkit version and your runtime version. Version numbers have four digits. We also need your effective level, which is not the same as your version number [mqsireportbroker].
Put Trace nodes before and after every major node in all your flows. There is no reason not to use Trace nodes. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jul 24, 2013 9:09 am Post subject: Re: Accessing Text Message inside Java Compute Node |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
DevNYC1 wrote: |
Since I am now working with the text message I set the MQInput domain to MRM. The above code does not work properly for the simple text messages.
Any thoughts? |
Yes; there's a problem with the way you've described the text message in a message set (as you say MRM I assume WMBv7 as you should be using DFDL in v8 or higher). By the time a message reaches a JCN it's a logical message tree which can be accessed using the sort of code you post; it makes no difference if the originating message is XML (under XMLNSC) or text (under MRM).
What does make a difference is that XML is self describing and the XMLNSC can work out the structure itself. Text is not self describing and the MRM parser relies on you to describe it. If the above code "does not work properly" (and you could be a bit more technical in your error description there) then the first suspects are your MRM message set and your code.
Trace nodes are an excellent suggestion for this kind of problem. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Wed Jul 24, 2013 9:23 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
|
Back to top |
|
 |
Vitor |
Posted: Wed Jul 24, 2013 9:41 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
lancelotlinc wrote: |
DevNYC1 wrote: |
2) I am not using a message set |
Not sure how the flow is going to work without a message set: |
Oooo....nice spot!  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
DevNYC1 |
Posted: Wed Jul 24, 2013 9:43 am Post subject: |
|
|
Apprentice
Joined: 22 Aug 2012 Posts: 32
|
Let me be precise on the version - it's 7.0.0.4 of the toolkit and the runtime.
Should I attach the Trace node to the "out" terminal of the MQInput node?
I am utilizing now the default Message Set with the MRM domain.
The Video Rental sample above is using ESQL, not Java Compute Node. But I will look into it closely to see if I can understand how to retrieve the text in the Java Compute Node. |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed Jul 24, 2013 9:57 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
There are plenty of other samples that use JCN's. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jul 24, 2013 10:34 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
DevNYC1 wrote: |
I am utilizing now the default Message Set with the MRM domain. |
Why? Why not build one? How do you know that matches your data? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
DevNYC1 |
Posted: Wed Jul 24, 2013 2:07 pm Post subject: |
|
|
Apprentice
Joined: 22 Aug 2012 Posts: 32
|
Vitor wrote: |
DevNYC1 wrote: |
I am utilizing now the default Message Set with the MRM domain. |
Why? Why not build one? How do you know that matches your data? |
I am not an expert on Message Broker, although used it quite a bit for the XML processing in the past few months. I am looking to solve a very simple problem, conceptually. I need to retrieve a text message from the MQ Queue in JCN - that's it.
If this was a simple JMS/MQ program we'd be talking about 1 line of code.
I tried using the message set with the MRM domain (specified it for MQInput) but then my JCN is not even being invoked. I know I am doing something wrong. I assume that I need to amend the message set somehow to allow for the processing of this plain text message so that it reaches the JCN and can be retrieved. |
|
Back to top |
|
 |
DevNYC1 |
Posted: Wed Jul 24, 2013 5:39 pm Post subject: |
|
|
Apprentice
Joined: 22 Aug 2012 Posts: 32
|
I found the solution on one blog after a very long, exhaustive search - in case anyone wants to know how to accomplish this simple task:
1) Set Blob as Message Domain on the MQInput Node
2) Use the following code in the JCN to retrieve the text as String from the queue:
MbElement inRoot = inMessage.getRootElement();
byte[] MessageBodyByteArray = (byte[]) (inRoot.getFirstElementByPath( "/BLOB/BLOB" ).getValue());
String msgStr = new String(MessageBodyByteArray); |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jul 24, 2013 9:18 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
DevNYC1 wrote: |
I found the solution on one blog after a very long, exhaustive search - in case anyone wants to know how to accomplish this simple task:
1) Set Blob as Message Domain on the MQInput Node
2) Use the following code in the JCN to retrieve the text as String from the queue:
MbElement inRoot = inMessage.getRootElement();
byte[] MessageBodyByteArray = (byte[]) (inRoot.getFirstElementByPath( "/BLOB/BLOB" ).getValue());
String msgStr = new String(MessageBodyByteArray); |
BAD Boy. You are completely bypassing the CCSID issue. Your java code makes a lot of assumptions one of which is that the CCSID corresponds to the default CCSID of the platform java is running in. This may or may not be the case... but before you convert a byte[] into a String you need to use the newer API using
Code: |
String msgStr = new String( byte[], DecodingCCSID); |
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
DevNYC1 |
Posted: Thu Jul 25, 2013 3:40 am Post subject: |
|
|
Apprentice
Joined: 22 Aug 2012 Posts: 32
|
fjb_saper wrote: |
BAD Boy. You are completely bypassing the CCSID issue. Your java code makes a lot of assumptions one of which is that the CCSID corresponds to the default CCSID of the platform java is running in |
Can you please suggest what I should change to take care of this CCSID issue? Should I choose the MRM domain and change the code accordingly?
I see a lot of replies in this thread but not a single suggestion in the form of code snippet on how to address this. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jul 25, 2013 5:06 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
What are you trying to actually get?
The entire input message as a String object?
Or the contents of a single field in the input message as a String object?
It seems from the various bits of code you've posted that you're struggling with understanding how Message Broker deals with data, more specifically how the Logical Message Tree works and how you should interact with that.
You might find it easier to work with Broker if you look at the facilities in Toolkit v8 and later to create a JAXB set of classes from your message models.
You generally want to let Message Broker parse input messages into a logical message tree, and then use the Message Broker Java API to interact with the logical message tree as individual fields, using Broker methods to navigate the fields and treating the contents of the fields as belonging to Message Broker Java API types.
It's much easier to do this, and much more maintainable for other message broker developers.
Using the JAXB generated classes makes this easier to do for java programmers who know JAXB but don't know Broker. |
|
Back to top |
|
 |
|