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 » Creating CData in a Java Task

Post new topic  Reply to topic
 Creating CData in a Java Task « View previous topic :: View next topic » 
Author Message
newtobroker
PostPosted: Mon Mar 15, 2010 5:11 pm    Post subject: Creating CData in a Java Task Reply with quote

Novice

Joined: 04 Feb 2010
Posts: 23

Hi,

In my Java class i have a code like this
Code:

MbElement outBody = mbOut.getOutputMbRoot().getLastChild();

         byte[] msgAsBytes = outBody.toBitstream(null, null, null, 0, 0, 0);
         String msgAsText = new String(msgAsBytes);


Now Im trying to insert the msgAsText in my XML as a new tag Payload2 with CDATA

Code:

         
clientRequest = "<![CDATA[" + msgAsText + "]]>";
         
outBody.getLastChild().createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Payload2", clientRequest);



where clientRequest is String.

When i do this way, its creating Payload2, but the Payload2 contains some junk data like &lt;&gt;&amp etc and so im not able to see that in my browser or neither im able to retrieve this Payload in my code using

Code:

InputRoot.XMLNSC.Envelope.(XMLNSC.CDataField)Payload2


Is this not the correct way to create a CDataField from java ?

Thanks,
C*
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Mar 15, 2010 5:34 pm    Post subject: Re: Creating CData in a Java Task Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

newtobroker wrote:
When i do this way, its creating Payload2, but the Payload2 contains some junk data like &lt;&gt;&amp etc


That's not junk - that's what XML looks like inside another XML document. Even inside a CData section.

newtobroker wrote:
im not able to see that in my browser or neither im able to retrieve this Payload in my code using

Code:

InputRoot.XMLNSC.Envelope.(XMLNSC.CDataField)Payload2


This does surprise me. Most browsers (and WMB) understand escaped characters. What happens when you use IE?

newtobroker wrote:
Is this not the correct way to create a CDataField from java ?


No idea. A Java expert will be along in a moment.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
newtobroker
PostPosted: Mon Mar 15, 2010 5:56 pm    Post subject: Reply with quote

Novice

Joined: 04 Feb 2010
Posts: 23

Vitor,

With IE when I open it says

Quote:

An invalid character was found in text content.


Thanks,
C*
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Mar 15, 2010 6:19 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

newtobroker wrote:
With IE when I open it says

Quote:

An invalid character was found in text content.



Well there's nothing invalid about &lt et al; they're just escaped characters.

I can only assume (and it's an assumption!) that bitstream resolves to isn't all it's cracked up to be and has nulls (or other characters outside the XML specification) in it.

Old advice is best advice - put a Trace node after your JCN and see what that field contains. Bet it's non-escaped non-XML.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
joebuckeye
PostPosted: Mon Mar 15, 2010 6:27 pm    Post subject: Re: Creating CData in a Java Task Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 365
Location: Columbus, OH

newtobroker wrote:
Now Im trying to insert the msgAsText in my XML as a new tag Payload2 with CDATA

Code:

         
clientRequest = "<![CDATA[" + msgAsText + "]]>";
         
outBody.getLastChild().createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Payload2", clientRequest);



where clientRequest is String.


You don't need to do the CDATA text yourself.

Drop your clientRequest line and just do this:

Code:
outBody.getLastChild().createElementAsLastChild(MbXMLNSC.CDATA_FIELD, "Payload2", msgAsText );


Assuming you are using the XMLNSC parser.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Mar 15, 2010 8:22 pm    Post subject: Reply with quote

Grand High Poobah

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

newtobroker wrote:

Code:

         MbElement outBody = mbOut.getOutputMbRoot().getLastChild();

         byte[] msgAsBytes = outBody.toBitstream(null, null, null, 0, 0, 0);
         String msgAsText = new String(msgAsBytes);


I'm not sure I quite follow you. So you change the body to a bitstream, but you do not specify a CCSID. You then transform back to Text and again do not specify a CCSID...(Unicode?)

Let's assume the byte[] msgAsBytes is in CCSID 1200 (i.e. default broker)
Now you run new String(msgAsBytes) and you leave it to Java to assume a default CCSID.... which I expect most certainly not to be 1200... but rather that of the platform Java is running on...

This is a recipe for disaster. You would be better off specifying explicitly the CCSID in both cases, and should probably use 1208 and "UTF-8" for common ground and reduced memory size (byte[])...

Just my $0.02 worth... take it with a grain of salt
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
newtobroker
PostPosted: Mon Mar 15, 2010 10:52 pm    Post subject: Reply with quote

Novice

Joined: 04 Feb 2010
Posts: 23

Thanks Joebuckeye, I was not aware of the CDATA_Field. I used it and its going ok now.

ftb_saper, I read in the ibm site that if we dont specifiy CCSID or leave it 0, broker takes the system's ccsid, in my case broker being on z/OS, i assume it will pick 500. However i will try giving the CCSID and let u know.

1) Meanwhile how do we set the CCSID at ??
Code:

new String(msgAsBytes)


2) I have a CData Within another CData. Whatz happening is that the CData thats inside the other, is coming with invalid characters like
Code:

|¢CDATA¢

Because of this I'm not able to see the XML in browser/IE
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Mar 16, 2010 7:30 am    Post subject: Reply with quote

Grand High Poobah

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

newtobroker wrote:
Thanks Joebuckeye, I was not aware of the CDATA_Field. I used it and its going ok now.

ftb_saper, I read in the ibm site that if we dont specifiy CCSID or leave it 0, broker takes the system's ccsid, in my case broker being on z/OS, i assume it will pick 500. However i will try giving the CCSID and let u know.

1) Meanwhile how do we set the CCSID at ??
Code:

new String(msgAsBytes)



java API wrote:
public String(byte[] bytes, String charsetName) throws UnsupportedEncodingException

Constructs a new String by decoding the specified array of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

The behavior of this constructor when the given bytes are not valid in the given charset is unspecified. The CharsetDecoder class should be used when more control over the decoding process is required.

Parameters:
bytes - the bytes to be decoded into characters
charsetName - the name of a supported charset
Throws:
UnsupportedEncodingException - If the named charset is not supported
Since:
JDK1.1

newtobroker wrote:

2) I have a CData Within another CData. What's happening is that the CData thats inside the other, is coming with invalid characters like
Code:

|¢CDATA¢

Because of this I'm not able to see the XML in browser/IE

AFAIK it is illegal in XML to have embedded [[CData]] sections.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
kimbert
PostPosted: Tue Mar 16, 2010 7:59 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Quote:
I have a CData Within another CData
That's illegal. You cannot nest CDATA sections.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Mar 16, 2010 8:01 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

fjb_saper wrote:
AFAIK it is illegal in XML to have embedded [[CData]] sections.



_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
newtobroker
PostPosted: Fri Mar 19, 2010 1:52 pm    Post subject: JCN issue with Property Reply with quote

Novice

Joined: 04 Feb 2010
Posts: 23

Hi,

Thanks team for the details, I have modified my design appropriately.

Thanks,
C*
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 » Creating CData in a Java Task
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.