xi binary conversion simplified: a step-by-step image file

13
XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 1 XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping Applies to: SAP Exchange Infrastructure (XI) 3.0 / Process Integration (PI) 7.0 This document describes Image / Binary file Conversion and mapping like JPG to PNG format using XI file Adapter and Java Mapping Program. This document also explains step by step working procedures for Image / Binary File to File scenario in XI including IR, ID and Java Mapping Code for binary conversion. This scenario also explains about the Business Service in ID and when or where to use Business Service instead of Business System. Hence, it applies to all Beginners to Expert XI Developers and Aspirants, especially for those who don’t have any scenario experience using Business Service in ID. Finally this document might be useful for those interested in preparing themselves for XI Certification or attending for some XI Interviews. Summary This document describes image/binary file conversion and mapping (such as JPG to PNG format) using the Exchange Infrastructure File Adapter and Java Mapping Program. This document also explains working procedures for the image/binary file-to-file scenario in XI including the Integration Repository (IR), Integration Directory (ID), and Java mapping code for binary conversion. This scenario also explains the Business Service in ID and when/where to use Business Service instead of Business System. Hence, it applies to beginners and expert XI developers, and to those who don't have any experience using Business Service in ID. This document also includes the source code of the generic Java mapping program which can used for any other binary/image conversion with minor type change information. Please see Java API and documentation library for further information. Author: Satish Jaiswal Company: HCL Technologies, Kolkata, India Created on: 25 June 2007 Author Bio Satish Jaiswal is working as a SAP NetWeaver Consultant for HCL Technologies, Kolkata.

Upload: others

Post on 12-Nov-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 1

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

Applies to: SAP Exchange Infrastructure (XI) 3.0 / Process Integration (PI) 7.0

This document describes Image / Binary file Conversion and mapping like JPG to PNG format using XI file Adapter and Java Mapping Program. This document also explains step by step working procedures for Image / Binary File to File scenario in XI including IR, ID and Java Mapping Code for binary conversion. This scenario also explains about the Business Service in ID and when or where to use Business Service instead of Business System. Hence, it applies to all Beginners to Expert XI Developers and Aspirants, especially for those who don’t have any scenario experience using Business Service in ID.

Finally this document might be useful for those interested in preparing themselves for XI Certification or attending for some XI Interviews.

Summary This document describes image/binary file conversion and mapping (such as JPG to PNG format) using the Exchange Infrastructure File Adapter and Java Mapping Program. This document also explains working procedures for the image/binary file-to-file scenario in XI including the Integration Repository (IR), Integration Directory (ID), and Java mapping code for binary conversion. This scenario also explains the Business Service in ID and when/where to use Business Service instead of Business System. Hence, it applies to beginners and expert XI developers, and to those who don't have any experience using Business Service in ID. This document also includes the source code of the generic Java mapping program which can used for any other binary/image conversion with minor type change information. Please see Java API and documentation library for further information. Author: Satish Jaiswal Company: HCL Technologies, Kolkata, India Created on: 25 June 2007

Author Bio Satish Jaiswal is working as a SAP NetWeaver Consultant for HCL Technologies, Kolkata.

Page 2: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 2

Table of Contents Applies to: ........................................................................................................................................ 1 Summary.......................................................................................................................................... 1 Author Bio ........................................................................................................................................ 1 Introduction ...................................................................................................................................... 2 Requirement Study and Solution Identification................................................................................ 2 Pre-Requisites ................................................................................................................................. 3

Knowledge Requirements: ........................................................................................................... 3 System Requirements:................................................................................................................. 3

Implementation - Build Solution....................................................................................................... 3 Step 1: Create & build jar / zip file for Java Mapping Program.................................................... 3 Step 2: Maintain IR (Integration Repository)................................................................................ 4 Step 3: Maintain ID (Integration Directory)................................................................................... 7

Testing the Scenario...................................................................................................................... 11 Some Error Tracking Tips:............................................................................................................. 12

