Author |
Message
|
cmmatei |
Posted: Tue Oct 10, 2006 4:43 am Post subject: JavaCompute Node detach() |
|
|
 Apprentice
Joined: 06 Feb 2006 Posts: 26 Location: PARIS/NEW YORK
|
Hello,
I would like to copy the xml data of a message into a file.
I use a JavaCompute Node as it follows :
evaluate(MbMessageAssembly assembly) throws MbException {
..............
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly, assembly.getMessage());
MbElement mqmdHeader = outAssembly.getMessage().getRootElement().getFirstChild().getNextSibling();
mqmdHeader.detach();
MbMessage msg = outAssembly.getMessage();
byte[] bitstream = msg.getBuffer();
//write bitestream to a file
...........
The problem is that the detach() method fails.
I would like to know why detach() throws an exception and which is the good way to get only the xml data from the message.
Thank you,
Cornel |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Oct 10, 2006 4:51 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
How does it fail? What's the exception? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Oct 10, 2006 5:07 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
which is the good way to get only the xml data from the message |
No idea why detach() fails. But why would ASBITSTREAM not do what you need? ( search this forum if you need an example - there must be dozens of posts about this ). |
|
Back to top |
|
 |
cmmatei |
Posted: Tue Oct 10, 2006 6:06 am Post subject: |
|
|
 Apprentice
Joined: 06 Feb 2006 Posts: 26 Location: PARIS/NEW YORK
|
Seems that can't read the content of the message?
'com.ibm.broker.plugin.MbReadOnlyMessageException'
(0x03000000):Catalog = 'BIPv600'
(0x03000000):Severity = 3
(0x03000000):Number = 4395
(0x03000000):Text = 'Unhandled exception in plugin method'
(0x01000000):Insert = (
(0x03000000):Type = 5
(0x03000000):Text = 'com.ibm.broker.plugin.MbReadOnlyMessageException'
)
(0x01000000):Insert = (
(0x03000000):Type = 5
(0x03000000):Text = 'com.ibm.broker.plugin.MbElement'
)
(0x01000000):Insert = (
(0x03000000):Type = 5
(0x03000000):Text = 'detach'
)
(0x01000000):Insert = (
(0x03000000):Type = 5
(0x03000000):Text = 'MbElement.java'
) |
|
Back to top |
|
 |
cmmatei |
Posted: Tue Oct 10, 2006 8:00 am Post subject: |
|
|
 Apprentice
Joined: 06 Feb 2006 Posts: 26 Location: PARIS/NEW YORK
|
Please find here the JavaComputeNode solution to write xml messages into a flat file:
public void evaluate(MbMessageAssembly assembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");
MbMessage inMessage = assembly.getMessage();
// create new message
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly,outMessage);
MbElement mqmdHeader = outAssembly.getMessage().getRootElement().getFirstChild().getNextSibling();;
mqmdHeader.detach();
MbMessage msg = outAssembly.getMessage();
byte[] bitstream = msg.getBuffer();
// ----------------------------------------------------------
// Add user code below
//PrintWriter streamFile;
try
{
FileOutputStream outputStream = new FileOutputStream("/file");
outputStream.write(bitstream);
outputStream.close();
}
catch(IOException exc)
{
System.out.println("Erreur d'ouverture");
}
message to the 'out' terminal
out.propagate(assembly);
}
Thanks for IBM experts help! |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Oct 10, 2006 8:07 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Okay.
You're doing
Code: |
MbMessage inMessage = assembly.getMessage();
// create new message
MbMessage outMessage = new MbMessage(inMessage); |
properly to create a message tree that you can edit.
But then you ignore that and do
Code: |
MbElement mqmdHeader = outAssembly.getMessage()... |
.
Try
Code: |
MbElement mqmdHeader = outMessage.getRootElement().getFirstChild().getNextSibling(); |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
cmmatei |
Posted: Tue Oct 10, 2006 9:47 am Post subject: |
|
|
 Apprentice
Joined: 06 Feb 2006 Posts: 26 Location: PARIS/NEW YORK
|
Sorry... I wasn't very clear in my last post.
The code I put in my last message works very well.
Thanks for your help!
 |
|
Back to top |
|
 |
chids |
Posted: Tue Oct 10, 2006 11:29 pm Post subject: |
|
|
 Novice
Joined: 09 Oct 2006 Posts: 22 Location: Stockholm, Sweden
|
As you've noticed the MbAssembly, and the contained message, that are passed in to your comput node are read only. To modify the assembly (except for the global env which is always mutable) or the message you need to make a copy and work on that. _________________ /mårten.
-- http://marten.gustafson.pp.se/
-- marten.gustafson@gmail.com |
|
Back to top |
|
 |
|