on 07-15-2008 3:35 PM
Hi,
We receive a string structure from a web service.
The string structure has an xml type format, that is all the tags and its content are in one line .
The WSDL file of the webservice defines its response structure as a string type.
How do i convert this string into proper XML structure (predefined by me in Integration repository).
OR how do i make XI understand this string as an XML structure for further processing.
Later i have to map this XML message type into IDoc.
Himani
Any other ideas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,,
try this in java-mapping:
public void execute (InputStream in, OutputStream out) {
try {
int buffer;
while ((buffer = in.read()) != -1) {
out.write(buffer);
} //end of while
out.flush();
} catch (Exception e) {
throw new StreamTransformationException(e.getMessage(), e);
}
}
regards mario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Kishore,
The problem is that the response string structure which come from web service has its content aranged in the form of an xml, but if i use graphical mapping and try to map the same into an XML structure,it does not map correctly.
For eg:
this is what i receive from Webservice.
<fromdate>250708</fromdate><todate>250708</todate>
This above is contained in a string data type structure say <response_webservice>
Now the message type that I have in XI-IR which resembles the actual XML format is like this
<MT_response>
<fromdate></fromdate>
<todate></todate>
</MT_response>.
In graphical mapping,
Source side message is <response_webservice> & target side message type is <MT_response>.
If i map <response_webservice> node to all the nodes of the target side message type.
This is the output-:
<MT_response>
fromdate <fromdate>250708</fromdate><todate>250708</todate>
todate <fromdate>250708</fromdate><todate>250708</todate>
</MT_response>
Whereas i want it that it should belike below after the mapping is done-:
<MT_response>
fromdate 250708
todate 250708
</MT_response>
Please help me,
Regards,
Himani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Himani ,
In graphical mapping,
Source side message is <response_webservice> & target side message type is <MT_response>.
If i map <response_webservice> node to all the nodes of the target side message type.
This is the output-:
<MT_response>
fromdate <fromdate>250708</fromdate><todate>250708</todate>
todate <fromdate>250708</fromdate><todate>250708</todate>
</MT_response>
It is clear that you are getting the reponse data captured in source message mapping structure <response_webservice>.
Please take the response message payload what ever ur getting from webservice and getting assigned to the source message. Test the message mapping using the test tab in Graphical mapping editor.
Please load the payload data into the source structure and see the data is getting assigned to the right xml node. while testing please check the queues in the mapping. Please let us know your observations.
If you face issue still then we need to use module processor program to parse the string into XML structure .
Regards,
Kishore
Dear Kishore,
The source structure in the mapping is the string structure received from webservice.
Thus for mapping I have only one node in the source structure which has as its content the XML tags and values between them in one line as a string.
I map this one node to 2 different nodes in the target side message structure that i have created.
Mapping is not able to differentiate between the tags and its values in the string structure and thus treat the tags as values.
Hence in result of the mapping, all nodes in the target structure have all the content of the string.(the tags and the values between them)
Can you please help with the XML parser as you suggested in you previous reply.
Thanks again for your constant help.
Himani
Hi Himani ,
It is clear now . It looks bit strange
To handle the reponse from webservice you have a message type . Please confirm the structure of the message type to handle webservice response -
<response_webservice> 1..1 cardinality --- which is a root node
<from_date> 1..1 or 0..1 cardinality
<to_date> 1..1 or 0..1 cardinality
when u get response string from webservice the value should get parsed and assigned to this structure. If your message structure is not the one i mentioned above you should get error or ur message structure should be different like this -
<response_webservice> 1..1 cardinality --- which is a root node and single node
<response_webservice>single string</response_webservice>
Please confirm the above understanding.
Are you using SOAP adapter for this webservice interface ?
Regards,
Kishore
Hi Himani ,
Also the message type to handle the webservice response is the same as the one provided in WSDL of the webservice.
It is
<response_webservice> 1...1 cardinality (root node)
<response_webservice> single string </response_webservice>
You can solve this in this way -
1) In Interface mapping use javamapping intially and parse the XML reponse message.
2) Define a message type with similar to the message structure after parsing.
3) Then use a message mapping which uses the new data structure after parsing the string as source and map it to the target structure.
Regards,
Kishore
Dear Kishore,
I dont know much Java,
My questions are-:
1. How do i parse an XML string in JAVA?(any sample code)
2.The target structure should be like that of the webservice response a string with only one node or that of the actual target structure i.e. a root node and multiple sub nodes (eg: <fromdate> & < todate> ).
Regards,
Himani
Hi Himani,
Please find the code for ur requirement -
String need to parse -<response_webservice><from_date>20080101</from_date><to_date>20080202</to_date></response_webservice>
Below mentioned code will convert it to -<MT_DATA><FROMDATE>20080202</FROMDATE><TODATE>20080101</TODATE></MT_DATA>
Create a Message type and map it like this using java mapping ( no need to use Graphical mapping).
Use MT_DATA as source and map it to your target structure .
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class XMLParser {
private Map param = null;
public static void main(String[] args) {
try {
XMLParser wdb = new XMLParser();
wdb.parse();
} catch (Exception e) {
e.printStackTrace();
}
}
public void setParameter(Map param) {
this.param = param;
if (param == null) {
this.param = new HashMap();
}
}
public void parse() {
String document = "<response_webservice><from_date>20080101</from_date><to_date>20080202</to_date></response_webservice>";
try {
Document sdoc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// parse using builder to get DOM representation of the XML file
sdoc = db.parse(new InputSource(new StringReader(document)));
Element docEle = sdoc.getDocumentElement();
NodeList nl = docEle.getElementsByTagName("from_date");
Element lstElmnt = (Element) nl.item(0);
NodeList nl1 = docEle.getElementsByTagName("to_date");
Element fstElmnt = (Element) nl1.item(0);
System.out.println(fstElmnt.getFirstChild().getNodeValue());
System.out.println(lstElmnt.getFirstChild().getNodeValue());
Document tdoc = db.newDocument();
Element structure = createElement("MT_DATA", null, tdoc);
tdoc.appendChild(structure);
Element statement = createElement("FROMDATE", fstElmnt.getFirstChild().getNodeValue(), tdoc);
structure.appendChild(statement);
Element statement2 = createElement("TODATE", lstElmnt.getFirstChild().getNodeValue(), tdoc);
structure.appendChild(statement2);
System.out.println("Struct is :::"+tdoc.getDocumentElement().toString());
} catch (DOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static Element createElement(String elementName, String content,
Document document) {
Element returnElement;
returnElement = document.createElement(elementName);
if (content != null) {
Text T = document.createTextNode(content);
returnElement.appendChild(T);
}
return returnElement;
}
static Element createElement(String elementName, String content,
String attributeName, String attributeValue, Document document) {
Element returnElement = createElement(elementName, content, document);
returnElement.setAttribute(attributeName, attributeValue);
return returnElement;
}
}
Regards,
Kishore
You can use XSLT mapping its very simple
eg
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:copy-of select="YourXMLStructure" />
</xsl:template>
</xsl:stylesheet>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Himani ,
We receive a string structure from a web service.
The string structure has an xml type format, that is all the tags and its content are in one line .
Please confirm that the string you are getting from webservice is a XML structure.
For example :<data><value1>100</value1><value2>101</value2></data>.
How do i convert this string into proper XML structure (predefined by me in Integration repository).
OR how do i make XI understand this string as an XML structure for further processing.
If it is a plain string then please let us know what is the string how you need to convert the structure.
Please let us know then we can direct where you need to use java mapping and how you can use .
regards,
kishore
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Himani,
How do i convert this string into proper XML structure (predefined by me in Integration repository).
OR how do i make XI understand this string as an XML structure for further processing.
If it is a plain string then please let us know what is the string how you need to convert the structure
Just want to know what is the type of the message of the string you are getting - I mean is it the string of type XML structure which i have mentioned in my previous post or it is a plain string which is inserted in the structure you have defined in repository object ( message type ).
Please let us know the structure of the string ur getting from webservice application & the message type you have defined in repository.
regards,
kishore
Dear Kishore,
The WSDL has this structure for the reponse from webservice-:
<xsd:element name="generateInvoiceInformationResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="generateInvoiceInformationReturn" type="xsd:string" nillable="true" /> </xsd:sequence>
</xsd:complexType>
</xsd:element>
The content of this return structure-:
<xmlns:ns0="http://nissan.com/ew"></ns0:MT_EXTN_WRNTY_SLS_NII_EXD xmlns:ns0="http://nissan.com/ew"><Session_Header><Queue_name>1234</Queue_name>etc..</session_header><Header><Document_header><Company>NESS</Company><Date>270708</Date>etc...<Line_item><value1>1</value1><value2>2</Value2></Line_item><Line_item><value1>3</value1><Value2>4</value2></line_item></Document_header></header><header><Document_header><Company>NESS</Company><Date>270708</Date>etc...<Line_item><value1>1</value1><value2>2</Value2></Line_item><Line_item><value1>3</value1><Value2>4</value2></line_item></Document_header></header></ns0:MT_EXTN_WRNTY_SLS_NII_EXD>.
The message type(MT_EXTN_WRNTY_SLS_NII_EXD ) that i have created in Repository to capture the above response-:
<MT_EXTN_WRNTY_SLS_NII_EXD>
<session_header>
-
-
</session_header>.
<Header>
<Document_Header>
-
-
<Line_Item>
-
-
</Line_item>
<Line_item>
-
-
</Line_item>
</document_header>
</header>
The header structure can replicate many times.
</MT_EXTN_WRNTY_SLS_NII_EXD>
I hope i clarify the situation.
Regards,
Himani
you said that your response comes inside a field which contains xml structure.
please open that response in notepad to check if you can see the structure some what like <Header>
if this is the case then you will have to write a java mapping to replace the occurences of < with "<" and > with ">"
Hi Himani ,
It is clear that you are getting the string in XML format from webservice. You just need to define a Message type which have defined in Integration repository .
I think you can get data mapped to the message type you have defined in IR.
Please let me know what is ur requirement
Regards,
kishore
Dear Kishore,
The problem is that the response string structure which come from web service has its content aranged in the form of an xml, but if i use graphical mapping and try to map the same into an XML structure,it does not map correctly.
For eg:
this is what i receive from Webservice.
<fromdate>250708</fromdate><todate>250708</todate>
This above is contained in a string data type structure say <response_webservice>
Now the message type that I have in XI-IR which resembles the actual XML format is like this
<MT_response>
<fromdate></fromdate>
<todate></todate>
</MT_response>.
In graphical mapping,
Source side message is <response_webservice> & target side message type is <MT_response>.
If i map <response_webservice> node to all the nodes of the target side message type.
This is the output-:
<MT_response>
fromdate <fromdate>250708</fromdate><todate>250708</todate>
todate <fromdate>250708</fromdate><todate>250708</todate>
</MT_response>
Whereas i want it that it should belike below after the mapping is done-:
<MT_response>
fromdate 250708
todate 250708
</MT_response>
Please help me,
Regards,
Himani
Hi Himani,
Please take the response message payload what ever ur getting from webservice and getting assigned to the source message. Test the message mapping using the test tab in Graphical mapping editor.
Please load the payload data into the source structure and see the data is getting assigned to the right xml node. while testing please check the queues in the mapping. Please let us know your observations.
I have asked you to check the above mentioned instructions in my previous post . I do understand the problem you mentioned but to isolate the problem please check the same and let us know so that we can
decide where do we need to insert our parsing logic to solve the issue.
Regards,
Kishpore
Hi Himani,
use JAVA-Mapping.
You can parse the InputStream. The parser will create a document (=JAVA-Object that is a XML document)
Than you can write the document to the output-stream.
Thats all
Regards Mario
Edited by: Mario Müller on Jul 15, 2008 10:41 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.