cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Binary payload(in a field) to .docx and .xlsx and send it as an attachment with SOAP adapter.

Former Member
0 Kudos

Hello PI team,

I need guidance in a synchronous scenario ; SOAP to Proxy.

A call is placed from sender SOAP channel to fetch a set of documents from ECC system. ECC system in turn calls 'opentext' server to fetch the required document.

The fetched document in Binary format is sent as a value of a field named 'List' in response payload to PI. In PI this binary data is decoded with base64 decoder and content type used is either for docx or xslx or PDF depending on the file fetched.

This converted file is send as an attachment in the response message of SOAP call.

PDF conversion and attachment is working fine.

Issue lies while converting the binary to docx and xlsx.

For docx , if content type:

  1. application/vnd.openxmlformats-officedocument.

then the attachment created is Attachment.bin not Attachment.doc

If content type = application/msword

then attachment created is Attachment.doc, it open properly but after two pop ups:

1.

2.

For xlsx, for any of the content type :

  1. application/msexcel ,
  2. application/ms-excel ,
  3. application/vnd.ms-excel,
  4. application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

the attachment in the response is getting created as Attachment.bin not attachment.xls/attachment.xlsx. .

Required is attachment.docx and attachment.xlsx in the response payload

Please suggest!

Thank You.

Indu Khurana.

Accepted Solutions (0)

Answers (7)

Answers (7)

YouriC
Participant
0 Kudos

I saw your message in

My scenario is in ABAP.

I use get_protocol from my sproxy class.

lo_att_protocol ?= lo_retrievedoc->get_protocol( if_wsprotocol=>attachments ).

Next step :

CALL METHOD lo_att_protocol->get_attachments

     RECEIVING

          attachments = li_attach.

DESCRIBE TABLE li_attach LINES lv_count.


for retrieving the attachment list.


You can find information from the attachment with :

       LOOP AT li_attach INTO DATA(ls_attach). 

      ls_attach->get_content_type( ).


     CALL METHOD ls_attach->get_binary_data

          RECEIVING

                       p_data = gs_document-att_content.

ENDLOOP.

With get_binary_data i have the content of the attachment in binary.

I save this content in XString variable.

After I create the file with :

OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE.

TRANSFER lv_xstring TO lv_file.

CLOSE DATASET lv_file.

For the extension i control the mime-type with table "sdokfext"

xlsx = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Good luck,

Youri

Former Member
0 Kudos

Thank you Youri for your inputs.

Good day to you.

Regards,

Indu.

iaki_vila
Active Contributor
0 Kudos

Hi Indu,

You can check it, taking the base stream manually and checking it online for example here: https://www.base64decode.org/

Regards

Former Member
0 Kudos

Hi Inaki,

Thank you for your inputs.

I have compared the base64 decoded data converted at this link and in soapUI response, they look a bit different.

But does that mean it is invalid?

Thanks,

Indu.

Former Member
0 Kudos

Hi,

Is there a possibility that base64 decoder is not decoding properly?

Thanks.

Former Member
0 Kudos

Hello,

How to set the content disposition of attachment ?

Regards,

Indu.

former_member181985
Active Contributor
0 Kudos

Hi Indu,

can you try with MessageTransformationBean in SOAP sender channel after the default module(s)

Inserting MessageTransformBean in Module Processor - SAP NetWeaver Process Integration - SAP Library

Check section "Set MIME Content Fields"

Transform.ContentDisposition

Under Parameter Value enter attachment or inline.

Example: attachment;filename="abcd.xlsx"

Br,

Praveen

Former Member
0 Kudos

Hi Praveen,

I have tried it partially, I will try again y setting MIME content fields as you said ut does this work in synchronous SOAP scenario?

Former Member
0 Kudos

Hello everyone,

Can anybody provide any inputs on the issue.

The issue still persists:

Wword attachment: pop ups with attahcments while opening

Excel attachment: attachment.bin is getting created not attachment.xls/xslx

Thanks,

Indu.

former_member181985
Active Contributor
0 Kudos

Hi Indu,

As per SAP help,

OutputAttachments

contentType - the type of the attachment. Have a look at http://de.selfhtml.org/diverses/mimetypen.htm for an overview of possible types.

for *.docx mime type: application/vnd.openxmlformats-officedocument.wordprocessingml.document

can you try with:

contentType = "name=\"file1.docx\""; application/vnd.openxmlformats-officedocument.wordprocessingml.document;

for *.xlsx mime type:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

can you try with:

contentType = "name=\"file2.xlsx\""; application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;

Br,

Praveen

Former Member
0 Kudos

Hi Praveen,

I tried with the MIME type given by you and still the same name: attachment.bin

Thanks,

IK.

Former Member
0 Kudos

Hi Praveen,

In addition to my earlier comment, whenever I change the name changes in content type but it does not change in Name section in SOAPUI as in screenshot.

I tried with setFileName() but it does not recognizes and fails while compiling.

Regards,

Indu

manoj_khavatkopp
Active Contributor
0 Kudos

Indu,

