on 05-13-2011 7:55 AM
Hi!
We want to create an attachment witihn a graphical mapping using an UDF function.
I use that function:
public String addAttachment(String filename, String mimeType, String content, Container container) throws StreamTransformationException{
BASE64Decoder decoder=new BASE64Decoder();
try {
GlobalContainer globalContainer = container.getGlobalContainer();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment attachments = outputAttachments.create(filename, mimeType,decoder.decodeBuffer(content));
outputAttachments.setAttachment(attachments);
return "Adde1: "+filename;
} catch (Exception e) {
return e.toString();
}
}
(SDN helped me much in creating that
This function has no compiling errors, anything workes fine:
It takes 3 input-parameters, see also: http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/api/OutputAttachments.html
filename (ok, more or less contentID)
mimeType (more or less contentType)
content: Base64-encoded String which should be set as content
In my sample I use the following constants for that function:
filename = "fn1.txt"
mimeType="application/xml"
content = "UG9seWZvbiB6d2l0c2NoZXJuZCBhw59lbiBNw6R4Y2hlbnMgVsO2Z2VsIFLDvGJlbiwgSm9naHVydCB1bmQgUXVhcms=" --> cames directly from http://de.wikipedia.org/wiki/Base64
When using the message, I got this error within SXMB_MONI:
<SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not queue receive for
message 0022642d-b106-02df-8e8c-f41c243bd112(INBOUND). Reason: java.lang.NullPointerException: while trying to
invoke the method com.sap.aii.af.sdk.xi.lang.Binary.getBytes() of an object returned from
com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload.getContent()</SAP:AdditionalText>
This looks pretty much the same as but this tread is also not answered.
looks also in that direction, again, no answer.
So, I was wondering if someone has solved such problem?
As you have catched all exceptions in your UDF, I assume that the error comes from another part of your mapping.
Do you have also an UDF, where you try to read an existing attachment? The error message shows, that the mapping cannot read a part of the message, but in your UDF you do not have a method for reading it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
The input-message doesn't have an attachemt therefore it makes no sense to read it.
And: The exception doesn't came from the mapping it cames from anything else.
If I remark out the line "outputAttachments.setAttachment(attachments);" then the message runs trough without any interruption.
The Error cames up in the SXMB_MONI when executing a message for this szenario/mapping.
So, if I change the UDF to that:
BASE64Decoder decoder=new BASE64Decoder();
try {
GlobalContainer globalContainer = container.getGlobalContainer();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment attachments = outputAttachments.create(filename, mimeType,decoder.decodeBuffer(content));
//outputAttachments.setAttachment(attachments);
return "Adde1: "+filename+" and attachments is null? "+ (attachments==null);
} catch (Exception e) {
return e.toString();
}
it runs without any error. and also the return-value shows me, that attachments is not null
Hi Divyesh!
We did it that way:
1. Choosing the XML-Mailstructure as Destination as described in Configuring the Receiver Mail Adapter - Advanced Adapter Engine - SAP Library - Example (XI payload with mail package)
2. now we have created a UDF for creating the "content"
public void getContent(String[] text, String[] attFname, String[] attType, String[] attContent, ResultList result, Container container) throws StreamTransformationException{
// vergleich ob alle att-Arrays selbe anzahl haben
if (attFname.length!=attType.length || attFname.length!=attContent.length) {
result.addValue(Integer.parseInt("Fehler: alle Attachment-Eingänge müssen die selbe Anzahl an Elementen haben!"));
}
String CRLF = "\r\n";
String output="This is a multi-part message in MIME format."+CRLF+CRLF+
"--"+getBoundary(container)+CRLF+
"Content-Type: text/plain; charset=UTF-8"+CRLF+
"Content-Disposition: inline" + CRLF + CRLF +
text[0]+CRLF;
for (int i=0;i<attFname.length;i++) {
output+="--"+getBoundary(container)+CRLF+
"Content-Type: "+attType[i]+"; name="+((char)34)+attFname[i]+((char)34)+CRLF+
"Content-Disposition: attachment; filename="+((char)34)+attFname[i]+((char)34)+CRLF+
"Content-Transfer-Encoding: Base64"+CRLF+CRLF+attContent[i]+CRLF;
}
output+="--"+getBoundary(container)+CRLF;
result.addValue(output);
}
This UDF is configured as "QUEUE"
We have configured this input-structure
The Content itself is allready base64.
So we can call this mapping and it creates a Multipart-Mail for us.
User | Count |
---|---|
94 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.