on 08-27-2023 9:47 AM
Dear Experts,
i have a scenario to read xml from source and pass the same content as attachment along with the soap envelop(and the attachment name as content Id inside the body elements) to receiver system.
so i used the groovy script as suggested in the following link Create Attachments by SAP Help but I'm getting the below error.
javax.script.ScriptException: java.lang.Exception: java.lang.NullPointerException:
Cannot invoke method indexOf() on null object@ line 12 in script3.groovy,
cause: java.lang.NullPointerException: Cannot invoke method indexOf() on null object
and the script used added below along with sample xml
Kindly let me know if any change required in script level.
<ns0:sddaa xmlns:ns0="http://sddaa.com/schema/service/Upload/1.0">
<ns0:SignRq>
<ns0:ClientDt>2023-07-23T11:50:52</ns0:ClientDt>
<ns0:LanguagePref>en-gb</ns0:LanguagePref>
<ns0:SignProfile>
<ns0:Sender>224</ns0:Sender>
<ns0:Receiver>test-001</ns0:Receiver>
<ns0:MsgCode>BUP</ns0:MsgCode>
</ns0:SignProfile>
</ns0:SignRq>
</ns0:sddaa>
import com.sap.gateway.ip.core.customdev.util.Message
import org.apache.camel.impl.DefaultAttachment
import javax.mail.util.ByteArrayDataSource
def Message processData(Message message)
{ // Get content type
def headers = message.getHeaders()
def contentType = headers.get("Content-Type")
// Define suffix
def suffix = contentType.substring(contentType.indexOf("/")+1)
if(suffix == "plain"){ suffix = 'txt' }
// Get message payload as input stream
def body = message.getBody(InputStream.class)
// Set MIME type
def dataSource = new ByteArrayDataSource(body, contentType)
// Construct a DefaultAttachment object
def attachment = new DefaultAttachment(dataSource)
// Add the attachment to the message
message.addAttachmentObject('attachment.' + suffix, attachment)
return message;
}
The example that you refer to is triggered by a soap call which passes the content-type header to the integration flow, based on the content-type the file suffix is defined accordingly, in your case obviously the content-type is not set, so you need to adapt your script accordingly, from what I understand you read an xml file and like to attach the same, so your suffix is fixed .xml
Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
74 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.