cancel
Showing results for 
Search instead for 
Did you mean: 

Need to config the fill name at runtime from server

Former Member
0 Kudos

Hi All,

Need to config the fill name at runtime from server

for ex: on server there is file  i.e ABC.txt nd in output it would be ABC(data till .)

i/p: ABC.txt

o/p: ABC

if anyone know about it then let me know

Thanks in advance.!!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks to all for providing possbile solutions,

I have wrote the UDF for it and in channel in ASMA property i copy the file directory,

used UDF as below,

String SourceFileName = new String("");

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

SourceFileName = conf.get(key);

  1. conf.put(key,SourceFileName);

return SourceFileName;

Thanks,

Ajay

Answers (3)

Answers (3)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ajay,

               Please use this java mapping in ESR after all graphical mappings in the same Operation mapping.


package com.javaMapping; 

import java.io.BufferedReader; 

import java.io.IOException; 

import java.io.InputStream; 

import java.io.InputStreamReader; 

import java.io.Reader; 

import java.io.UnsupportedEncodingException; 

import java.text.SimpleDateFormat; 

import java.util.Date; 

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

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

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

public class DynamicFileName_JavaMapping extends AbstractTransformation { 

     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 { 

        // TODO Auto-generated method stub 

      

        String newFileName = null; 

      

      

      

      

          DynamicConfiguration conf = in.getDynamicConfiguration(); 

          String oldFileName = conf.get(KEY_FILENAME);              

        

          newFileName = oldFileName.replaceAll(".txt", ""); 

    

          

                  

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

          String outData = inData; 

          try { 

            out.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8")); 

        } catch (UnsupportedEncodingException e) { 

            // TODO Auto-generated catch block 

            e.printStackTrace(); 

        } catch (IOException e) { 

            // TODO Auto-generated catch block 

            e.printStackTrace(); 

        } 

          conf.put(KEY_FILENAME,newFileName); 

    } 

      public String convertStreamToString(InputStream in){ 

            StringBuffer sb = new StringBuffer(); 

            try 

            { 

            InputStreamReader isr = new InputStreamReader(in); 

            Reader reader = 

            new BufferedReader(isr); 

            int ch; 

            while((ch = in.read()) > -1) { 

                sb.append((char)ch);} 

                reader.close(); 

            } 

            catch(Exception exception) { } 

            return sb.toString(); 

            } 

Please tick on ASMA filename in sender and receiver file adapter.

Regards

Anupam

iaki_vila
Active Contributor
0 Kudos

Hi Ajay,

If you are not using ESR objects, you can deploy Eng Swee Yeoh module bean: DynamicAttributeChangeBean - The no-mapping sol... | SCN

Regards.

Former Member
0 Kudos

i m using ESR object

former_member182412
Active Contributor
0 Kudos

Hi Ajay

If you want file name in the receiver file adapter then use dynamic configuration in the mapping if you're u have mapping

Regards

Praveen

Former Member
0 Kudos

yes i have mapping but i have to write udf at recvr side field for that there is no field from sender side.

so without sender field how i pick up the file  at recever side

former_member187339
Active Contributor
0 Kudos

Hi Ajay,

Check the first UDF in the following link

To invoke the UDF, do a mapping like this

<source message type or Header Node in Source XML Structure> --- UDF --- <target message type or Header Node in Target XML Structue>

Make sure Dynamic Configuration (Filename) is selected in both source and target channel.

Regards

Suraj