Author |
Message
|
Halloween |
Posted: Tue Dec 08, 2015 7:14 am Post subject: Storing the XML into string |
|
|
Acolyte
Joined: 11 Mar 2015 Posts: 60
|
Hello guys,
I am triggering this message in SOAPUI
Code: |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:ProcessMessage>
<tem:strXmlMessage>
<![CDATA[<advance-person-data xmlns="http://www.bmw.com/BWMS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bmw.com/BWMS /ed/advance.xsd">
<header>
<sender>Siebel</sender>
<receiver>BWMS</receiver>
<case-id />
<crm-number>1530800001</crm-number>
<order-number>3756551</order-number>
<time-stamp>20151117091518</time-stamp>
</header>
<body>
<language>en</language>
<companions-number-of>0</companions-number-of>
<children-number-of>0</children-number-of>
<young-persons-number-of>0</young-persons-number-of>
</body>
</advance-person-data>
]]>
</tem:strXmlMessage>
</tem:ProcessMessage>
</soapenv:Body>
</soapenv:Envelope>
|
I am trying to store the
Code: |
<advance-person-data xmlns="http://www.bmw.com/BWMS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bmw.com/BWMS /ed/advance.xsd">
<header>
<sender>Siebel</sender>
<receiver>BWMS</receiver>
<case-id />
<crm-number>1530800001</crm-number>
<order-number>3756551</order-number>
<time-stamp>20151117091518</time-stamp>
</header>
<body>
<language>en</language>
<companions-number-of>0</companions-number-of>
<children-number-of>0</children-number-of>
<young-persons-number-of>0</young-persons-number-of>
</body>
</advance-person-data>
|
I am trying to store the above XML payload into string variable in JAva compute node
i am trying this code but does not work
byte [] msgAsBytes = inMessage.getRootElement().getLastChild().getLastChild().toBitstream(null,null,null,0,1208,0);
String msgAsText = new String(msgAsBytes);
getLastChild() is parsing to the element advanced-person-data which is the root of XML payload
And then it throws error when encounter the line and throws exception as
Text:CHARACTER:Unexpected XML type at this point in document.
Insert
Type:INTEGER:5
Text:CHARACTER:xmlns[http://www.bmw.com/BWMS]
Insert
Type:INTEGER:5
Text:CHARACTER:namespaceDeclType
I am new with Java and any help would be appreciated |
|
Back to top |
|
 |
Vitor |
Posted: Tue Dec 08, 2015 7:18 am Post subject: Re: Storing the XML into string |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Halloween wrote: |
I am new with Java and any help would be appreciated |
So why are you using Java rather than one of the other languages?
Halloween wrote: |
I am trying to store the above XML payload into string variable in JAva compute node |
Why? Is this part of this solution you were trying to put together?
As you were told in that thread, don't do this in code. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
timber |
Posted: Tue Dec 08, 2015 8:25 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Can you tell us what the message flow is supposed to do? We may be able to suggest a simple solution. |
|
Back to top |
|
 |
Halloween |
Posted: Tue Dec 08, 2015 9:01 am Post subject: |
|
|
Acolyte
Joined: 11 Mar 2015 Posts: 60
|
Hello guys,
The message flow will log this XML payload into database.
So, we fist have to store this as string variable and store into database
I asked DB admin to create Data Source name so i can use Compute and ESQL to do all this.
But they want me to use JDBC type 4 connection. SO i need to create configurable service and there is no other way other than using JAva compute node to interact with the database.
I would need to remove the namespace and store the whole XML payload as a string into string variable and then insert into the database.
Thanks |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Dec 08, 2015 9:27 am Post subject: Re: Storing the XML into string |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Halloween wrote: |
i am trying this code but does not work
byte [] msgAsBytes = inMessage.getRootElement().getLastChild().getLastChild().toBitstream(null,null,null,0,1208,0);
String msgAsText = new String(msgAsBytes);
getLastChild() is parsing to the element advanced-person-data which is the root of XML payload
And then it throws error when encounter the line and throws exception as
Text:CHARACTER:Unexpected XML type at this point in document.
Insert
Type:INTEGER:5
Text:CHARACTER:xmlns[http://www.bmw.com/BWMS]
Insert
Type:INTEGER:5
Text:CHARACTER:namespaceDeclType
I am new with Java and any help would be appreciated |
Don't do that. Your payload is in a CDATA section of your SOAP message.
So first you have to get to the SOAP:Body, then retrieve the tag 2 levels below. That should be your CDATA content.
Once you have the CDATA content, all that's left is putting that into the DB.
Code: |
String payload=inMessage.getRootElement().getLastChild().getLastChild().getLastChild().getLastChild().getStringValue(); |
or something like that...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
timber |
Posted: Tue Dec 08, 2015 9:42 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
btw, using the single-parameter String(byte[]) constructor:
Quote: |
new String(msgAsBytes); |
...is almost always a bug. I hope you can see why - if not, just look up the JavaDoc provided by Oracle.
Fortunately, you are about to throw away that code anyway. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Dec 08, 2015 9:59 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Halloween wrote: |
The message flow will log this XML payload into database.
So, we fist have to store this as string variable and store into database |
So we're back to your earlier thread here then?
Halloween wrote: |
But they want me to use JDBC type 4 connection. |
Odd choice.
Halloween wrote: |
there is no other way other than using JAva compute node to interact with the database. |
As you were told in the previous thread, that's not true. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Halloween |
Posted: Tue Dec 08, 2015 10:44 am Post subject: |
|
|
Acolyte
Joined: 11 Mar 2015 Posts: 60
|
Hello Victor,
Is there a way that i can use JDBC type 4 connection avoiding the use of configurable service and JCN.
I exacly don't know which way would that be.
Btw the requirement is simple, so JCN would not be a bad choice.
Thanks |
|
Back to top |
|
 |
Halloween |
Posted: Tue Dec 08, 2015 10:48 am Post subject: |
|
|
Acolyte
Joined: 11 Mar 2015 Posts: 60
|
Hello fjb_saper,
Yes i can come two level down. But i need the entire XML starting from <advanced person data> ...</advanced-person-data>
I already removed that Body and other issues.
I have clean XML with parent element <advanced person -data> ..</advanced person data> coming under XMLNSC as an input to JCN. I am trying to store this entire thing into string variable, so i can store it into database.
But it also has names spaces,i think thats the one causing an issue. Do you know if any how to remove the namespace in JCN from the input XML
Thanks |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Dec 08, 2015 10:52 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You need to confirm with the database team that you need to remove the namespace.
There are examples in this forum that discuss removing namespaces.
It's probably not what you need to do. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
Vitor |
Posted: Tue Dec 08, 2015 11:44 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Halloween wrote: |
Hello Victor |
I hope you read documentation better than you read names
Halloween wrote: |
Is there a way that i can use JDBC type 4 connection avoiding the use of configurable service and JCN. |
How about a Mapping node?
Halloween wrote: |
Btw the requirement is simple, so JCN would not be a bad choice. |
If it's that simple, a Mapping node would be a better choice. Especially for someone who keeps posting that he's new to Java, and claims not to know the language that well. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
sapana |
Posted: Wed Dec 09, 2015 10:53 pm Post subject: Re: Storing the XML into string |
|
|
Apprentice
Joined: 16 Apr 2007 Posts: 33 Location: Pune
|
fjb_saper wrote: |
Don't do that. Your payload is in a CDATA section of your SOAP message.
So first you have to get to the SOAP:Body, then retrieve the tag 2 levels below. That should be your CDATA content.
|
If you follow this, its pretty straightforward to extract the cDATA content as char. With esql, you could probably write on these lines -
Code: |
DECLARE cDataRef REFERENCE TO InputRoot.XMLNSC.soapenvNS:Envelope.soapenvNS:Body.tempuriNS:ProcessMessage.tempuriNS:strXmlMessage;
DECLARE whiteSpace CHARACTER CAST( X'090D0A20' AS CHAR CCSID 1208); --/* tab, cr, lf, space */
DECLARE cDataChar CHARACTER TRIM( whiteSpace FROM cDataRef);
|
If you have to use JDBC to connect to database, you can still write an external java procedure that is called from esql, and pass along the extracted string as parameter.
I am comfortable with esql, and whenever something comes up that has to be done in java, I generally follow this approach instead of using a JCN altogether. However, I am not sure if this is expensive in terms of processing costs, and would be curious to hear from others. |
|
Back to top |
|
 |
maurito |
Posted: Thu Dec 10, 2015 12:23 am Post subject: Re: Storing the XML into string |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
sapana wrote: |
I am comfortable with esql.
Code: |
DECLARE cDataRef REFERENCE TO InputRoot.XMLNSC.soapenvNS:Envelope.soapenvNS:Body.tempuriNS:ProcessMessage.tempuriNS:strXmlMessage;
DECLARE whiteSpace CHARACTER CAST( X'090D0A20' AS CHAR CCSID 1208); --/* tab, cr, lf, space */
DECLARE cDataChar CHARACTER TRIM( whiteSpace FROM cDataRef);
|
|
so, can you explain what you think the code you provided is doing ?
TRIM is a string manipulation function that manipulates all string data types (BIT, BLOB, and CHARACTER), and removes trailing and leading singletons from a string.
Singleton: A character encoded with one unit in variable-width encoding schemes for computer character sets |
|
Back to top |
|
 |
mgk |
Posted: Thu Dec 10, 2015 12:51 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
so, can you explain what you think the code you provided is doing ? |
His code is doing exactly what it looks like and is following this example of a "multi character singleton" from the docs:
Quote: |
http://www-01.ibm.com/support/knowledgecenter/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ak05270_.htm?lang=en |
.
Kind regards. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
maurito |
Posted: Thu Dec 10, 2015 1:09 am Post subject: |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
mgk wrote: |
Quote: |
so, can you explain what you think the code you provided is doing ? |
His code is doing exactly what it looks like and is following this example of a "multi character singleton" from the docs:
Quote: |
http://www-01.ibm.com/support/knowledgecenter/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ak05270_.htm?lang=en |
.
Kind regards. |
Ok, the code is good. I missed that example, but would it not be easier and more understandable to address the CDATA using something like
Code: |
InputRoot.SOAP.Body.ns:root.(XMLNSC.CDataField)Field1 ;
|
|
|
Back to top |
|
 |
|