cancel
Showing results for 
Search instead for 
Did you mean: 

remove extension .pgp with out mapping after decryption

former_member355445
Participant
0 Kudos

HI all ,

i have a requirement , i need to decrypt the PGP file and place it in a local NFS directory, with out any mapping

Scenario: file (NFS) to file (NFS)

initally the file will be like BR_AXBT_123.csv.pgp , after decrypting the file , the file should be placed in the target with the file name BR_AXBT_123.csv

please help me on this, how to achieve this

Thanks,

Viany.

View Entire Topic
GauravKant
Contributor
0 Kudos

Hi Vinay,

As Manoj mentioned, there is no slandered way to achieve this without mapping. You can try with java mapping.

I had same requirement and implemented with java mapping.

Regards,

Gaurav

former_member355445
Participant
0 Kudos

can you please share the java mapping

GauravKant
Contributor
0 Kudos

Hi Vinay,

You can try with the below java code. It will work perfectly fine for your requirement.

create a jar file and import it to imported archive.

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"));  //or we can try .txt

  

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

  }

}

}

you can check the below blog as well for this requirement.

http://scn.sap.com/community/pi-and-soa-middleware/blog/2016/09/15/how-to-remove-extension-of-file-a...

Regards,

Gaurav

Ryan-Crosby
Active Contributor
0 Kudos

Hi Vinay,

I know Guarav already supplied a mapping but here is a different implementation that works for both adding and removing extensions in the case you later have to add an extension for a PGP encrypted file.  It makes use of two parameters for the mapping named MODE and VALUE.


import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.IOException;

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.MappingTrace;

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

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

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

public class DynamicConfigurationMap extends AbstractTransformation

{

  private MappingTrace trace;

  private static final DynamicConfigurationKey KEY_FILENAME =

  DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");

 

  @Override

  public void transform(TransformationInput in, TransformationOutput out)

            throws StreamTransformationException

  {

    // Initialize variables, objects for processing

    trace = getTrace();

    BufferedInputStream bis = new BufferedInputStream(in.getInputPayload().getInputStream());

    BufferedOutputStream bos = new BufferedOutputStream(out.getOutputPayload().getOutputStream());

   

    // access dynamic configuration

    DynamicConfiguration conf = in.getDynamicConfiguration();

    String filename = conf.get(DynamicConfigurationMap.KEY_FILENAME);

    if(filename == null || filename.compareTo("") == 0)

    {

      throw new StreamTransformationException("Invalid or missing filename");

    }

       

    // Getting java mapping input parameter for mode and value

    String mode = in.getInputParameters().getString("MODE");

    String value = in.getInputParameters().getString("VALUE");

    if(mode.compareToIgnoreCase("append") == 0)

      conf.put(DynamicConfigurationMap.KEY_FILENAME, filename + value);

    else if(mode.compareToIgnoreCase("remove") == 0)

      conf.put(DynamicConfigurationMap.KEY_FILENAME, filename.replaceFirst(value, ""));

    else

    {

      throw new StreamTransformationException("Unsupported mode: " + mode);

    }

   

    // Transfer input stream to output stream without modification

    int theInt;

    try {

      while((theInt = bis.read()) != -1)

      {

        bos.write(theInt);

      }

      bos.flush();

      bis.close();

      bos.close();

    } catch (IOException e) {

      throw new StreamTransformationException("Error transferring input stream to output stream", e);

    }

  }

}

Regards,

Ryan Crosby