While you are converting the base64data back to the doc/xsl/pdf and setting the file as an attachment you can set content type.


Attachment attOut = outAttach.create(filename1.replaceAl, "content-type", byte);

Br,

Manoj

Former Member
0 Kudos

Hello Manoj,

Thank you for your inputs.

I'm using this UDF:

GlobalContainer globalContainer = container.getGlobalContainer();    OutputAttachments outputAttachments = globalContainer.getOutputAttachments();    AbstractTrace trace;  trace = container.getTrace();  byte[] pdfBytes; String contentType =Type[0]; String contentType ="application/msexcel"; String pdf = ""; //Loop at the Data for (int i=0; i

Thanks,

Indu.

Former Member
0 Kudos

earlier message did not come properly.sending again

BASE64Decoder decoder = new BASE64Decoder();

byte[] decodedBytes = decoder.decodeBuffer(pdf);

Attachment newopAttachment = outputAttachments.create("test.xlsx" ,contentType , decodedBytes);  

outputAttachments.setAttachment(newopAttachment);  

manoj_khavatkopp
Active Contributor
0 Kudos

The code look fine .

Is it possible to check in RWB/Moni after message mapping and check the content type is set correctly or not , if possible download the attachment and then open.

Br,

Manoj

Former Member
0 Kudos

Manoj, I'm working on single stack.

I'm using soapUI as testing tool and I can see the content type in soapUI, It is whatever I have set in UDF: application/msexcel.

Tx,

Indu.

Former Member
0 Kudos

Hello,

Can anybody provide some insights on this?

Thanks,

Indu.

Snavi
Active Participant
0 Kudos

Hi,

for docx attachments use content-type as "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

and for xlsx use "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

Former Member
0 Kudos

Hi Navdeep,

Thanks for your feedback.

When I use the provided content type, the name of attachment in soapUI remains: Attachment.bin for both cases mentioned by you.

I'm not sure with synchronous SOAP adapter but I'm now trying  dynamic configuration to change the name of attachment from attachment.bin to attachment.xlsx

Thanks,

Indu.

Snavi
Active Participant
0 Kudos

Hi Indu,

when you get the binary from ECC, do you also get the document extension. or, how do you evaluate what content type you need to set in outputAttachments.create

Former Member
0 Kudos

Hi Navdeep,

In the response payload there is a field which carries the name of the file. e.g. file.docx or file.xlsx or file.pdf

Thanks,

Indu.

Snavi
Active Participant
0 Kudos

Hi Indu,

1.     when you rename the attachment.bin with correct extension manually, does the file gets opened correctly?

2.     If answer to point 1 is no, is it possible to update your code and save the decodedBytes to some file location, just to confirm if the binary you are getting in response is ok.

you can do this with following code

FileOutputStream fos = new FileOutputStream(filepath/filename);

fos.write(decodedBytes);

fos.close();

3.     In SOAPUI, if you click on raw tab in the response, what content type do you see

Former Member
0 Kudos

Hi Navdeep,

when I try to open the file it shows me invalid characters/junk as it open by default in notepad.
When I save the .bin file as .xlsx and try opening it then it opens the excel file but there is a pop up prior to this : it's corrupt and do u trust the sender, on clicking yes it opens the file properly.

Thanks.

Former Member
0 Kudos

Hi Navedeep,

2. As I can open the file saving it as .xlsx, so can I assume the binary file is okay?

3. Attached is the screenshot of the raw response:

Former Member
0 Kudos

sorry for typo: "Navdeep"

Snavi
Active Participant
0 Kudos

Hi Indu,

If the file prompts you with corrupt message, then i do think the content is not correct.

can you open the file in notepad++ with show all characters option enabled and see if there are CRLF characters at the end of the file. and if you remove those, does the file open normally.

Former Member
0 Kudos

Hi Navdeep,

I can see the CRLF characters but I checked in a well formed doc/xls file and they also have CRLF characters.

Snavi
Active Participant
0 Kudos

Hi Indu,

I have created a dummy interface with similar code that works with SOAPUI and shows the attachment name

I did some changes to simulate the the issue you are having, and i can see the attachment name shows as .bin only when i either don't specify the file extension or give null in the filename in the create() method

Former Member
0 Kudos

Hi Navdeep,

First of all thanks a ton for trying the scenario and taking out time for the issue. I truly acknowledge and appreciate

Secondly, could you please put the code you have used and I could not follow " file extension null in create()"; As I'm giving the file name.

Thanks,

Indu Khurana.

Snavi
Active Participant
0 Kudos

Hi Indu,

I am reading the file from local filesystem and leave blank in the first argument in the create method. this will have .bin as the file name in SOAPUI response


InputStream fis = new FileInputStream(file);

byte[] data = getBytesFromInputStream(fis);

Attachment attach = oa.create("", "application/vnd.openxmlformats-officedocument.wordprocessingml.document",  data);

oa.setAttachment(attach);

Former Member
0 Kudos

Hi Navdeep,

I tried the same way , but it just changes the value of contentID to file name ut "Name" is still attachment.bin.

See the screenshot attached.

Thanks.