Skip to end of metadata
Go to start of metadata


Applies to scenario:

Need to manipulate file name at target for Pass-through (no mapping) interface. Pass-through payload can be

  • PDF, excel, word, zip, flat file, image – message structures cannot be defined.
  • XML – for which no transformation is required.

Summary

Need to manipulate file name at target for Pass-through (no mapping) interface. Variable substitution (for Dynamic File Name), cannot be used as Input payload is not / cannot be read, as it is pass-through interface. Reader must know to perform File to File scenario and to implement Java Mapping.
 

Author:  

   
Company:     Infosys Limited.
Created on:    07/06/2011
Author(s) Bio
I am SAP Certified Development Associate - Process Integration with SAP Netweaver (PI 7.1). I have about 5 year experience of SAP XI/PI implementation and support. I am also, Sun Certified Programmer for the Java Platform, Standard Edition 6. I have good understanding of XML, XSLT, SOAP, WSDL, ABAP. I am an active member in SAP SND.

Solution

Using Java Mapping
a. output file name will be manipulated using DynamicConfiguration.
b. input payload will be copied to output payload, as it is.


Steps in ESR

  • Create a Data Type (some dummy structure). E.g.,
    <DT_Structure>
      <Child>
         <GrandChild1 />
         <GrandChild2 />
      </Child>
    </DT_Structure>
  • Create a Message Type, MT_Structure and refer DT_Structure.
  • Create an Outbound Service Interface, SI_Structure_Out and refer MT_Structure.
  • Create an Inbound Service Interface, SI_Structure_In and refer MT_Structure.
  • Create an Operational Mapping, OM_Structure. Refer SI_Structure_Out and SI_Structure_In.
  • Create a zip or jar file of below Java Mapping ‘DynamicFileName_JavaMapping’ (compiled). Import it into ESR as imported archive. Refer this Java Mapping in OM_Structure.

Steps in Integration Directory

  • Create a File Sender channel. In ‘Advance’ tab, select ‘Use Adapter-Specific Message Attributes’ and ‘File Name’.
  • Create a File Receiver channel. In ‘Advance’ tab, select ‘Use Adapter-Specific Message Attributes’ and ‘File Name’.
  • Create Sender and Receiver Communication Components. Create ‘Integrated Configuration’ Object to run scenario in Advance Adapter Engine OR Create Sender Agreement, Receiver Determination, Interface Determination (should refer OM_Structure), and Receiver Agreement to run in Integration Engine. 

This is an example of a Java Mapping Code sample:


Java Mapping Code
package com.javaMapping;

import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;

public class DynamicFileName_JavaMapping extends AbstractTransformation
{
 public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
                                                                        throws StreamTransformationException
 {
  try
  {
   InputStream inputstream = transformationInput.getInputPayload().getInputStream();
   OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

   Map mapParameters = (Map) transformationInput.getInputHeader().getAll();

   // a) Set Output File name
   mapParameters.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/Dynamic",
                                                         StreamTransformationConstants.DYNAMIC_CONFIGURATION), "");
   DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
   DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");

   //Depending on your requirement edit this logic. Here, NewDynamicName + CurrentDate will be output file name.
   DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
   conf.put(key, ("NewDynamicName_" + dateFormat.format(new Date())) + ".pdf");

   // b) Just copy Input file content to Output file content
   byte[] b = new byte[inputstream.available()];
   inputstream.read(b);
   outputstream.write(b);
  } catch (Exception exception)
  {
   getTrace().addDebugMessage(exception.getMessage());
   throw new StreamTransformationException(exception.toString());
  }
 }
}

For above code

 Input File Name: xi_input_DynamicFileName.pdf
 Output File Name: NewDynamicName_201107.pdf

5 Comments

  1. Steps in Integration Directory

    When input is non-XML, and you are using ICO. Delete SWCV from ICO object. More info http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/08/15/reading-binary-file-using-ico 

  2. Hi Raghu,

    i am trying to implement this code for changing file extension. but  getting error in code as i have imported sap jar file also for java mapping.

    Pls suggest.

    Regards,

    Gaurav

  3. Thanks Raghu !! Nice blog (smile)

    Issue resolved with the same above code. i have missed com.sap.xpi.ib.mapping.lib.jar file to import. After import it is working fine.

  4. Very useful post sir . Thanks a lot.