|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
XMLNSC domain to BLOB domain in JavaCompute |
« View previous topic :: View next topic » |
Author |
Message
|
naio |
Posted: Wed Nov 14, 2012 12:01 pm Post subject: XMLNSC domain to BLOB domain in JavaCompute |
|
|
Voyager
Joined: 08 Nov 2012 Posts: 82
|
Hi to all,
For a requeriment, I have to Zip the Payload that cames in the XMLNSC Domain and need to be sennt as a Zipped String to a MQ Queue.
My idea was to zip the hole Payload of the XMLNSC domain, create BLOB domain with that zipped message and delete the XMLNSC Domain.
I could figure it out with a Java Compute, and a Compute, but I am trying to just use the Java Compute, here is muy Code:
FIRST THE JAVA:
MbOutputTerminal out = getOutputTerminal("out");
MbMessage inMessage = contact admin.getMessage();
MbMessage outMessage = new MbMessage(inMessage);
MbElement msgBody;
try {
// ZIP THE MESSAGE
String ccsid = inMessage.getRootElement().getFirstElementByPath("Properties/CodedCharSetId").getValueAsString();
msgBody = outMessage.getRootElement().getLastChild();
Integer ccsidValue = new Integer(ccsid);
byte[] testByteStream = msgBody.toBitstream(null, null, null, 0, ccsidValue, 0);
String message = new String(testByteStream);
String compressMessage = ZipUtils.getInstance().compressToString(message);
//CREATE A NEW ELEMENT CALLED BLOB AND DELETE THE TREE XMLNSC
MbElement root = outMessage.getRootElement();
MbElement msgElement = root.getLastChild();
msgElement.detach();
root.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"BLOB", compressMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin,outMessage);
out.propagate(outAssembly);
}
The OUTPUT of this node is a RootTree with PROPERTIES, MQMD and BLOB subtrees, but the BLOB is not recognized as a DOMAIN and then I can not see it enqueued the PAYLOAD. The result is a message enqueued without PAYLOAD (the zipped message).
So I nedd to put a Compute After this with the following code:
SET OutputRoot.Properties = InputRoot.Properties;
SET OutputRoot.MQMD = InputRoot.MQMD;
CREATE LASTCHILD of OutputRoot DOMAIN('BLOB') Name 'BLOB';
SET OutputRoot.BLOB.BLOB=CAST (InputRoot.BLOB AS BLOB CCSID InputRoot.Properties.CodedCharSetId);
So, I want to now HOY to create properly the BLOB Domain in JAVA in order to just use that node. I have search in the inforcenter and this Forum, but I couldn´t still find the answer.
Thanks in Advance! _________________ "God is in his heaven all's right with the world" |
|
Back to top |
|
 |
naio |
Posted: Wed Nov 14, 2012 5:12 pm Post subject: |
|
|
Voyager
Joined: 08 Nov 2012 Posts: 82
|
I have found a solution. I will post the solution when I am back at the office!
thanks. _________________ "God is in his heaven all's right with the world" |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Nov 14, 2012 6:18 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
naio wrote: |
I have found a solution. I will post the solution when I am back at the office!
thanks. |
relatively easy. You are missing the declaration of the parser:
You should have
Code: |
MbElement parser = root.createElementAsLastChild(MbBLOB.BLOB_NAME); --from memory...
parser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"BLOB", compressMessage); |
Also your conversion to string is not good.
Do not use the input ccsid. Use CCSID 1208 (utf-8 ) you can then specify the same in the conversion to String : new String(byte[], "UTF-8");
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kimbert |
Posted: Thu Nov 15, 2012 1:17 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Do not use the input ccsid. Use CCSID 1208 (utf-8 ) you can then specify the same in the conversion to String : new String(byte[], "UTF-8"); |
If the capture of the bitstream is occurring near the start of the flow then it's best to use InputRoot.Properties.CodedCharSetId. That will ensure that the input bitstream can simply be used as-is.
If you choose a CCSID that is not the same as the input then the parser will need to parse the entire message and re-serialize it in the new character encoding.
However, I do think that this looks strange:
Code: |
String message = new String(testByteStream);
String compressMessage = ZipUtils.getInstance().compressToString(message); |
Surely you want the zip utility to compress the raw bytes, not some string that was created from the bytes? |
|
Back to top |
|
 |
rekarm01 |
Posted: Thu Nov 15, 2012 1:36 am Post subject: Re: XMLNSC domain to BLOB domain in JavaCompute |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
fjb_saper wrote: |
You should have
Code: |
MbElement parser = root.createElementAsLastChild(MbBLOB.BLOB_NAME); --from memory... |
|
Almost. That should be MbBLOB.PARSER_NAME (which resolves to "NONE", not "BLOB"). The parser class name does not always match the parser or root element name, so it's usually a good idea to use the built-in parser constants, rather than hardcoding literal values. |
|
Back to top |
|
 |
naio |
Posted: Fri Nov 16, 2012 5:17 am Post subject: |
|
|
Voyager
Joined: 08 Nov 2012 Posts: 82
|
I have solved it with:
MbElement outParser = root.createElementAsLastChild(MbBLOB.PARSER_NAME);
outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", compressMessage.getBytes());
The want to ZIP the entire message!
Thanks to all!!! _________________ "God is in his heaven all's right with the world" |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|