Author |
Message
|
bijesh |
Posted: Sun Mar 11, 2007 8:42 pm Post subject: Writing to a file |
|
|
Acolyte
Joined: 30 Jan 2007 Posts: 66
|
Hi,
I've a flow , MQInput -> Java compute node.
MQInput node uses an MRM parser to read the input message from a queue. Java compute node writes the message to a file. When I do this, I'm getting an exception as below.
<com.ibm.broker.plugin.MbParserException class:JNI method:CpContext::loadWorker
source:BIPv600 key:5136 >
at com.ibm.broker.plugin.MbElement._toBitstream(Native Method)
at com.ibm.broker.plugin.MbElement.toBitstream(MbElement.java:2221)
at com.tgt.wbimb.enterprise.amzgiftregistry.AMZGR_FILE_WRITE_MF_JavaComp
ute.evaluate(AMZGR_FILE_WRITE_MF_JavaCompute.java:45)
at com.ibm.broker.javacompute.MbRuntimeJavaComputeNode.evaluate(MbRuntim
eJavaComputeNode.java:105)
at com.ibm.broker.plugin.MbNode.evaluate(MbNode.java:1222)
Instead of MRM parser, If I'm sending an XML message and parse it using an XMLNSC parser the data gets written to the file.
Any thoughts to share on this? |
|
Back to top |
|
 |
bijesh |
Posted: Sun Mar 11, 2007 8:52 pm Post subject: Re: Writing to a file |
|
|
Acolyte
Joined: 30 Jan 2007 Posts: 66
|
The code being used in the Java compute node follows..
Code: |
MbElement mbElement=inMessage.getRootElement();
MbElement body=mbElement.getLastChild();
System.out.println("the body of the message is "+body.getName());
//MbElement body=mqmd.getNextSibling();
b=body.toBitstream(null,null,null,0,1208,0);
FileOutputStream fout=new FileOutputStream("c:\\Test2.txt",false);
fout.write(b);
fout.close(); |
|
|
Back to top |
|
 |
