cancel
Showing results for 
Search instead for 
Did you mean: 

Change Content Encoding to base64

Former Member
0 Kudos

I have created a module to encode a pdf attachment to base64. When I see it the receiver channel the encoding says binary. How can I change the content encoding to base64.

Thanks

Asif

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

No I did not change it to base64. I sent it as is, the receiving system was able read it without converting to base64. Their original sample provided by them had it as base64, but they were read the attachment as binary. My scenario was ECC (idoc)->PI (PIDX invoice and pick a pdf file from ftp and attach it to the invoice - this was in the adapter module)-> RNIF.

Regards

Asif

vk_k3
Participant
0 Kudos

Ok, Can you please give me some rough idea on the syntax you have used in the adapter module to attach the PDF File to the Invoice ?

Did you write code in Adapter Module to pick the file from the FTP and attach it to the Invoice ?

Regards,

Vkjoat

Former Member
0 Kudos

VKjoat

Below is the code snippet to do the attachment. This is just part of the code, you need to create the complete module. Refer the links below to create your module.

Object obj = null;   // Handler to get Principle data

Message msg = null;  // Handler to get Message object

//Get the Principal data...

            obj = inputModuleData.getPrincipalData();

            msg = (Message) obj;

                    Payload payload = msg.createPayload();

                    payload.setContentType("application/pdf");

                    payload.setContent(file.getBytes());

                    payload.setAttribute("Content-ID", "filename@company.com.");

                    payload.setName("filename");

                    msg.addAttachment(payload);

                    inputModuleData.setPrincipalData(msg);

Links:

http://scn.sap.com/docs/DOC-3816

http://scn.sap.com/people/farooq.farooqui3/blog/2008/09/24/sap-xipi-encode-outgoing-payload-using-ad...

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c0b39e65-981e-2b10-1c9c-fc3f8e674...

Regards

Asif

Former Member
0 Kudos

Hi ALL

    We are able do attachment using UDF Need help for updating Content-Transfer-Encoding: Binary  to base64

Content-Type: application/pdf

Content-Transfer-Encoding: base64

content-id: <Attachment0>

0 Kudos

Hi,

Our scenario is ECC (idoc)->PI (PIDX invoice )-> RNIF. We want to change Content-Transfer-Encoding from binary to 8 bit. Can you please let me know how we can update Encoding in PIDX message?

Currently we can see binary in PIDX message but receiver wants it to be 8 bit.

Thanks and Regards,

Prachi

stefan_grube
Active Contributor
0 Kudos

> I have created a module to encode a pdf attachment to base64. When I see it the receiver channel the encoding says binary.

This is correct. Do not change it.

Former Member
0 Kudos

How will the receiving system know whether I have encoded to base64 or not. If I do not encode the attachment the Content encoding is "binary" and if I encode the Content encoding is also "binary". My receiver channel is RNIF in my scenario.

Below is what I get in the channel for encoded as well as without encoding.

Content-Type: application/pdf

Content-Transfer-Encoding: binary

Content-ID: Attachment.7017f020a66c11dfbc9f001125c0de06ATsap.com

This is from the sample I received from my trading partner on how it is expected; which is what I am trying to do here

Content-Type: application/pdf

Content-Transfer-Encoding: base64

content-id: <Attachment0>

stefan_grube
Active Contributor
0 Kudos

> Content-Transfer-Encoding: base64

This is something totally different of that you have posted the first time.

Why you do not describe your scenario first so a reader knows what you are talking about?

Sorry, I do not know this.

vk_k3
Participant
0 Kudos

HI Asif,

I am exactly in the same situation now!!

When I am trying to post RNIF message to Legacy system it works when there is no attachment.

But when there is attachment, it doesnt work.

I am trying to change the "Content-Transfer-Encoding"  to base64 but finding it bit difficult.

Can you please suggest if you have fixed your Issue or if I can try something ?

Regards,

VkJoat

Former Member
0 Kudos

Hi

I do not remember how I resolved the issue, it was awhile back. I might have sent the file as is without encoding to base64. But try setAttribute in the module.

Payload payload = msg.createPayload();

payload.setContentType(contentType);

payload.setContent(file.getBytes());

payload.setAttribute("Content-Transfer-Encoding","base64");

Let me know if it works

Asif

vk_k3
Participant
0 Kudos

HI Asif,

Thanks for the reply!!

Do you want me to write an Adapter module ?

Or  just try to handle it with payloadzipbean in the Module processor ?

Regards,

Vkjoat

vk_k3
Participant
0 Kudos

HI Asif,

Can you please try to  recollect your solution for this problem as this has become bit critical for me now!!

Regards,

Vkjoat

Former Member
0 Kudos

I was creating an attachment in a module, for me I had the option of sending it in base64 or binary. The solution I provided above is to be used in a module. I don't know where you are getting the attachment from. If you are getting it from the sender of the message you can ask them to send it in binary format or you could decode it in mapping then send it to to the receiver. Let me know you complete scenario

Thanks

Asif

vk_k3
Participant
0 Kudos

HI Asif.

In My Scenario,

