on 11-17-2009 2:48 PM
Hi,
I'm trying to add an attachment to the main payload in a SOAP communication channel, like this:
XMLPayload extraInfoAsAttachment = new XMLPayloadImpl(); //com.sap.engine.interfaces.messaging.spi.XMLPayloadImpl
//XMLPayload extraInfoasAttach = msg.createXMLPayload(); //--> when trying with this it will also fail
try{
String text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><testing>test</testing>";
extraInfoAsAttach.setContentType("UTF-8");
extraInfoAsAttach.setContent(text.getBytes());
msg.addAttachment(extraInfoAsAttach); //provokes exception
} catch (Exception e){
audit.addAuditLogEntry (key, AuditLogStatus.ERROR, "Failure when adding the attachment");
audit.addAuditLogEntry (key, AuditLogStatus.ERROR, e.getMessage()); //--> writes UNDEFINED
throw new ModuleException (e);
}
But it will fail in the catch block, with UNDEFINED message.
Ive found the same problem, unresolved, here:
Any tips? Thanks a lot.
Edited by: Jorge Lopez on Nov 17, 2009 3:49 PM
I have tested following for PI 7.0 and Xi 3.0:
public ModuleData process(ModuleContext moduleContext,
ModuleData inputModuleData)
throws ModuleException {
// create a second attachment for the receiver mail adapter
try {
// get the XI message from the environment
Message msg = (Message)
inputModuleData.getPrincipalData();
// create a new payload
TextPayload attachment = msg.createTextPayload();
// provide attributes and content for the new payload
attachment.setName("Attachment");
attachment.setContentType("text/plain");
attachment.setText("Hello World");
// add the new payload as attachment to the message
msg.addAttachment(attachment);
// provide the XI message for returning
inputModuleData.setPrincipalData(msg);
} catch (Exception e) {
// raise exception, when an error occurred
ModuleException me = new ModuleException(e);
throw me;
}
// return XI message
return inputModuleData;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Stefan, I made it work with a similar code.
Just for the record, when trying to get the attachment again in another interface (my message with attachment is the input for another interface), there are two things that won't work (they would work only on the same interface, in a following module for example):
- You can't get the attachment as TextPayload (you have to use Payload)
- The name of the attachment is not kept (so don't try to get the attachment by name)
Not fully sure, but there is sthg strange for me :
...setContentType("UTF-8");
not sure this value is an accetable content-type header value, should be sthg like "attachment/xml" or "text/xml" (any valid string defining type of the data you're adding)
Rgds
Chris
PS: any hope to get the call stack for this UNDEFINED exception ?
Edited by: Christophe PFERTZEL on Nov 17, 2009 4:02 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cristophe,
I've tried with text/xml and other values with the same result.
Also, I've tried with:
TextPayload extraInfoAsAttachment = new TextPayloadImpl();
with no result either.
It's always a MP: exception caught with cause java.lang.NullPointerException: message.
This is intriguing as most of the weblogs or forums messages related with attachments deal with how to read the attachments, not how to create the attachments (only for the mail adapter there are some about how to create but it's an specific thing of the mail adapter).
User | Count |
---|---|
78 | |
10 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.