cancel
Showing results for 
Search instead for 
Did you mean: 

how to get rid of the proxy extra namespace

Former Member
0 Kudos

We are having a proxy to xml scenario and for some reason, when I look at the payload in PI, I am getting a weird auto-generated namespace in one environment.

<nm:ProjOrganization xmlns:nm="http://kiewit.com/pi/TEL/FleetData/VisionLink"xmlns:prx="urn:sap.com:proxy:E1D:/1SAI/TASB2FB1DA7AC17B5DD0F0A:731">

In another environment, all I see is

<nm:ProjOrganization xmlns:nm="http://kiewit.com/pi/TEL/FleetData/VisionLink">

which is what I am expecting because there is a java code that runs through this mapping and it expects the namespace to be of this format.

Is there any way we can get rid of the extra namespace added ? Since we are not getting this extra namespace in a different environment, I am assuming its a configuration issue. Appreciate anybody's response.

Thanks for your help !

Accepted Solutions (0)

Answers (4)

Answers (4)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Venkata,

    Use this java mapping code before you process the XML in any of the mapping. This code will remove the namespace problem from root node of the source XML.

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.Attr;
import org.w3c.dom.Document;  
import org.w3c.dom.Element;  
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.sap.aii.mapping.api.AbstractTransformation;  
import com.sap.aii.mapping.api.TransformationInput;  
import com.sap.aii.mapping.api.TransformationOutput;  
import com.sap.aii.mapping.api.StreamTransformationException;  
public class DomParser1 extends AbstractTransformation {

    public void execute(InputStream in, OutputStream out) 
    throws StreamTransformationException {
        try
         {
         DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();  
         DocumentBuilder builderel=factory.newDocumentBuilder(); 
         Document docIn=builderel.parse(in);
         TransformerFactory tf=TransformerFactory.newInstance();
         Transformer transform=tf.newTransformer(); 
         Element root;
         Document docOut=builderel.newDocument();
         Element srcRootNode;
         srcRootNode=(Element) docIn.getDocumentElement();
         NamedNodeMap nm= srcRootNode.getAttributes();
         root=(Element) docOut.createElement(srcRootNode.getNodeName());
         for (int g = 0; g < nm.getLength(); g++) {
                   Attr attribute = (Attr)nm.item(g);
                   if(!attribute.getName().equals("xmlns:prx"))
                   {
                    root.setAttribute(attribute.getName(),attribute.getValue());
                   }
               }
         Node temp;
         NodeList childNodes=srcRootNode.getChildNodes();
         for(int i=0;childNodes!=null && i<childNodes.getLength();++i)
         {
          temp=docOut.importNode(childNodes.item(i),true);
          root.appendChild(temp);
         }
         docOut.appendChild(root);
         transform.transform(new DOMSource(docOut), new StreamResult(out));
         }
        catch(Exception e)
        {
         e.printStackTrace();
        }
    }
    
   
public void transform(TransformationInput arg0, TransformationOutput arg1)
   throws StreamTransformationException {
  // TODO Auto-generated method stub
   this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
 
}

}

Thus if the input xml is

<nm:ProjOrganization xmlns:nm="http://kiewit.com/pi/TEL/FleetData/VisionLink" xmlns:prx="urn:sap.com:proxy:E1D:/1SAI/TASB2FB1DA7AC17B5DD0F0A:731">

<a>hello</a>

</nm:ProjOrganization>

The output produced by this code will be

<?xml version="1.0" encoding="UTF-8"?>

<nm:ProjOrganization xmlns:nm="http://kiewit.com/pi/TEL/FleetData/VisionLink">

<a>hello</a>

</nm:ProjOrganization>

I have assumed you are working in PI 7.1 or above versions. The java mapping codes depends on PI version you are working on.

Hope this resolves your problem.

Regards

Anupam

udo_martens
Active Contributor
0 Kudos

Hi,

if the prefix "prx" is never used in any element any mapping would kill the namespace definition. If it is used then the corresponding elements have its own identity and you need to map them element by element, you can do that by message mapping or other mappings.

If the message structure is pretty complex and this is too much work then you could as alternative create a non parsing Java (or ABAP) mapping, what simply replaces:

  • The unwished namespace definition (xmlns..) with nothing
  • Each expression '<prx:' with '<nm:'
  • Each expression '</prx:' with '</nm:'

Regards,

Udo

Former Member
0 Kudos

You can use AF_Modules/XMLAnonymizerBean to achieve this. Use parameter anonymizer.acceptNamespaces ; value: http://kiewit.com/pi/TEL/FleetData/VisionLink nm

Thanks

Asif

rajasekhar_reddy14
Active Contributor
0 Kudos

can you check in message type,what is the XML name space entered, if you dont want XML name space then remove it from message type.

or

even you can handle this at mapping level to remove name space(JAVA Mapping/XSLT mapping)

search in scn

Former Member
0 Kudos

Getting rid of the namespace on the message type will remove the namespace entirely from the message, which is not what I want, that will again lead to code changes in another environment.

I do want the message to include the "actual namespace" without the extra namespace added to it.

Thanks for your help!

rajasekhar_reddy14
Active Contributor
0 Kudos

try using JAVA or XSLT mapping to remove , similar threads available in SCN..google it.