cancel
Showing results for 
Search instead for 
Did you mean: 

read webservice filename tag & pull the file from file location

Former Member
0 Kudos

Hi,

PI system has exposed a web service out of the following structure for the outside party to call

<MAT>

<doc type>pdf</doc type

<subnumber>1234</subnumber>

<id>45ABC<id>

<matno>ABCD</matno>

<filename>transaction1.pdf</filename>

</MAT>

When the outside party submits a web service request, I have to read the <filename> value (transaction1.pdf) and get the file from the file location which is local and convert the file to byte array.

How do I do this in message mapping or java mapping? Any help is greatly appreciated

thx

mike

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi. Michael.

You need another scenario to red the PDF file.

You can use a java mapping, to read the PDF file.

Also you can check this document.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/9913a954-0d01-0010-8391-8a3076440...

Regards

Lucho.

Former Member
0 Kudos

I don't think I can use another scenario because it has to be in the same scenario where in webservice request comes to PI and PI use a look up file as shown in the below link to get the file from the ftp location

File Lookup in UDF - Process Integration - SCN Wiki

Can I use this for PDF? And also how would the code looks like in my case for reading pdf and convert to byte array.

thanks

mike

Former Member
0 Kudos

And also I am in PO 7.4. there should be an easy way in PO 7.4 hopefully

Former Member
0 Kudos

Hi. you can use this UDF to convert the PDF to byteArray.


public static byte[] loadFile(String sourcePath) throws IOException {

        byte[] buffer = new byte[8192];

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        InputStream inputStream = null;

        int bytesRead;

     

        try {

            inputStream = new FileInputStream(sourcePath);

            while ((bytesRead = inputStream.read(buffer)) != -1) {

                baos.write(buffer, 0, bytesRead);

            }

         

        } finally {

            if (inputStream != null) {

                inputStream.close();

            }

        }

        return baos.toByteArray();

    }

Former Member
0 Kudos

Thanks Luis for the reply. I am not efficient in writing java program in udf.

can you please write the full java code for udf for connecting to ftp server url and then get the file using file name and convert to byte array. It would be really helpful

thx

mike