Check whether Image Conversion has been done successfully: .............................................. 12 Understanding Outcomes (Tips).................................................................................................... 12 Related Content............................................................................................................................. 12 Disclaimer and Liability Notice....................................................................................................... 13

Introduction I had a requirement in one of our XI project to transfer some signature files from a source directory to SAP R/3 System and this Signature file needs to be converted in some other binary format like PNG, TIF etc. here the source was in JPG format and was not acceptable by R/3 system due to some constrains. Hence, I used the power of XI with File adapter and created one Generic Java Mapping Program to convert the source JPG file to PNG file as shown in this example. I have found lots of queries on how to do such a scenario without having any proper solution for implementation. Also I found most of the IX scenario implementation & example follows Business System in ID not Business Service. Hence I tried here to come up with a scenario with real life implementation for image conversion using java mapping in Cross Company Environment, where all relevant information for creating a Business System in SLD for Sender or Receiver is not available. Hope this document will help all XI professionals as a ready reference in real life situation in cross company environment. Happy Learning…

Requirement Study and Solution Identification We need to implement one scenario where XI will pick for a particular file binary type from source directory using file adapter (say JPG). The XI sever need to transform / convert the source binary / image file to another binary / image file (say PNG). Here, one java mapping program is required which will be responsible for the Image Type conversion from Source JPG to Target PNG format. After the conversion file adapter will store the newly converted file into the target directory. Assume that we don’t have sufficient information to create a Business System in SLD for Sender and Receiver System. Hence, I have used Business Service in ID like in any Cross Company Environment. So we don’t have to create any SLD Business System to implement such scenario.

Page 3: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 3

Pre-Requisites

Knowledge Requirements: • Basic knowledge of XI and how it works

• Nice to have one file to file scenario implementation experience. Please see the reference section if you want to go through one file to file scenario example

• Basic java knowledge and How to do java mapping in XI is preferred.

System Requirements: • JDK Version should be compatible with XI server JDK Runtime / Supported version

• Developer Access to Recipient XI System is required to create this scenario

Implementation - Build Solution

Step 1: Create and Build JAR/AIP file for Java Mapping Program Please create a java class like MapImage is created here. Use the below provided source code for image conversion from JPG to PNG. Compile your class and create the jar / zip file of the program. This Generic Java Mapping program which can use for any other binary / image conversion with minor type change information (Like “PNG” is used here). Please see java API and documentation library for further information. package com.satish.xi.map.image; import com.sap.aii.mapping.api.StreamTransformation; import java.awt.image.BufferedImage; import java.io.*; import java.util.Map; import javax.imageio.ImageIO; /** @author satishj */ public class MapImage implements StreamTransformation { private Map map; BufferedImage img; public void setParameter (Map param){ map = param; } public void execute (InputStream in, OutputStream out){ try { img = ImageIO.read(in); ImageIO.write(img, "PNG",out); }//End Of Try catch(Throwable t){ t.printStackTrace();

Page 4: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 4

} }//End Of Execute Function }

Step 2: Maintain IR (Integration Repository)

Create Namespace under your software components to use to create the objects in IR. Create Data Type for Sender as shown below. As in our scenario we will be exchanging binary

information. So, please select the base64Binary for Sender types.

Figure 2: Data Type Creation

Likewise Create Data Type for Receiver as shown above Create Message Type for the above created Data Type (Receiver and Sender both) as shown

below

Figure 3: Message Type Creation

Create Massage Interface (Sender and Receiver both) with the following options

Page 5: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 5

Figure 4: Message Interface Creation (Outbound / Sender)

Figure 5: Message Interface Creation (Inbound / Receiver)

Tip: as we are going to use java mapping program so, we will not create any Message Mapping Object.

Import Java Achieve to be used as mapping program. Select Imported Achieve under your name space -> New as shown below

Page 6: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 6

Figure A: Creating New archive object

