on 03-01-2012 4:57 PM
Hi everyone,
Iu2019 m working in a scenario SOAP to SOAP. Iu2019ve to convert a XML to String XML in message request, but on the other hand, in message response Iu2019ve convert the String XML to XML.
For the message request, I used u201Creturn as XMLu201D in a message mapping.
The problem is in the message response: I donu2019t know how to convert a String XML to XML.
Iu2019m using PI 7.1, and Iu2019m beginner dev. What do you recommend for this case?
The structure of the XML RESPONSE is:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:XML_SIEBEL_RESP_MT xmlns:ns1="http://example/test">
<STHEADER>
<IDCLIENTESRF/>
<FILLER1/>
<CODRETORNO/>
<NROJOURNALT/>
<NROJOURNALH/>
<OBS/>
</STHEADER>
<TRANSACTION>
<OPERACIONES>
<OPERACION>
<APELLIDO_NOMBRE/>
<TIPO_DOCUMENTO/>
<NRO_DOCUMENTO/>
<CODIGO_OPERACION/>
<COMENTARIO/>
<FORMA_PAGO/>
<NRO_BOLETO/>
<COTIZACION/>
<MONEDA_RECIBIDA/>
<MONTO_RECIBIDO/>
<MONEDA_ENTREGADA/>
<MONTO_ENTREGADO/>
</OPERACION>
</OPERACIONES>
<ERRORES>
<ERROR>
<COD_ERROR/>
<DESC_ERROR/>
</ERROR>
</ERRORES>
</TRANSACTION>
</ns1:XML_SIEBEL_RESP_MT>
>The problem is in the message response: I donu2019t know how to convert a String XML to XML.
You can do this with java mapping.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guys,
The example of mapping in message response for convert the String XML to XML is the following:
Xml source:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/"><CONSULTA_ST_RESP><STHEADER><IDCLIENTESRF /><FILLER1 /><CODRETORNO /><NROJOURNALT /><NROJOURNALH /><OBS /></STHEADER><TRANSACTION><ERRORES><ERROR><COD_ERROR>1005</COD_ERROR><DESC_ERROR>Length cannot be less than zero. Parameter name: length</DESC_ERROR></ERROR></ERRORES></TRANSACTION></CONSULTA_ST_RESP></string>
Xml target:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:CONSULTA_ST_RESP xmlns:ns1="http://example.com/pi">
<STHEADER>
<IDCLIENTESRF/>
<FILLER1/>
<CODRETORNO/>
<NROJOURNALT/>
<NROJOURNALH/>
<OBS/>
</STHEADER>
<TRANSACTION>
<ERRORES>
<ERROR>
<COD_ERROR>1005</COD_ERROR>
<DESC_ERROR>Length cannot be less than zero. Parameter name: length</DESC_ERROR>
</ERROR>
</ERRORES>
</TRANSACTION>
</ns1:CONSULTA_ST_RESP>
Cheers!
Edited by: ecruz2010 on Mar 5, 2012 5:00 PM
chk this code:
u can test this code locally
package com.test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class test extends AbstractTransformation{
public void transform(TransformationInput in,TransformationOutput out) throws StreamTransformationException
{
this.execute(in.getInputPayload().getInputStream(),
out.getOutputPayload().getOutputStream());
}
public void execute(InputStream in1, OutputStream out1)
throws StreamTransformationException
{
try
{
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db= dbf.newDocumentBuilder();
Document doc=db.parse(in1);
Document doc1=db.newDocument();
TransformerFactory tf=TransformerFactory.newInstance();
Transformer transform=tf.newTransformer();
Node p;
Element target=doc1.createElement("XML_SIEBEL_RESP_MT");
p=doc.getElementsByTagName("CONSULTA_ST_RESP").item(0);
NodeList Nodes = p.getChildNodes();
for(int i=0;i<Nodes.getLength();i++)
{
Node temp=doc1.importNode(Nodes.item(i),true);
target.appendChild(temp);
}
doc1.appendChild(target);
transform.transform(new DOMSource(doc1), new StreamResult(out1));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args) {
try{
test javaMapping =new test();
FileInputStream in=new FileInputStream("C:\\Documents and Settings\\amisriva\\Desktop\\test.xml");
FileOutputStream out=new FileOutputStream("C:\\Documents and Settings\\amisriva\\Desktop\\output.xml");
javaMapping.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Hi Guys!
The problem is finished. The code used is the following, Thank you a lot for your cooperation.
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class ConvertStringToXml extends AbstractTransformation {
@Override
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException
{
String inData = "";
try
{
getTrace().addInfo("JAVA Mapping Iniciado");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document docIn = db.parse(in.getInputPayload().getInputStream());
NodeList nodos = docIn.getChildNodes();
if (nodos.item(0) != null)
{
String xmlEmbebido = nodos.item(0).getTextContent();
InputSource source = new InputSource(new StringReader(xmlEmbebido));
Document docOut = db.parse(source);
inData = getStringFromDocument(docOut);
}
}
catch(Exception e)
{
getTrace().addInfo("Excepcion: " + e.getMessage());
}
try
{
out.getOutputPayload().getOutputStream().write(inData.getBytes("UTF-8"));
getTrace().addInfo("JAVA Mapping Finalizado");
}
catch(IOException e1)
{
getTrace().addInfo("IOException e1: " + e1.getMessage());
}
}
public String getStringFromDocument(Document doc)
{
try
{
DOMSource domSource = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
return writer.toString();
}
catch(TransformerException ex)
{
getTrace().addInfo("TransformerException e1: " + ex.getMessage());
return null;
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.