cancel
Showing results for 
Search instead for 
Did you mean: 

Read Attachment file name using JAVA UDF

Former Member
0 Kudos

Hi All,

I have a requirement to read the attachment file name in SAP PI using java udf and place it in dynamic configuration.

Scenario is Proxy==>PI==>SOAP , so i have to read the attachment file name which is comming from proxy and then send it to SOAP receiver  in dynamic configuration.

Accepted Solutions (0)

Answers (2)

Answers (2)

venkatasasidhargupta_gada
Active Participant
0 Kudos

Hi Pavan

Proxy uses SOAP to send message to XI, so you can check the Dynamic Configuration in XI runtime in Monitor(sxi_monitor) for details. Find out the parameter where the attachment name is stored and read that using java udf.

Thanks

Sasidhar Gupta

kavitha_rambabu
Explorer
0 Kudos

Hi Amit,

I am trying to read the attachment file names in mapping and tried the UDF posted by you. UDF returns runtime created attachment ID like below.

I also tried like , but could not retrieve file name and the result is still CID as below. I tried using Dynamic configuration with the same result.

Can someone help me on reading attachment filename from ABAP Proxy sender? Or is there a possibility mapping to read PI SOAP BODY manifest that has file name in **<SAP:Name>FileName.PNG</SAP:Name>**?

Please let me know..

Thanks,

Kavitha

azharshaikh
Active Contributor
0 Kudos

Hello Kavitha,

Open the PI message in Monitoring and check if you get the File Name in Content Type in Attachment tab of Moni.as shown in attached Screenshot.

You can try to read the filename using

attachments.getContentType();

Hope it helps

Regards,

Azhar

kavitha_rambabu
Explorer
0 Kudos

Thanks Azhar, I used attachments.getContentType(); and retrieved only document type. It does not have information on FileName. Attached the snapshot below that was returned.


In my case, sender is ABAP proxy, and i have to read the file name and encode the content and send to target system. I can encode file content but have problem retrieving with file name. Does Attachment interface have a method getName() or so to return file name?

Thanks,

Kavitha

kavitha_rambabu
Explorer
0 Kudos

Here is my code i'm using to read attachment file name:

GlobalContainer globalContainer = container.getGlobalContainer();

InputAttachments inputAttachments = globalContainer.getInputAttachments();

AbstractTrace trace = container.getTrace();

try

{

     //check the availability of attachments in input message 

     if(inputAttachments.areAttachmentsAvailable())

     {

          trace.addInfo("Input attachment available");

          //get attachmentIds and store it in an Object array

          Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);

          Object[] arrayObj = CollectionIDs.toArray();

          int attachmentCount = arrayObj.length;

          String[] Content = new String[attachmentCount];

          String[] AttachmentID = new String[attachmentCount];

          String[] AttachmentName = new String[attachmentCount];

          //Loops input attachments to get content of the attachment 

          for(int i =0;i<attachmentCount;i++)

          {

               AttachmentID[i] =(String) arrayObj[i];

               Attachment attachments =inputAttachments.getAttachment(AttachmentID[i]);

               Content[i] = attachments.getBase64EncodedContent();

               //AttachmentName[i] = attachments.getContentType();

               AttachmentName[i] = attachments.getName();

               AttData.addValue(Content[i]);

               AttName.addValue(AttachmentName[i]);

          }

     }

}

catch (Exception e)

{

e.printStackTrace();

}

and it compiles with below error after adding attachment.getname() method.

cannot find symbol
symbol : method getName()
location: interface com.sap.aii.mapping.api.Attachment

I searched on this error but couldn't get through.Can you help proceed further with the error and with reading file name?

Help on this much appreciated!!

Kavitha.

azharshaikh
Active Contributor
0 Kudos

Hi Kavitha,

There is no method as getName for Attachment.

I suggest you to first check in pimon, if you are getting the File name in Content-Type (refer the screenshot I attached abv).

If yes, then you need to perform substring operations on Content-Type value that you get inorder to pick the File name from the content-type string.

The screenshot you added is not very clear. Can you also try to add trace in your mapping to check the value returned in content-type:

trace.addInfo("contentType is:"+AttachmentName[i]);

