on 07-17-2011 3:47 PM
Hi Experts,
I have a file to Idoc scenario where my input file comes without a name space message type like this
<?xml version="1.0" encoding="UTF-8"?>
<Header>
<Field>
<FieldSeparator/>
<EncodingCharacters/>
<SendingApplication/>
</Field>
In PI I have created the data type in a particular namespace and the message type, so when this file is polled for at the source folder, it fails in the moni
any idea on how to proceed ??
Regards,
Teja
Hi Ravi,
You can do it with a simple JAVA mapping.
You need to add this Java Mapping in Operation mapping Before your actual graphical mapping.
INPUT:
<?xml version="1.0" encoding="UTF-8"?>
<Header>
<Field>
<FieldSeparator/>
<EncodingCharacters/>
<SendingApplication/>
</Field>
</Header>
OUTPUT:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MessageType xmlns:ns0="urn:sap.com:test:mapping:java">
<Header>
<Field>
<FieldSeparator/>
<EncodingCharacters/>
<SendingApplication/>
</Field>
</Header>
</ns0:MessageType>
Please find the Java code.
package addMessageTypeAndNamespace;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
//1. AbstractTransformation class is imported.
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.InputAttachments;
import com.sap.aii.mapping.api.InputParameters;
import com.sap.aii.mapping.api.InputPayload;
import com.sap.aii.mapping.api.OutputAttachments;
import com.sap.aii.mapping.api.OutputHeader;
import com.sap.aii.mapping.api.OutputParameters;
import com.sap.aii.mapping.api.OutputPayload;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.api.InputHeader;
public class addMessageTypeAndNamespace extends AbstractTransformation{
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException
{
try {
String strinput=readInputStreamAsString(arg0.getInputPayload().getInputStream());
String withoutXmlDeclaration=strinput.substring(39, strinput.length());
String XmlDeclaration=strinput.substring(0, 38);
strinput=XmlDeclaration+"<ns0:MessageType xmlns:ns0=\"urn:sap.com:test:mapping:java\">"+withoutXmlDeclaration+"</ns0:MessageType>";
arg1.getOutputPayload().getOutputStream().write(strinput.getBytes("UTF-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (NullPointerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
getTrace().addInfo(e.getMessage());
}
}
public static String readInputStreamAsString(InputStream in) throws IOException
{
BufferedInputStream bis = new BufferedInputStream(in);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1)
{
byte b = (byte)result;
buf.write(b);
result = bis.read();
}
return buf.toString();
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Teja,
In the source Message Type, you have to Provide the XML Namespace inorder to get the Namespace in the Payload.
Hope this helps....
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
In PI I have created the data type in a particular namespace and the message type, so when this file is polled for at the source folder, it fails in the moni
You can remove the namespace of your message type by opening your source message type and deleting the entry in XML namespace.
Hope this helps,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You really want name space and message type name in payload??
if you dont want then take your source XSD and import in to PI(dont create data type) ,it will work,
if you want name space then take payload in moni and test your mapping and correct the mapping error accordingly
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.