Skip to Content
0

File data not getting passed in Dynamic JAVA Mapping for pass-through scenario

Oct 12, 2017 at 05:10 AM

27

avatar image
Former Member

Hello everyone,

My requirement is to place files in different target directories based on the source filename. I followed the below blog.

https://blogs.sap.com/2014/10/13/step-by-step-dynamically-choosing-target-folder-using-java-mapping-with-sftp-adapter/

I am able to place the files in the correct folders. However, file data is missing. Not sure if it is getting missed in the mapping program. I have created dummy data types of type xsd:string for both sender and receiver as mentioned in the blog and built the other required ESR objects over them, and used the below java mapping code. Can anyone help on what can possibly be going wrong here?

import com.sap.aii.mapping.api.AbstractTrace; 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 ReadFileNameToDirName extends AbstractTransformation { public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException { AbstractTrace trace; trace = (AbstractTrace) getTrace(); //Capture trace object and write trace for debugging purpose. DynamicConfiguration DynConfig = arg0.getDynamicConfiguration(); //get the DynamicConfiguration Running Instance if( DynConfig == null){ throw new StreamTransformationException("Unable to load the Dynamic Configuration Object!"); } //Define the Keys that we want to read DynamicConfigurationKey Key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System", "FileName"); DynamicConfigurationKey Key2 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory"); String FileName = DynConfig.get(Key); //get method to read the key int p = FileName.lastIndexOf("_"); String Temp = FileName.substring(0, p); //Read Dynamic Configuration try{ DynConfig.put(Key2,FileName); }catch(Exception ee){ trace.addInfo("Unable to write the Dynamic Configuration!"); } } }

Thanks in advance,

Shanthi Priya

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Oct 12, 2017 at 01:00 PM
0

Hello everyone,

Thank you for your responses. I missed to pass the input payload to the output payload. Added the below lines. Now they are fine. Took the below link as reference.

https://wiki.scn.sap.com/wiki/display/XI/Dynamic+file+name+for+pass-through+scenario

InputStream inputstream = arg0.getInputPayload().getInputStream(); OutputStream outputstream = arg1.getOutputPayload().getOutputStream(); try{ byte[] b = new byte[inputstream.available()]; inputstream.read(b); outputstream.write(b); } catch (Exception exception) { getTrace().addDebugMessage(exception.getMessage()); throw new StreamTransformationException(exception.toString()); }

Thanks,

Shanthi Priya

Share
10 |10000 characters needed characters left characters exceeded
Manoj K Oct 12, 2017 at 05:45 AM
0

Hi Shanti,

Can you please clarify how if the filename and directory name associated with one example ?

In you code : String Temp = FileName.substring(0, p); what is p ?

and also this variable Temp is not used at all. So if you provide us more clarification it would be helpful to assist further.

Br,

Manoj

Share
10 |10000 characters needed characters left characters exceeded
Mark Dihiansan Oct 12, 2017 at 06:30 AM
0

Hi,

Maybe it is because you have not used these two parameters TransformationInput arg0, TransformationOutput arg1 that is why there is no output.

Regards,

Mark

Share
10 |10000 characters needed characters left characters exceeded