Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Ryan-Crosby
Active Contributor
0 Kudos

The Goal


- To move a .jpg file from XI to an abap proxy in converted XSTRING format for processing.  It was important to pass the original file name to the receiver in this scenario.  ** Note ** Even though this scenario called for moving a .jpg file it is applicable to any binary file type.




The Solution


- The first requirement is to use Adapter-Specific Message Attributes to pass the filename to the receiver.  The second requirement is to use a Java Mapping compiled with NWDS to do the file conversion from base64binary encoding to the appropriate hexadecimal string.  Hexadecimal string format was necessary in the scenario because of the function module that was called in the ABAP Proxy.  A simple assignment from the string in the payload to an XSTRING variable within an ABAP Proxy gives you the file content, which can then be converted to any other necessary format using a function module.




Integration Repository


- The first step is to setup the outbound and inbound data types:






The next step is to setup the outbound and inbound message types:






Now we are ready to create our outbound and inbound Message Interfaces:



The fourth step is to generate a compiled .jar in NWDS for importing into the IR:
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformation;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Map;

public class MapFileStream
implements StreamTransformation
{
private byte[] bytes = new byte[4096];
private StringBuffer sb;
private String digits = "0123456789ABCDEF";
private Map map;
private static final DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
private static final DynamicConfigurationKey KEY_FILETYPE = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileType");

public void setParameter(Map param)
{
this.map = param;
}

public void execute(InputStream in, OutputStream out)
{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
DynamicConfiguration conf = (DynamicConfiguration)this.map.get(
"DynamicConfiguration");

String fileName = conf.get(KEY_FILENAME);
String fileType = conf.get(KEY_FILETYPE);

this.sb = new StringBuffer();
try
{
int len;
while ((len = in.read(this.bytes)) != -1)
{
int len;
for (int i = 0; i < len; i++)
{
int c = this.bytes[i] & 0xFF;
this.sb.append(this.digits.charAt(c >> 4));
this.sb.append(this.digits.charAt(c & 0xF));
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
String header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
header = header + "<ns:MT_FILE_IN filename=\"";
header = header + fileName;
header = header + "\" filetype=\"";
header = header + fileType;
header = header + "\" xmlns:ns=\"http://idexxi.com/sapxi/xiftp/anyfile\">";
bw.write(header);

bw.write(this.sb.toString());

String trailer = "</ns:MT_FILE_IN>";
bw.write(trailer);
bw.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}

Now the .jar file needs to be imported into IR:





The last step in the IR is to create our Interface Mapping: (It was not possible to get a full screenshot, so these are the key areas for the Interface Mapping)






Integration Directory


- One important piece for the sender communication channel is to enable Adapter-Specific Message Attributes and check the FileName attribute:



4 Comments
Labels in this area