PI is receiving the attachment from ECC via ABAP Proxy.

In SXMB_MONI, I can see the message with the attachment which is base64 encoded.

As, you said, I can get a binary file from ECC and try to decode it in PI.

So it says you have Developed  your own Adapter Module? right ?

Regards,

VKJoat

Former Member
0 Kudos

Yes, mine was an adapter module to create the attachment. For ABAP Proxy sender you can try decoding it in the mapping. Create a java mapping look for the attachment then decode it and attach it back.

vk_k3
Participant
0 Kudos

HI Asif,

I have a question for you!!

If we are writing an Adapter Module to encode, we have to apply this module befpre RNIFModuleListener, so RNIFModuleListener will still change the content-encoding to Binary.

So, I think the two cases are same.

Case A: where attachment is already base64 encoded in ABAP and sent to PI and then to RNIF adapter.

Case B: encoding the attachment via an Adapter Module.

where we use the Module before RNIFModuleListener

.-->Can you please give me your opinion on the above cases ?

  -->Shall we proceed with Case B or shall we write an Adapter Module to change the Encoding from Binary to Base64 ?

Regards,

Vkjoat

Former Member
0 Kudos

"If we are writing an Adapter Module to encode, we have to apply this module befpre RNIFModuleListener"

Yes, here I was suggesting trying to change Content-Transfer-Encoding:  from binary to base64.

Case A - I suppose this is whats not working for you, hence the above suggestion.

Case B - Here my suggestion was to decode base64 attachment and send the attachment as binary.

Both the cases require writing a Adapter module.

Again the easiest solution to try is decoding the attachment via a java mapping.

Below is a sample java mapping, you need to change it for your requirement. This java mapping decodes a base64 data coming in the xml element PDFOutput. I use it for a scenario where ABAP proxy sends an pdf in base64 format in the xml tag PDFOutput, I decode it and put in FTP. It is not an attachment.

"

package decodeAttachment.mapping;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

import sun.misc.BASE64Decoder;

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 DecodeAttachment extends AbstractTransformation{

    public void transform(TransformationInput input, TransformationOutput output) throws StreamTransformationException {       

        try{

             

               DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

               DocumentBuilder builder = factory.newDocumentBuilder();

               Document docOld = builder.parse(input.getInputPayload().getInputStream());

               //Get the node name Details that contains the Based64 Encoded information..

               NodeList details = docOld.getElementsByTagName("PDFOutPut");

               //Get the Text of Node.

               String data = details.item(0).getChildNodes().item(0).getNodeValue();

               //Instantiate an object of BASE64Decoder...

               BASE64Decoder decoder =  new BASE64Decoder();

               //Decode the encoded information....

               byte b[] = decoder.decodeBuffer(data);

              

               StreamResult result = new StreamResult(output.getOutputPayload().getOutputStream());

               result.getOutputStream().write(b);

              }

              catch (Exception e){

               System.out.println(e);

              }

    }

}

"

Please refer to this blog for how to read attachment in message mapping.

http://scn.sap.com/people/yugapreetha.t/blog/2009/08/24/read-the-attachments-of-the-input-xi-message...

vk_k3
Participant
0 Kudos

HI Asif,

Do you have any document for the Module that you have created ?

I have setup the NWDS and have also created a module but for the proper java syntax I need some assistance.

Can  you please give me some Java syntax for setting up just the content-transfer-encoding in the Adapter module ?

Regards,

Vkjoat

vk_k3
Participant
0 Kudos

Hi Asif,

Can you please confirm if you have achieved the content-transfer-encoding problem via an Adapter Module? (change it from base64 to binary). As, I think it is not possible because of two reasons:

1.The RNIFModuleListener is always executed at last so though we write an Adapter module the RNIFmodulelistener will act at last and will write the content-transfer-encoding to binary.

2. Stefan Grube in the following post confirms that it is not possible.

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

Regards,

Vkjoat

vk_k3
Participant
0 Kudos

Hi Asif,

Can you please confirm if you have achieved the content-transfer-encoding problem via an Adapter Module? (change it from base64 to binary). As, I think it is not possible because of two reasons:

1.The RNIFModuleListener is always executed at last so though we write an Adapter module the RNIFmodulelistener will act at last and will write the content-transfer-encoding to binary.

2. Stefan Grube in the following post confirms that it is not possible.

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

Regards,

Vkjoat

Former Member
0 Kudos

VK

Stefan Grube is probably right, changing Content-Transfer-Encoding may not be possible. As I mentioned earlier since my module was creating the attachment rather than receiving it from the sender, I had the option of doing base64 or sending it as is. Since I never got a response for this I sent the attachment as is. I used the setAttribute to change my Content-ID.

Regards

Asif

vk_k3
Participant
0 Kudos

HI Asif,

Even my scenario is same where I am sending the base64 File coming form ABAP as it is via Receiver Adapter. When you have created the attachment and sent it to receiver it means you have used Receiver RNIF. So, my question is were you able to populate Content-Transfer-Encoding to "Base" in this case ?

Regards,

vkjoat

vk_k3
Participant
0 Kudos

I mean "base64" instead of binary?