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.

Accepted Solutions (0)

Answers (4)

Answers (4)

GauravKant
Contributor
0 Kudos

Hi Vinay,

Hope, you got solution for this thread. If yes, please close the thread.

Thanks !

Regards,

Gaurav

anupam_ghosh2
Active Contributor
0 Kudos

Hi Vinay,

                First you need PGPDecryption module in sender file adapter as shown in this blog

This will decrypt the  the contents but will not change the filename. To change the filename you need either custom adapter module as shown in this blog http://scn.sap.com/docs/DOC-61728

or you need java mapping as shown below

  1. package com.javaMapping;   
  2. import java.io.BufferedReader;   
  3. import java.io.IOException;   
  4. import java.io.InputStream;   
  5. import java.io.InputStreamReader;   
  6. import java.io.Reader;   
  7. import java.io.UnsupportedEncodingException;   
  8. import java.text.SimpleDateFormat;   
  9. import java.util.Date;   
  10. import com.sap.aii.mapping.api.AbstractTransformation;   
  11. import com.sap.aii.mapping.api.DynamicConfiguration;   
  12. import com.sap.aii.mapping.api.DynamicConfigurationKey;   
  13. import com.sap.aii.mapping.api.StreamTransformationException;   
  14. import com.sap.aii.mapping.api.TransformationInput;   
  15. import com.sap.aii.mapping.api.TransformationOutput;   
  16. public class DynamicFileName_JavaMapping extends AbstractTransformation {   
  17.      private static final DynamicConfigurationKey KEY_FILENAME =   
  18.            DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");   
  19.     @Override   
  20.     public void transform(TransformationInput in, TransformationOutput out)   
  21.             throws StreamTransformationException {   
  22.         // TODO Auto-generated method stub   
  23.         
  24.         String newFileName = null;   
  25.         
  26.         Date date = new Date(); // get the current date   
  27.         SimpleDateFormat dateFormatter = new SimpleDateFormat ("yyyyMMdd-HHmmss-SSS"); // set the format for date   
  28.         String dfmt =  dateFormatter.format(date);   
  29.          
  30.         
  31.         
  32.           DynamicConfiguration conf = in.getDynamicConfiguration();   
  33.           String oldFileName = conf.get(KEY_FILENAME);                
  34.           
  35.           oldFileName = oldFileName.replaceAll(".pgp", "");   
  36.       
  37.           newFileName = oldFileName ; // the final filename   
  38.                     
  39.           String inData = convertStreamToString(in.getInputPayload().getInputStream());   
  40.           String outData = inData;   
  41.           try {   
  42.             out.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));   
  43.         } catch (UnsupportedEncodingException e) {   
  44.             // TODO Auto-generated catch block   
  45.             e.printStackTrace();   
  46.         } catch (IOException e) {   
  47.             // TODO Auto-generated catch block   
  48.             e.printStackTrace();   
  49.         }   
  50.           conf.put(KEY_FILENAME,newFileName);   
  51.     }   
  52.       public String convertStreamToString(InputStream in){   
  53.             StringBuffer sb = new StringBuffer();   
  54.             try   
  55.             {   
  56.             InputStreamReader isr = new InputStreamReader(in);   
  57.             Reader reader =   
  58.             new BufferedReader(isr);   
  59.             int ch;   
  60.             while((ch = in.read()) > -1) {   
  61.                 sb.append((char)ch);}   
  62.                 reader.close();   
  63.             }   
  64.             catch(Exception exception) { }   
  65.             return sb.toString();   
  66.             }   
  67. }   



ESR steps

-----------------

1) Create a Data Type

<DT_Structure>

  <Data>

  </Data>

</DT_Structure>

2) Create a Message Type, MT_Structure and refer DT_Structure.

3) Create an Outbound Service Interface, SI_Structure_Out and refer MT_Structure.

4) Create an Inbound Service Interface, SI_Structure_In and refer MT_Structure.

5) Create an Operational Mapping, OM_Structure. Refer SI_Structure_Out and SI_Structure_In.

6) 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.

ID steps

------------

1)  Create a File Sender channel. In ‘Advance’ tab, select ‘Use Adapter-Specific Message Attributes’ and ‘File Name’.

2)  In Receiver channel. In ‘Advance’ tab, select ‘Use Adapter-Specific Message Attributes’ and ‘File Name’.

3)   Create Sender and Receiver Communication Components. Create ‘Integrated Configuration’ Object to run scenario in Advance Adapter Engine

4) When input is non-XML, and you are using ICO. Delete SWCV from ICO object.

Regards

Anupam

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

manoj_khavatkopp
Active Contributor
0 Kudos

Vinay,

If you are using SAP's PGP modules well then there is no standard way to do this without mapping.

you can go for custom module

br,

Manoj

former_member355445
Participant
0 Kudos

this should be configured in the reciever channel , if yes i have done already but no luck

manoj_khavatkopp
Active Contributor
0 Kudos

this is custom module , have you downlded the ear file and deployed in your PI system ?