on 08-13-2010 1:27 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Regards
Asif
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
> 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>
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
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
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
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
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
"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.
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
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
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
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
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
User | Count |
---|---|
85 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.