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 Index » WebSphere Message Broker (ACE) Support » navigating XML message in Java Compute Node

Post new topic  Reply to topic
 navigating XML message in Java Compute Node « View previous topic :: View next topic » 
Author Message
wyatt
PostPosted: Wed Oct 18, 2006 5:14 am    Post subject: navigating XML message in Java Compute Node Reply with quote

Voyager

Joined: 28 Nov 2004
Posts: 76

Hi Folks

Anyone know how to get the entire XML document using provided methods within MB java compute node?

MbElement root = assembly.getMessage().getRootElement();
MbElement document = root.getLastChild().getFirstChild();
MbElement chapter = document.getFirstChild(); // returns the first chapter
as documented in http://www-128.ibm.com/developerworks/websphere/library/techarticles/0605_crocker/0605_crocker.html

Currently, I have a working kludge as follows:
byte[] msgBytes = inMessage.getBuffer();
String msgString = new String(msgBytes);
String xmlMessage = msgString.substring(msgString.indexOf("<"));
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Oct 18, 2006 5:21 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Whaddya mean, "the entire XML document"?

What you get inside a JCN is the logical message tree - just like what you get inside a ComputeNode.

In either case, you can ask for the bit stream that the logical message tree represents. In ESQL, this is done using the ASBITSTREAM function, and in Java it's done basically the way you've shown.

There's no way, that I'm aware of, to get the Document object that the internal parser used to build the logical message tree from a bistream that contained XML data.

But regardless, you can navigate and manipulate the logical message tree - without needing to access the bitstream.

In the JavaCompute node, you can use XPath - at least a subset of XPath 1.0 - to navigate and manipulate the message tree. Or you can use the various methods on MbElement and MbAssembly and etc. to do this.

What are you actually trying to do with "the entire XML document"?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
wyatt
PostPosted: Wed Oct 18, 2006 5:38 am    Post subject: Reply with quote

Voyager

Joined: 28 Nov 2004
Posts: 76

..using xstream to convert the XML into a java object
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Oct 18, 2006 5:59 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

...

why?

...

Again, you can get the bitstream - which you basically are already doing and it's not a kludge - but you can't get a w3c DOM Document or etc without creating one from the bitstream.

But the logical message tree is already "a Java object", and you can navigate it as such. If you're trying to call some "reusable" Java code that accepts a particular object you may be computationally better off writing something that accesses the necessary fields of the logical tree and inserts them into that Java object than reparsing the bitstream.

If the Java object is complicated, you may be better off exposing the "reusable" Java code as a WebService and invoking it that way.

If you're just trying to create a Java object that you can then access from your code in the JavaCompute node - then you really should just navigate the logical message tree.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
wyatt
PostPosted: Wed Oct 18, 2006 7:01 am    Post subject: Reply with quote

Voyager

Joined: 28 Nov 2004
Posts: 76

The java object will be passed to a different team. This team has designed a set of "services" that accept java objects as part of the service signature - the service applies business rules and persistence to DB. The java compute node contains about 10 lines of code, it converts XML to Java Objects; i.e. serializes the XML data.

I don't know what you mean by "But the logical message tree is already "a Java object", and you can navigate it as such". Is there a better way to create Java Objects in MB?
Back to top
View user's profile Send private message
mlafleur
PostPosted: Wed Oct 18, 2006 7:06 am    Post subject: Reply with quote

Acolyte

Joined: 19 Feb 2004
Posts: 73

You can use the toBitstream method of MbElement.

For example,

byte[] xml = msg.getRootElement().getLastChild().toBitstream(null, null, "XMLNS", 0, 0, 0);
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Oct 18, 2006 7:11 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

You're going to have some fun trying to get those services to run inside Message Broker.

Especially if their persistance layer tries to use a Type 2 JDBC driver, or if they are written using J2EE.

Your JavaCompute node is going to run in a JVM that is specific to the ExecutionGroup that your flow is deployed to.

The XML Data that your JavaCompute node receives will have already been un-marshalled (not serialized!) to MbElement Java objects. You're not serializaing and unserializing the data, you're marshalling it from XML to a Java object, and unmarshalling it from a Java object to XML data.

That's why you have to get the bitstream - because you're trying to marshal it back to XML data.

Instead of remarshalling the XML data into a bitstream and then passing it to XStream to unmarshall back into an instance of a specific Java object of a specific class, you can create an empty Java object of that specific class.

Then you can use the methods on MbElement and MbNode to navigate to the specific part of the XML data you need for each field in the Java object that you need to pass to this "service". Then you can call a setter on the Java object to apply the vlaue from the MbElement. Think of this as a "copy constructor" rather than an unmarshalling step.

But again, you may have some difficulty getting these "services" to run in the WMB execution group JVM.

And a Java "interface" does not a "service" make.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
wyatt
PostPosted: Wed Oct 18, 2006 8:09 am    Post subject: Reply with quote

Voyager

Joined: 28 Nov 2004
Posts: 76

mlafleur wrote:
You can use the toBitstream method of MbElement.

For example,

byte[] xml = msg.getRootElement().getLastChild().toBitstream(null, null, "XMLNS", 0, 0, 0);


That works, Thx
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Oct 18, 2006 8:12 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

That assumes that you're using the XMLNS parser.

In WMB v6, you should probably use the XMLNSC parser.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
wyatt
PostPosted: Wed Oct 18, 2006 8:52 am    Post subject: Reply with quote

Voyager

Joined: 28 Nov 2004
Posts: 76

jefflowrey wrote:
That assumes that you're using the XMLNS parser.

In WMB v6, you should probably use the XMLNSC parser.


I made the necessary adjustment

Thanks for the insight/suggestions
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » navigating XML message in Java Compute Node
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.