Quantcast
Channel: Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 741

how to remove extension of file and put required extension using java mapping.

$
0
0

In this blog, i am going to tell you how to remove extension of a file using java mapping while placing it to folder.

Using this we can change the file extension in our required format while saving.

Eg: incoming file name : abc.csv.pgp

if we want .csv file or .txt file in our folder we can do it by using below java mapping.

 

Steps:

 

  • Create datatype, message type and service interface. (dummy )

DT.PNG

  • Create a jar file for the below java code.
  • create imported archives and import the jar file.

IA.PNG

  • create operation mapping.

OM.PNG

 

Code:

 

 

import java.io.InputStream;

import java.io.OutputStream;

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");

  String Fname=conf.get(key);

  int length=Fname.length();

  int index=length-8;

  String newName=Fname.substring(0,index);

   //Depending on your requirement edit this logic. Here, NewDynamicName + CurrentDate will be output file name.

     conf.put(key, (newName+".csv"));

  

 

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

  }

}

}

 

J_code.PNG

create the ID part using created SI and activate all the object.


Viewing all articles
Browse latest Browse all 741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>