Author |
Message
|
Natalya V.S. |
Posted: Tue Aug 15, 2006 5:14 am Post subject: Working with JMS messages using JavaCompute |
|
|
Newbie
Joined: 15 Aug 2006 Posts: 5
|
Hello all:)
I have a message flow like
JMSInput ->JavaCompute ->JMSOutput.
How can I use package javax.jms in a JavaCompute Node?
Or I can use only MbMessage class for parsing incoming message?
There is such text in Broker documentation:
"The payload for some of the JMS message types can be extracted as a whole from the message object by using the JMS API. The payload is passed as a bit stream to a broker parser. This is true for the following message types:
* BytesMessage
* TextMessage
* ObjectMessage
Additional processing is required to deal with the ObjectMessage payload because the JMS ObjectMessage payload is a serialized Java Object.
The JMSInput node obtains the payload by calling getObject( ) on the message. getObject( ) returns a de-serialized object of the original class. This class definition must be made available to the JMSInput node, and you should ensure that it is accessible through the broker's Java class path. (The class path is defined in the mqsiprofile batch file, which is in the broker's executable directory; for example, on Windows, this is mqsiprofile.cmd in the install_dir/bin directory.) The JMSInput node invokes the BLOB parser, which creates the message body by using a bit stream that is created from the object.
The Java Object can be subsequently re-serialized in a JavaCompute Node or a user-defined extension, and is updated by using its method calls.
"
(http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/index.jsp?topic=/com.ibm.etools.mft.eb.doc/ac24869_.htm)
The last phrase said that it's possible to use jms api,isn't it?
Thanks . |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Aug 15, 2006 5:16 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Well, doesn't it seem likely that the JMS api would already be on the classpath of a JCN running inside a flow that has JMS nodes on it?
Did you try adding "import javax.jms.*;" to your JCN code?
I think it will just work. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Natalya V.S. |
Posted: Wed Aug 16, 2006 12:05 am Post subject: |
|
|
Newbie
Joined: 15 Aug 2006 Posts: 5
|
Yes, "import javax.jms.*;" works.
But I had to a kind a little another problem.
Maybe it'silly question, but I don't know how to transform MbMessage to javax.jms.Message inside Java code in JavaCompute node...
How to get access to source javax.jms.Message... |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 16, 2006 2:58 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Don't think you really need to.
What you do need is the bitstream from the message, and you are getting that as a BLOB.
Now you can use it to deserialize the object, perform any methods needed on the object, reserialize it into a bitstream (BLOB) and send it on its way back...
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Natalya V.S. |
Posted: Thu Aug 17, 2006 2:15 am Post subject: |
|
|
Newbie
Joined: 15 Aug 2006 Posts: 5
|
Thanks,
Do you mean something like this?
"
try
{
MbMessage inMessage = contact admin.getMessage();
MbElement root=inMessage.getRootElement();
MbElement blob = root.getFirstElementByPath("/BLOB");
log.write((blob.toString()).getBytes());
javax.jms.Message jmsmsg;
byte[] payload=blob.toBitstream(null,null,null,0,0,0);
if(payload != null) {
log.write("payload not null".getBytes());
ObjectInputStream in =
new ObjectInputStream(new ByteArrayInputStream(payload));
Object obj = in.readObject();
log.write("THERE!".getBytes());
jmsmsg=(javax.jms.Message)obj;
String messageID = jmsmsg.getJMSMessageID();
}
}
catch(ClassNotFoundException e) {
log.write("ClassNotFoundException".getBytes());
}
catch(JMSException ej) {
log.write("JMSException".getBytes());
}
"
but it doesn't work.. no errors and exceptions, but it does not reach the line "log.write("THERE!".getBytes());"
Then I use "payload = inMessage.getBuffer()" instead of "payload=blob.toBitstream(...)" result is the same..

Last edited by Natalya V.S. on Thu Aug 17, 2006 2:40 am; edited 1 time in total |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 17, 2006 2:23 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I wouldn't toString this...
I might (bytes[])(blob.getValue()) _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Aug 17, 2006 3:09 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
And the resulting object from the bitstream (BLOB) would not be of type javax.jms.Message but would represent the payload of the javax.jms.ObjectMessage.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Natalya V.S. |
Posted: Thu Aug 17, 2006 3:13 am Post subject: |
|
|
Newbie
Joined: 15 Aug 2006 Posts: 5
|
Ooh...
if I use
byte[] payload=(byte[])(blob.getValue());
payload becomes null.
if I use "payload=blob.toBitStream(..)", payload is empty/
if I use "payload=inMessage.getBuffer()", payload contains smth like
"<Transport_Folders><Message_MetaData><PayloadType>Byte</PayloadType><MessagePersistence>Non_Persistent</MessagePersistence></Message_MetaData><Header_Values><JMSDestination> </JMSDestination><JMSDeliveryMode dt="i4">1</JMSDeliveryMode><JMSExpiration dt="r8">0E+0</JMSExpiration><JMSPriority dt="i4">0</JMSPriority><JMSTimestamp
...
</JMSXUserID></Standard_Properties></Transport_Folders>"
but it doesn't contain message data.
but all of there byte[] objects cannot convert to javax.jms.Message (and for Object maybe too!).
Maybe I do something wrong there?
" ObjectInputStream in =
new ObjectInputStream(new ByteArrayInputStream(payload));
Object obj = in.readObject();
jmsmsg=(javax.jms.Message)obj; " //or javax.jms.ObjectMessage
Excuse me please, probably I'm really newbie.. and I cannot understand simple things 
Last edited by Natalya V.S. on Thu Aug 17, 2006 3:31 am; edited 1 time in total |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Aug 17, 2006 3:29 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Remember as well in JMS you can have a message with no payload. In MQ this means it would only have the RFH part be meaningfull. This would mean that the meaningfull information is in the properties that have been set on the message, or in case of a pub/sub registration etc...
You would really have to inspect the message as such before it hits the broker. Maybe use a JMSBrowser to understand exactly how your message is made up before you try to model it.
Furthermore your message seems to be of the type BytesMessage and not ObjectMessage. So you may not be able to create an Object from it as it just transports bytes and not necessarily a serialized java object...
From what you have described your bit stream would only represent the RFH header or its equivalent if the provider is non MQ?
Hope it helps some.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 17, 2006 4:14 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Yeah, casting the Object result of getValue to a byte[] isn't going to work...
My point was more that the BLOB MBElement contains the bytes you need, and getValue is pretty much the right way to retrieve those.
I know somewhere there is somewhere in the info center a description of mapping from MBElement value types to Java types, to know what kind of Object you'll get back.
Now my brain wants to suggest (blob.getValue()).getBytes(), but I don't trust it. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Natalya V.S. |
Posted: Thu Aug 17, 2006 5:22 am Post subject: |
|
|
Newbie
Joined: 15 Aug 2006 Posts: 5
|
Thank you!
It was the problem with jms sender program, and now "payload=inMessage.getBuffer()"
returns all the message with it's content and headers.
but my tries to deserialize it don't work((
But it's something with what is possible to work further)
jefflowrey, but now blob element is null, instead of it is "XML" element...
and I think that it is possible to work further only with inMessage.getBuffer()...
thanks all:) |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 17, 2006 5:26 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You won't be able to deserialize it if it's not an ObjectMessage.
You might be able to unmarshall the XML into an object using something like Castor or JAXB or whatever the kids are using these days.
But if it's XML data, you should let WMB parse it for you, and just walk the fields using MBElement and MBNode and etc. - unless you have existing Java code to handle the XML data that you are trying to reuse. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|