on 08-25-2010 6:20 PM
Hello All,
We have a requirement which involves taking in an input PDF file and mapping it to a message type with binary attribute and sending it to an R3 system.
Can anyone please detail the steps or point us to the correct documents for setting up the scenario.
The scenario is file to Proxy adapter. The part which we need assitance is pulling up the input pdf and mapping it to binary field.
Thanks.
Kiran
hi,
You can create an adapter module for same by using itext libray:
How to write PDF file:
/people/shabarish.vijayakumar/blog/2009/05/17/trouble-writing-out-a-pdf-in-xipi
Refer to links below for same:
How to create an adapter module:
https://wiki.sdn.sap.com/wiki/display/XI/XIlibrariesfor+development
Adjust your PI 7.0 Adapter Modules for PI 7.1 in 15 minutes
/people/stefan.grube/blog/2008/12/11/adjust-your-pi-70-adapter-modules-for-pi-71-in-15-minutes
JavaDoc:
http://help.sap.com/javadocs/pi/SP3/xpi/index.html
Sample for reading an PDF file will look like:
// Create a PdfReader instance
PdfReader r = PdfReader.fileReader("sample_doc1.pdf");
// Create a PdfDocument instance with the reader
PdfDocument d = new PdfDocument(r);
// Get page count and display on console
System.out.println( -- in actual code store it to string/bytestream and add it to message payload.
"Number of pages in sample_doc1.pdf is " +
d.getPageCount());
// Close all I/O streams associated with the PDF reader
r.dispose();
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello All,
The sample example being posted is for the creating a pdf on the receiver side. We want to read a pdf assign it to an attribute on the receiver side and send the file across.
I found the following example which comes close to our requirement but can anyone tell us the sender and receiver message types to be used for the scenario.
https://wiki.sdn.sap.com/wiki/display/XI/HowtoSendBinaryDatatoRFCfromXI%28or%29PI
Thanks.
Kiran
Thanks Sarvesh for your response. Can you please explain how can I go about the mapping in the ESR what should be my source message ?
As far as I know my Target message will be 2 elements one base64" and one file name. But how about the source message and which code I can use to read the pdf ?
Thanks.
Kiran
> But how about the source message and which code I can use to read the pdf ?
Go through this blog, which explains how to read the pdf file..
/people/sap.user72/blog/2005/07/31/xi-read-data-from-pdf-file-in-sender-adapter
Update:- I am not realy sure how much above blog will help you, but the basic idea is that we have to convert the PDF into binary (I am not sure how to do that in XI ) may be by using java mapping (if possible) otherwise you can simply use the above blog (which converts the pdf file into xml data) and sent the xml data to inbound proxy where you take this xml data into one string and convert it into Binary (there are function moudules) and then just do rest of the things..
>The scenario is file to Proxy adapter.
Best option is to send this as an attachment and handle it accordingly in the ABAP/Java Proxy on the receiver side..
otherwise if your proxy logic is already developed , then just modify the java mapping snippet (Java Mapping Snippet Code section) @[How to Send Binary Data to RFC from XI(or)PI |https://wiki.sdn.sap.com/wiki/display/XI/HowtoSendBinaryDatatoRFCfromXI%28or%29PI]
Remove dynamic configuration code....in that snippet
>For the mapping to my inbound I will research on Apache Commons (org.apache.commons.codec.binary.Base64) which I can use in my udf.
SAP has provided this com.sap.aii.utilxi.base64.api.*;
aii_utilxi_misc.jar (PATH: /usr/sap/<SID>/DVEBMGS<nr>/j2ee/cluster/server0/bin/ext/com.sap.xi.util.misc)
Edited by: Praveen Gujjeti on Aug 26, 2010 10:07 PM
Thanks Praveen,Mayank,Sarvesh and Andreas for your valuable help with the issue.
I was able to successfully pick up the binary PDF file from a file server , encode it using Base 64 and post it to R3.
I used the following code snippet and added the mentioned jar files to create a new jar file which was used as java mapping in the operation mapping.
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.*;
import com.sap.aii.utilxi.base64.api.*;
import java.io.*;
import java.util.*;
public class Base64EncodingXIStandard implements StreamTransformation{
String fileNameFromFileAdapterASMA;
private Map param;
public void setParameter (Map map)
{
param = map;
if (param == null)
{
param = new HashMap();
}
}
public static void main(String args[])
{
Base64EncodingXIStandard con = new Base64EncodingXIStandard();
try
{
InputStream is = new FileInputStream(args[0]);
OutputStream os = new FileOutputStream(args[1]);
con.execute(is, os);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void execute(InputStream inputstream, OutputStream outputstream)
{
DynamicConfiguration conf = (DynamicConfiguration) param.get("DynamicConfiguration");
DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
fileNameFromFileAdapterASMA = conf.get(KEY_FILENAME);
if (fileNameFromFileAdapterASMA == null)
{
fileNameFromFileAdapterASMA = "ToBase64.txt";
}
try
{
while ((len = inputstream.read(buffer)) > 0)
baos.write(buffer, 0, len);
str = Base64.encode(baos.toByteArray()); //buffer);
outputstream.write("<?xml version=\"1.0\" encoding=\"utf-8\"?><ROOT>".getBytes());
outputstream.write(("<FILENAME>" + fileNameFromFileAdapterASMA + "</FILENAME>").getBytes());
outputstream.write( ("<BASE64DATA>" + str + "</BASE64DATA></ROOT>" ).getBytes());
}
catch(Exception e)
{
e.printStackTrace();
}
}
byte[] buffer = new byte[1024*5000];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len;
String str = null;
}
I had to do the following configuration settings
1) Create a Sender Comm Channel with Adapter Specific message attributes and Filename checkbox checked.
2) Use the Java Mapping in the Operation mapping.
The scenario is working smoothly with out any issues.
Thanks.
Kiran
try using a java mapping. In this you can use the Apache Commons (org.apache.commons.codec.binary.Base64) library to convert base64 values from and to binary. This spares you the touble of developing an adapter module.
For the inbound message you can use any datatype.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Andreas !! Can you please explain what should be the data type of my input message and how do I capture the input pdf in my outbound binary input message. For the mapping to my inbound I will research on Apache Commons (org.apache.commons.codec.binary.Base64) which I can use in my udf.
Thanks.
Kiran
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.