kimbert |
Posted: Mon Mar 12, 2007 2:20 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
toBitstream(null,null,null, |
The docs say:
Quote: |
public byte[] toBitstream(String messageType,
String messageSet,
String messageFormat,
int encoding,
int ccsid,
int options) throws MbException |
You need to set the message set, message type and message format.
I do think the error message could be better, though. |
|
Back to top |
|
 |
bijesh |
Posted: Mon Mar 12, 2007 2:52 am Post subject: |
|
|
Acolyte
Joined: 30 Jan 2007 Posts: 66
|
kimbert wrote: |
Quote: |
toBitstream(null,null,null, |
The docs say:
Quote: |
public byte[] toBitstream(String messageType,
String messageSet,
String messageFormat,
int encoding,
int ccsid,
int options) throws MbException |
You need to set the message set, message type and message format.
I do think the error message could be better, though. |
When I provide the values for those arguments, the exception becomes this,
<com.ibm.broker.plugin.MbParserException class:JNI method:MtiImbRMErrorMap::chec
kRC source:BIPv600 key:5304 >
at com.ibm.broker.plugin.MbElement._toBitstream(Native Method)
at com.ibm.broker.plugin.MbElement.toBitstream(MbElement.java:2221)
at com.tgt.wbimb.enterprise.amzgiftregistry.AMZGR_FILE_WRITE_MF_JavaComp
ute.evaluate(AMZGR_FILE_WRITE_MF_JavaCompute.java:45)
at com.ibm.broker.javacompute.MbRuntimeJavaComputeNode.evaluate(MbRuntim
eJavaComputeNode.java:105)
at com.ibm.broker.plugin.MbNode.evaluate(MbNode.java:1222) |
|
Back to top |
|
 |
kimbert |
Posted: Mon Mar 12, 2007 4:46 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
You have set something incorrectly. Maybe the parameters are in the wrong order? ( toBitstream's parameters are Type, Set, Format which is not the usual order ).
I have a suggestion.
- insert a Compute node before your Java Compute node,
- use the ESQL function ASBITSTREAM to convert the message tree to a BLOB
- Change your java to expect a BLOB instead of a message tree.
If you do it this way, you will get better error messages. Once you get this working you may be able to switch back to using toBitstream. |
|
Back to top |
|
 |
bijesh |
Posted: Mon Mar 12, 2007 8:14 pm Post subject: |
|
|
Acolyte
Joined: 30 Jan 2007 Posts: 66
|
- Change your java to expect a BLOB instead of a message tree.
How can I make my java compute node to expect a BLOB instead of a message tree.? |
|
Back to top |
|
 |
kimbert |
Posted: Tue Mar 13, 2007 1:19 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Err, how about something like this:
Code: |
MbElement mbElement=inMessage.getRootElement();
//Set MbElement to InputRoot.BLOB
MbElement body=mbElement.getLastChild();
//Set MbElement to InputRoot.BLOB.BLOB
MbElement BLOB =body.getLastChild();
//now get the value of BLOB and write it to the file
...
|
|
|
Back to top |
|
 |
bijesh |
Posted: Tue Mar 13, 2007 2:54 am Post subject: |
|
|
Acolyte
Joined: 30 Jan 2007 Posts: 66
|
kimbert wrote: |
Err, how about something like this:
Code: |
MbElement mbElement=inMessage.getRootElement();
//Set MbElement to InputRoot.BLOB
MbElement body=mbElement.getLastChild();
//Set MbElement to InputRoot.BLOB.BLOB
MbElement BLOB =body.getLastChild();
//now get the value of BLOB and write it to the file
...
|
|
Not much success..
the 'body' itself gives me 'MRM' as the last child.
again getting last child gives me the last element in the MRM. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Mar 13, 2007 3:23 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
OK - sorry for confusing you. I should have told you do this:
In the Compute node which you inserted:
- use ASBITSTREAM to convert your MRM tree to a BLOB.
- save that BLOB in the environment tree.
In the Java Compute node
- access the environment tree and save the BLOB to your file. |
|
Back to top |
|
 |
bijesh |
Posted: Tue Mar 13, 2007 7:59 pm Post subject: |
|
|
Acolyte
Joined: 30 Jan 2007 Posts: 66
|
kimbert wrote: |
OK - sorry for confusing you. I should have told you do this:
In the Compute node which you inserted:
- use ASBITSTREAM to convert your MRM tree to a BLOB.
- save that BLOB in the environment tree.
In the Java Compute node
- access the environment tree and save the BLOB to your file. |
thanks a lot for your suggestions.
tried it, but results in the same exception. Even if the data is in the environment as a blob , I need to use the toBitStream function to convert it into bytes, right? Then only i'l b able to write into a file. |
|
Back to top |
|
 |
bijesh |
Posted: Tue Mar 13, 2007 8:01 pm Post subject: |
|
|
Acolyte
Joined: 30 Jan 2007 Posts: 66
|
One more thing is,
instead of an MRM document, If the input is an XML document it is getting written to the file as it is. No exceptions are thrown at this point. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Mar 14, 2007 4:28 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You won't need to use toBitstream() on a BLOB type. MbElement.getValue should return a bytes[] if the element is a BLOB. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
bijesh |
Posted: Wed Mar 14, 2007 9:36 pm Post subject: |
|
|
Acolyte
Joined: 30 Jan 2007 Posts: 66
|
jefflowrey wrote: |
You won't need to use toBitstream() on a BLOB type. MbElement.getValue should return a bytes[] if the element is a BLOB. |
Thanks Jefflowrey..
I 'm getting some success out of this..
Thanks to Kimbert too... |
|
Back to top |
|
 |
team |
Posted: Thu Oct 04, 2007 5:19 am Post subject: |
|
|
Centurion
Joined: 03 Nov 2006 Posts: 108
|
Hi,
I do a very similar thing:
MbMessage inMessage = contact admin.getMessage();
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin,outMessage);
String filename = "c:\temp.txt";
File outfile = new File(filename);
FileOutputStream fos = new FileOutputStream(outfile);
//fos.write(outMessage.getRootElement().getLastChild().getName().getBytes());
fos.write((byte[])outMessage.getRootElement().getLastChild().getValue());
However the file is empty.
If outMessage.getRootElement().getLastChild().getName().getBytes() , this gives me the result as BLOB. Would you know where I am going wrong?
Rgds |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Oct 04, 2007 2:35 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Wouldn't the bytes be in the BLOB.BLOB?
So :
outMessage.getRootElement().getLastChild().getLastChild().getValue();
 _________________ MQ & Broker admin |
|
Back to top |
|
 |
|