cancel
Showing results for 
Search instead for 
Did you mean: 

Add Namespce and message type to incoming file

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member854360
Active Contributor
0 Kudos

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(); 
	} 
}

Answers (3)

Answers (3)

Former Member
0 Kudos

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,

Former Member
0 Kudos

This is what mark is mentioning about.

/people/sameer.shadab/blog/2005/12/05/how-to-remove-namespaces-in-mapping--xi

Regards,

---Satish

markangelo_dihiansan
Active Contributor
0 Kudos

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

rajasekhar_reddy14
Active Contributor
0 Kudos

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