This blog was created in 2019 and was a response to the CPI on Neo did not include JMS or it was expensive. With SAP Integration Suite now the pipeline concept is the way to go for simplifying your operations. We don’t recommend this setup anymore.
It is pretty difficult to restart SAP CPI messages from any external applications. There
We wanted to make some of the development a little easier. It requires just one groovy script and two script steps in your iflow. We will show a different way that allows you to restart messages in an external application and
Check out the video where you can see how simple it is to restart a SAP CPI message.
We currently do not know how this will affect count of connections on your SAP CPI system, so use with caution.
You can try out Figaf IRT on your own system. We have both a cloud and an on-prem version to deploy the application.
You can see the code below, it will be updated so you can find a more uptodate version in the IRT application.
package com.figaf.irt
import com.sap.gateway.ip.core.customdev.util.Message
import org.apache.camel.converter.stream.InputStreamCache
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def Message initalSave(Message message) {
try {
//Body
def body = message.getBody(java.lang.String)
def base64 = body.bytes.encodeBase64().toString()
Map map = message.getHeaders()
map.put("body", base64)
message.getHeaders()
def json = JsonOutput.toJson(map)
def cache = new InputStreamCache(json.bytes)
// we save the json as a property, so we can restore it in the pipeline
message.setProperty("IRTSAVE", cache)
} catch (Exception ex) {
try {
def messageLog = messageLogFactory.getMessageLog(message)
messageLog.setStringProperty("CustomLog", ex.getClass().getName() + ":" + ex.getMessage())
} catch (Exception ignored) {}
}
return message
}
/**
* An error have occurred then save the payload as an attachement
* @param message
* @return
*/
def Message savePayload(Message message) {
try {
def messageProperties = message.getProperties()
def ex = messageProperties.get("CamelExceptionCaught")
if (ex == null) {
return message
}
def irtpayload = message.getProperty("IRTSAVE")
JsonSlurper jsonSlurper = new JsonSlurper()
def map = jsonSlurper.parseText(irtpayload.getText())
map.put("Cause", ex.getClass().getName() + ":" + ex.getMessage())
irtpayload = new InputStreamCache(JsonOutput.toJson(map).bytes)
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream()
irtpayload.writeTo(bytesOut)
def messageLog = messageLogFactory.getMessageLog(message)
messageLog.addAttachmentAsString("IRTSAVE", new String(bytesOut.toByteArray()), "application/json")
message.setHeader("SAP_Receiver", "LOG")
} catch (Exception ex) {
try {
def messageLog = messageLogFactory.getMessageLog(message)
messageLog.setStringProperty("CustomLog", ex.getClass().getName() + ":" + ex.getMessage())
} catch (Exception ignored) {}
}
return message
}