Problem:

A lot of customers have a 3-tier on-premise landscape in place which they like to integrate with C4C. This also implies the development system DEV in which they are implementing and testing new features. The tricky thing about integrating DEV is that all PDI extension fields switch their namespace once the patch solution has been created. Technically the fields with the original namespace are still there, but not active any more since the patch namespace has now been set to active. This implies that all mappings created for those fields are not valid anymore. This article describes a solution how to handle this namespace switch without redundantly redefining the mapping for all extension fields.

Note: The so-called “namespace switch problem” only occurs in the DEV tenant, more precisely the tenant in which the original PDI solution resides. The namespace of subsequent systems (i.e. QAS, PRD) does not change if you follow the standard deployment process in PDI. In those systems the patch solution is merged into the existing solution which has a constant namespace.


Solution:


The mapping is defined once based on the original solution A. This mapping will then work out of the box in the following systems:

  • DEV (as soon as patch solution has not yet been created)
  • All systems <> DEV (e.g. QAS, PRD)

Once the patch solution B is created in DEV, the mapping will not work anymore in this system. The idea is now to still make use of the original mapping and to switch the namespace for all PDI extension fields from A to B in the DEV system as part of an XML transformation. This can be done by adding some Java coding as second step after the message mapping step (C4C inbound) resp. first step before the message mapping step (C4C outbound) in the operation mapping:

Operation_Mapping.png

The following includes a sample Java coding snippet which can be used to perform the namespace switch:

package sap.pi.java.util.switchNameSpace;

import java.io.BufferedReader;

import java.io.ByteArrayInputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import com.sap.aii.mapping.api.AbstractTransformation;

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;

public class SwitchNameSpace extends AbstractTransformation {

                public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {

       

       

                                String _originialNS = arg0.getInputParameters().getString(“ORIGINALNS”);

                                String _extendedNS = arg0.getInputParameters().getString(“EXTENDEDNS”);

                                String inData = convertStreamToString(arg0.getInputPayload().getInputStream());

                                String outData = inData.replaceAll(_originialNS,_extendedNS );

                                try

                                {

                                                arg1.getOutputPayload().getOutputStream().write(outData.getBytes(“UTF-8”));

                                }

                                catch(Exception exception1) { }

                }

       

                public String convertStreamToString(InputStream in) {

                                StringBuffer sb = new StringBuffer();

                                try {

                                                BufferedReader reader = new BufferedReader(new InputStreamReader(in, “UTF-8”));                               

                                                String line;

                                                while ((line = reader.readLine()) != null) {

                                                                sb.append(line);

                                                                sb.append(“\n”);

                                                       

                                                }

                                                reader.close();

                                } catch (Exception exception) {

                                }

                                return sb.toString();

                }

       

       

                public static void main(String[] args) {

       

                       

                }

       

}


Given that the operation mapping is a transportable designtime entity and the namespace switch should only happen in DEV system, best practice is to parameterize the Java method so that source and target namespace can be handed over as part of the runtime configuration (e.g. in the Interface Determination). If that is done, then the source namespace needs to be set to the namespace of the original solution, the target namespace on the other side to the namespace of the patch solution in DEV. In all other systems source and target namespace need to be the same, i.e. the namespace of the original solution:


Interface_Determination.png

Note: The JAVA class performing the namespace switch has been incorporated into the pre-delivered PI content for CRM integration (CRMCOD01 IC 700) and ERP integration (COD_ERP_INT_IC 6.00). Details how to use this class can be found in SAP note 2233214.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply