As we all know SAP PI is rapidly moving to Single Stack (i.e. JAVA Stack) hence we should also be capable of handling Simple Java Codes to write UDFs and Java Mappings.
We can create a Java Mapping for our custom requirement either using SAX or DOM Parser ( I will elaborate in my next blog). We will write a simple program which will handle '&' coming in source payload. As PI can't handle special characters of XML language.
Below steps will help you to create your first java mapping.
Steps for writing JAVA mapping :
Prerequisites: We need below Jar file to be imported in our Java Project for writing a mapping.
TO Download the jar please follow the below link:
https://sites.google.com/site/learnsappiblogspotcom/a-rapid-journey-to-sap-xi-pi/com.sap.xpi.ib.mapping.lib.zip?attredirects=0&d=1
Below are the step need to be followed while creating the JAVA mapping.
Download and install the eclipse (its freeware).
Step1: Create a JAVA Project in Eclipse

Note: If you are using PI version 7.30 then select JRE as J2SE-1.5 from dropdown list.

Step2: Create a package com.test

Step3: Add External mapping jar downloaded from above link.
Right Click on Project --> Build Path --> Configure Build Path
Goto Libraries tab and Click on Add External Jar

Then browse your jar location and add the Jar to library. Then you can see the jar in your library.

Step4: Now create a class file name as Handling_Ampersand in package com.test as below


Step5 : Now write the below code in your class.
}
Step 6: Now create a jar for this through below steps.
Right click on your Project -> Export -> JAVA (Expand the tree) -> JAR file

Click on Next.
Step 7: Then browse the path to save the jar and select the below checkboxes and click Finish button.

Step 8: After this we can use this jar as external Archive in our SAP PI ESR in Operation mapping as JAVA class. This will handle the ampersand coming in our payload.
We can create a Java Mapping for our custom requirement either using SAX or DOM Parser ( I will elaborate in my next blog). We will write a simple program which will handle '&' coming in source payload. As PI can't handle special characters of XML language.
Below steps will help you to create your first java mapping.
Steps for writing JAVA mapping :
Prerequisites: We need below Jar file to be imported in our Java Project for writing a mapping.
TO Download the jar please follow the below link:
https://sites.google.com/site/learnsappiblogspotcom/a-rapid-journey-to-sap-xi-pi/com.sap.xpi.ib.mapping.lib.zip?attredirects=0&d=1
Below are the step need to be followed while creating the JAVA mapping.
Download and install the eclipse (its freeware).
Step1: Create a JAVA Project in Eclipse
Note: If you are using PI version 7.30 then select JRE as J2SE-1.5 from dropdown list.
Step2: Create a package com.test
Step3: Add External mapping jar downloaded from above link.
Right Click on Project --> Build Path --> Configure Build Path
Goto Libraries tab and Click on Add External Jar
Then browse your jar location and add the Jar to library. Then you can see the jar in your library.
Step4: Now create a class file name as Handling_Ampersand in package com.test as below
Step5 : Now write the below code in your class.
package com.test;
import java.io.InputStream;
import java.io.OutputStream;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class Handling_Ampersand extends AbstractTransformation
{
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException
{
try
{
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
byte[] b = new byte[inputstream.available()];
inputstream.read(b);
String inputContent = new String(b);
inputContent = inputContent.replaceAll("&", "&;");
outputstream.write(inputContent);
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
Step 6: Now create a jar for this through below steps.
Right click on your Project -> Export -> JAVA (Expand the tree) -> JAR file
Click on Next.
Step 7: Then browse the path to save the jar and select the below checkboxes and click Finish button.
Step 8: After this we can use this jar as external Archive in our SAP PI ESR in Operation mapping as JAVA class. This will handle the ampersand coming in our payload.
Thanks for sharing this Information.
ReplyDeletesap pi/po online training
sap pi/po online training in ameerpet