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 » Putting XML content on the output Q in Java Compute Node

Post new topic  Reply to topic
 Putting XML content on the output Q in Java Compute Node « View previous topic :: View next topic » 
Author Message
DevNYC1
PostPosted: Fri Feb 01, 2013 6:56 pm    Post subject: Putting XML content on the output Q in Java Compute Node Reply with quote

Apprentice

Joined: 22 Aug 2012
Posts: 32

I understand how to create XML element by element and place the produced XML on the outbound Q. However, I need to do something different. In my Java Compute Node I am calling a utility that returns already generated XML as a String and I need to write this XML to the Q (MQOutput node)

I thought I can just do this (assume that xml variable contains the XML structure):
Code:
MbElement outParser = outRoot.createElementAsLastChild(MbXMLNSC.PARSER_NAME);       
outRoot.createElementAsFirstChild(xml);


But that does not work - nothing is written to the Q. I could not find any articles on this. Any help would be appreciated.
Back to top
View user's profile Send private message
DevNYC1
PostPosted: Fri Feb 01, 2013 7:14 pm    Post subject: Reply with quote

Apprentice

Joined: 22 Aug 2012
Posts: 32

Found the solution (posting in case someone else finds this useful):

Code:
byte []msgBytes = xml.getBytes();
outRoot.createElementAsLastChildFromBitstream
         (msgBytes,MbXMLNSC.PARSER_NAME,"","","",0,0,0);
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat Feb 02, 2013 4:54 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

You sure about your code?
I would have thought you'd parse attaching to outParser and not outRoot...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
DevNYC1
PostPosted: Sat Feb 02, 2013 6:32 am    Post subject: Reply with quote

Apprentice

Joined: 22 Aug 2012
Posts: 32

fjb_saper wrote:
You sure about your code?
I would have thought you'd parse attaching to outParser and not outRoot...
Just to make sure I understand, can you please provide the code snippet for what you just described?

Here is the article where I found the solution that I posted (see Code Listing 1): http://www.ibm.com/developerworks/websphere/library/techarticles/1101_dunna/1101_dunna.html?ca=drs-
Back to top
View user's profile Send private message
kimbert
PostPosted: Sat Feb 02, 2013 1:44 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

1. This code is not safe (although it is very common):
Code:
byte []msgBytes = xml.getBytes();
outRoot.createElementAsLastChildFromBitstream
         (msgBytes,MbXMLNSC.PARSER_NAME,"","","",0,0,0);
You should almost never call the single-parameter version of java.lang.String.getBytes(). You cannot guarantee the character encoding of the bytes that will be returned. It is much safer to specify an encoding using the two-parameter version.

2. I'm not convinced that you need to use XMLNSC at all. If you have been given a valid XML string then why not convert it to a BLOB ( in the encoding required by the consumer ) and then output that BLOB using the BLOB domain?

If you cannot trust the service that returned the string, and you want to validate the returned XML then you should continue to use XMLNSC.
Back to top
View user's profile Send private message
DevNYC1
PostPosted: Sat Feb 02, 2013 2:16 pm    Post subject: Reply with quote

Apprentice

Joined: 22 Aug 2012
Posts: 32

kimbert wrote:
You should almost never call the single-parameter version of java.lang.String.getBytes(). You cannot guarantee the character encoding of the bytes that will be returned. It is much safer to specify an encoding using the two-parameter version
Thanks so much for this advice. The output Q's application expects the standard XML document. What is the appropriate encoding that I should specify in the getBytes method for the standard XML file? If that is relevant for the charset, the QA and Prod environments and MQs are on the AIX Unix and we develop on Windows XP Pro.
Quote:
I'm not convinced that you need to use XMLNSC at all. If you have been given a valid XML string then why not convert it to a BLOB ( in the encoding required by the consumer ) and then output that BLOB using the BLOB domain?
the consumer expects a valid XML document that can be validated against the XSD. I am inclined to use the XMLNSC if it works.
Back to top
View user's profile Send private message
kimbert
PostPosted: Sun Feb 03, 2013 12:58 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Quote:
The output Q's application expects the standard XML document. What is the appropriate encoding that I should specify in the getBytes method for the standard XML file?
This is something that you should either know, or should be able to look up in a specification document. I cannot possibly tell you what encoding you should use.
Does the XML that you are emitting begin with an XML declaration? If so, does it have an 'encoding' attribute? Because it if does, it would be a good idea to emit the XML in the encoding that the document claims to be using.
Quote:
the consumer expects a valid XML document that can be validated against the XSD. I am inclined to use the XMLNSC if it works.
Fair enough. If the source cannot be trusted then using XMLNSC is a good way to ensure that you emit well-formed XML that conforms to the XSD.
Back to top
View user's profile Send private message
rekarm01
PostPosted: Sun Feb 03, 2013 3:45 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

kimbert wrote:
You should almost never call the single-parameter version of java.lang.String.getBytes(). ... It is much safer to specify an encoding using the two-parameter version.

Good advice, but slightly off: You should almost never call the zero-parameter version of java.lang.String.getBytes(). ... It is much safer to specify a charset using the one-parameter version.

DevNYC1 wrote:
What is the appropriate encoding that I should specify in the getBytes method for the standard XML file?

That's to be decided between the sending and receiving applications, based upon whatever charsets they both support. In the absence of any other requirements, "UTF-8" works well for most applications. (Charset names are case-insensitive).

More importantly, the createElementAsLastChildFromBitstream() ccsid parameter must indicate the specified charset. For example, set ccsid=1208 for the "UTF-8" charset, set ccsid=819 for the "ISO-8859-1" charset, etc. Setting ccsid=0 defaults to the qmgr's ccsid, which may or may not be suitable; if the ccsid and charset don't match, the output message may be partially or completely garbled.

DevNYC1 wrote:
the consumer expects a valid XML document that can be validated against the XSD.

If the message flow is validating the output message against a schema, then either set the createElementAsLastChildFromBitstream() messageSet and messageType parameters to identify the schema and message element to validate against, or make sure to set these values elsewhere.
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 » Putting XML content on the output Q 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.