Give name for Imported Achieve and click on create, the following screen will appear

Figure B: Importing Java Archive Program

Now select the jar / zip file you have created for your mapping program and save. The newly imported archive will appear in your object lists.

Goto change list and activate your imported archive. Now your java mapping program is ready to use.

Create Interface Mapping. Please select Source and Target Message Interface (created above).

Now select Mapping Program Type as Java Class (as we are using Java Mapping). Please select the main java class responsible for execute method for transformation as in our example MapImage.

Page 7: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 7

Figure 6: Interface Mapping Creation and Selecting Mapping Type

Figure 7: Selection Java Class responsible for mapping program (execute method)

Now GOTO Change List and activate all object created in IR

Step 3: Maintain ID (Integration Directory) Open Integration Directory Create One new Configuration Scenario and give the name for it.

Page 8: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 8

Now select the newly created Configuration Scenario - > Service Without Party-> Business service-> Right Click and create New. Give one Business Service Name

Figure 8: Create Business service (Sender / Receiver)

Now in Business Service window select the following (Inbound Interface and Communication Channel-File Adapter) for Receiver. Put all valid entry for file adapter as shown below. Please remember to change the Target Directory and File Name Scheme as per your available directory and required file name.

Figure 9: Create and configure Communication Channel Receiver

Page 9: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 9

Goto Sender Tab of sender Business service and select the following. Put all valid entry for file adapter as shown below. Please remember to change the Source Directory and File Name Scheme as per your available directory and required file name

Figure 10: Create and configure Communication Channel Sender

Now create Receiver Determination as shown below:

Figure 11: Create Receiver Determination

Now create Interface Determination as shown below:

Page 10: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 10

Figure 12: Create Interface Determination

Now create Sender Agreement as shown below. Please select Business Service and Sender Communication channel that we have created before

Figure 12: Create Sender Agreement

Now we have to create the Receiver Agreement as shown in figure below. Please select the Business Service that we have already created.

Page 11: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 11

Figure 12: Create Receiver Agreement

Now if you open the Configuration Scenario Object the all related objects created for the scenario will appeared as shown below:

Figure C: Final View of CS Object

All the objects created should be activated without any error.

Testing the Scenario Please put one <XXX>.JPG image file into your source directory which you have set into the

sender adapter The <XXX>.JPG file will be picked by the XI file adapter and java mapping program will convert

the file JPG file into PNG format and will put into the Target directory. So Goto your Target Directory as set in File Adapter Receiver and check for the image file into the target directory. Here in this example OUT.PNG has been set.

Page 12: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 12

Log in to Xi system and execute transaction SXMB_MONI and check for the XML messages. Use your source and destination system to filter messages; it should have flag as in picture below.

Check the destination directory, it should have file with the name specified. Check the file; it

should have same image as source but with the format PNG here as in example.

Some Error Tracking Tips:

Check whether Image Conversion has been done successfully 1. Check the source file size (JPG) and the Target file size (PNG). The size should be different. Also

please check the both file must be viewable by any image viewer application.

2. You may get the error in SXBM_MONI. This is because of incompatible class / JDK version (linkage error) used for java source file compilation. Please choose valid JDK to resolve this.

Understanding Outcomes (Tips) Tip 1: Java Mapping is the best choice while some critical conversion / transformation /

mapping is required to be done in XI Tip 2: In java Mapping Message Mapping Object creation is not required Tip 3: If we don’t have sufficient information to create a Business System in SLD for Sender or

Receiver then we can use Business Service in ID as shown in this example (Cross Company Environment)

Related Content Info on Business Services (SAP Help Site) Java Mapping (SAP Help Site)Java Mapping example - a must-read on Java mapping by Lionel and Nicolas

Page 13: XI Binary Conversion Simplified: A Step-by-Step Image File

XI Binary Conversion Simplified: A Step-by-Step Image File to Image File Mapping and Conversion Using Java Mapping

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 13

Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.