Skip to Content

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:

imageimage


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

imageInbound Message Type


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

Message Interface OutboundMessage Interface Inbound

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:
Importing .JAR Archive


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)

Interface Mapping1Interface Mapping2


Integration Directory

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

Sender Communication Channel

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. S. Gokhan Topcu
    I was really wondering how it would be possible to do this, I thought we could just pass the attacment to the proxy and get it as an XSTRING from the protocol. I wasn’t aware a change of encoding was necessary. Is it possible the other way around, from proxy-to-file adapter? How can we do it, as the receiver file adapter does not support attachments?

    Anyways, thank you for your solution on this important topic.

    Best regards,
    Gökhan

    (0) 
    1. Ryan Crosby Post author
      I know there is a way to do it with an attachment also, but I wasn’t sure how to grab the file name in that scenario and it was necessary for the scenario that I had.  As far as going from proxy to file adapter, do you mean going from an XSTRING to base64binary on the receiver adapter?  If that’s so, I can post the java mapping code that would make that conversion…
      (0) 
  2. Saravana Kumar Kuppusamy
    Ryan,

    How did you make sure the *.jpg file after being read by the sender file CC is converted to your outbound DataType ? Did you do any File content conversion in the sender FCC ? Appreciate your clarification on the same.

    Regards
    Saravana

    (0) 
    1. Ryan Crosby Post author
      Saravana,

      File content conversion wasn’t necessary because the appropriate conversion from base64binary to a hexadecimal string (moved to XSTRING variable in ABAP) is done within the java mapping.  Once the java mapping code is compiled as a .jar file in NWDS, you only need to import the .jar as an archive.  After the import you create the interface mapping between sender & receiver and use java mapping references the imported .jar archive.  Let me know if you need anymore clarification.

      Regards,
      Ryan

      (0) 

Leave a Reply