Hope it helps.

Regards,

Azhar

Former Member
0 Kudos

Hi Azhar,

I am using Proxy to Mail scenario and need to retrieve attachment names so that I can pass on to mail. I see that all attachments are converting into "untitled.txt" and hence trying to set the file name in UDF. But I need to retrieve exact source attachment name send through proxy.

I need to retrieve attachment file name "Attach1.txt" in UDF which was attached using ABAP Proxy.

I could get the "contentID" value as "cid:payload-552538D9131F36A2E10000000A284B3F@sap.com" using mentioned code but my requirement is to get the "Attach1.txt" value mentioned in <SAP:Name> tag.

In our case, we see attachment name starting with "payload-" where as I see in other blogs that we can see actual attachment name instead of SAP generated name.

I see attachment name in <SAP:Payload> tag like <SAP:Payload xlink:href="cid:Attach1.txt"> whereas in our case we see as <SAP:Payload xlink:href="cid:payload-.......>

Please advise.

Regards

Srini

kavitha_rambabu
Explorer
0 Kudos

Hi Azhar,

Since sender is ABAP proxy, i cannot check the message in communication channel monitoring for attachment file name.

Moreover, Attachment.getContentType() could only me document type. Here is the traceinfo for same, that returned image/png as ContentType and does not contain file name in it.

                                                           Please suggest if there is a way to read the attachment name sent in ABAP proxy message.

Thanks for your help,

Kavitha

azharshaikh
Active Contributor
0 Kudos

Hi Kavitha,

For Proxy scenario I am not very sure on process to read Attachment name. Hope someone in forum might provide inputs on this.

As an alternative solution, since you are having Proxy at Sender side, can you request the Sender to send File name in one of the XML Field, so that you can map it directly. I believe the ABAPer can pass the filename value in the payload.

Regards,

Azhar

kavitha_rambabu
Explorer
0 Kudos

Thanks Azhar...

Kavitha

Former Member
0 Kudos

Hi Kavitha!

Have you managed to solve the issue?

WBR

Dmitriy

kavitha_rambabu
Explorer
0 Kudos

Hello Dmitriy,

I got attachment file names passed in source payload and mapped one to one for file name. Used above UDF to read and convert attachment data to base64encoded.

You also have to select 'Read Attachments' in Operation mapping.

Regards,

Kavitha

Former Member
0 Kudos

Thank you!

rhviana
Active Contributor
0 Kudos
Former Member
0 Kudos

Hi Ricardo,

You didn't get my point. my scenario is Proxy system will send the main payload with and attachment. so i have to read that extra attachment file name using java UDF.

rhviana
Active Contributor
0 Kudos

Pavan,

Sorry for that.

Java UDF code :

http://scn.sap.com/thread/1341089

Configuration at Directory:

https://scn.sap.com/thread/3154499

Regards,

Former Member
0 Kudos

Hi Ricardo,

That was good code, but this code will read the attachment data only. but i need the file name not the content in side the attachment.

Former Member
0 Kudos

Hello,

Check this code:

Below code will read the attachment file name

GlobalContainer gc = container.getGlobalContainer();

InputAttachments ia = gc.getInputAttachments();

String ContentID = new String();

AbstractTrace trace = container.getTrace();

try

{

if(ia.areAttachmentsAvailable())

{

trace.addInfo("Input attachment available");

Collection<String> collectionIDs = ia.getAllContentIds(true);

for (Iterator<String> it = collectionIDs.iterator(); it.hasNext();)

{

ContentID = it.next();

trace.addInfo("ContentID :" + ContentID);

result.addValue(ContentID) ;

}

}

}

catch(Exception e)

{

}

Thanks

Amit Srivastava

swapna_patha
Explorer
0 Kudos

Hi Amit, Thanks for the code, this is helpfull for me. I need some more help on this,

by using the above code i am able to get "payload-DB16DE56787A6555E10000003547E459@sap.com" in the feild.

Requirement: is it possible to provide the same along with "cid" and can we create link on this(on click of this) the payload or content id specific to this has to be opened.

please let me know if i have to provide any further information.

Regards,

Swapna.