{
"page": "0",
"lastPage": "true",
"bounces": [
{
"messageId": "100000328097215",
"recipient": "test1@example.com",
"errorCode": "5.4.7",
"errorText": "[internal] exceeded max time without delivery",
"type": "Soft",
"timestamp": "2017-10-22 11:44:18.779"
},
{
"messageId": "100000328097294",
"recipient": "test2@example.com",
"errorCode": "5.4.7",
"errorText": "[internal] exceeded max time without delivery",
"type": "Soft",
"timestamp": "2017-10-22 11:43:54.793"
},
{
"messageId": "100000329705936",
"recipient": "test3@example.com",
"errorCode": "550",
"errorText": "NOMB - 550 Requested action not taken: mailbox unavailable",
"type": "Hard",
"timestamp": "2017-10-24 14:02:06.055"
}
]
}
{
"SAPnotificationList": {
"groupIndex": 1,
"groupCount": 1,
"SAPnotifications": [
{
"account": "TestAccount",
"notificationId": "100000328097215",
"status": [
{
"statusCode": "CH_REJECTED",
"statusText": "SOFT_BOUNCE",
"channel": "EMAIL",
"timestamp": "2017-10-22 11:44:18.779",
"recipient": "email:test1@example.com",
"channelStatusCode": "SMTP=554,DSN=5.4.7",
"channelStatusText": "ERR - 554 5.4.7 [internal] exceeded max time without delivery"
}
],
"characterSet": null,
"sender": "sender1@exampe.com",
"recipients": null,
"contentTextType": null,
"contentText": null,
"contentTextEncoding": null,
"channelPreferences": null,
"configuration": null,
"contentAttachments": null,
"campaign": "TestCampaign"
},
{
"account": "TestAccount",
"notificationId": "100000328097294",
"status": [
{
"statusCode": "CH_REJECTED",
"statusText": "SOFT_BOUNCE",
"channel": "EMAIL",
"timestamp": "2017-10-22 11:43:54.793",
"recipient": "email:test2@example.com",
"channelStatusCode": "SMTP=554,DSN=5.4.7",
"channelStatusText": "ERR - 554 5.4.7 [internal] exceeded max time without delivery"
}
],
"characterSet": null,
"sender": "sender1@exampe.com",
"recipients": null,
"contentTextType": null,
"contentText": null,
"contentTextEncoding": null,
"channelPreferences": null,
"configuration": null,
"contentAttachments": null,
"campaign": "TestCampaign"
},
{
"account": "TestAccount",
"notificationId": "100000329705936",
"status": [
{
"statusCode": "CH_REJECTED",
"statusText": "HARD_BOUNCE",
"channel": "EMAIL",
"timestamp": "2017-10-24 14:02:06.055",
"recipient": "email:test3@example.com",
"channelStatusCode": "SMTP=550,DSN=null",
"channelStatusText": "NOMB - 550 Requested action not taken: mailbox unavailable"
}
],
"characterSet": null,
"sender": "sender1@exampe.com",
"recipients": null,
"contentTextType": null,
"contentText": null,
"contentTextEncoding": null,
"channelPreferences": null,
"configuration": null,
"contentAttachments": null,
"campaign": "TestCampaign"
}
]
}
}
def Message redefineInputHeaders(Message message) {
def header = message.getHeaders();
def query = header.CamelHttpQuery;
query = query.replaceAll('startTimeUTC','startUTCTime');
query = query.replaceAll('endTimeUTC','endUTCTime');
query = query.replaceAll('page','groupIndex');
query = query.replaceAll('sourceSystem','campaign');
regexPattern = "(?<=groupIndex=)[0-9]([0-9])?" as String;
pattern = Pattern.compile(regexPattern) as Pattern;
def matcher = pattern.matcher(query) as Matcher;
def newQuery = "";
if(matcher.find()){
def page = query.substring(matcher.start(), matcher.end()) as Integer;
page = page+1;
newQuery = query.substring(0,matcher.start())+page+query.substring(matcher.end());
}
header.CamelHttpQuery = newQuery;
message.setHeaders(header);
return message;
}
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SAPnotificationList">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="groupIndex"/>
<xs:element type="xs:byte" name="groupCount"/>
<xs:element name="SAPnotifications" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="account"/>
<xs:element type="xs:long" name="notificationId"/>
<xs:element name="status" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="statusCode"/>
<xs:element type="xs:string" name="statusText"/>
<xs:element type="xs:string" name="channel"/>
<xs:element type="xs:string" name="timestamp"/>
<xs:element type="xs:string" name="recipient"/>
<xs:element type="xs:string" name="channelStatusCode"/>
<xs:element type="xs:string" name="channelStatusText"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="characterSet"/>
<xs:element type="xs:string" name="sender"/>
<xs:element type="xs:string" name="recipients"/>
<xs:element type="xs:string" name="contentTextType"/>
<xs:element type="xs:string" name="contentText"/>
<xs:element type="xs:string" name="contentTextEncoding"/>
<xs:element type="xs:string" name="channelPreferences"/>
<xs:element type="xs:string" name="configuration"/>
<xs:element type="xs:string" name="contentAttachments"/>
<xs:element type="xs:string" name="campaign"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="page"/>
<xs:element type="xs:string" name="lastPage"/>
<xs:element name="bounces" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:long" name="messageId"/>
<xs:element type="xs:string" name="recipient"/>
<xs:element type="xs:string" name="errorCode"/>
<xs:element type="xs:string" name="errorText"/>
<xs:element type="xs:string" name="type"/>
<xs:element type="xs:string" name="timestamp"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
{
"page": 0,
"lastPage": true,
"bounces": []
}
def Message changeErrorCode(Message message){
def body = message.getBody(java.lang.String) as String;
def root = new XmlSlurper().parseText(body);
root.bounces.each { bounce ->
def errorCode = bounce.errorCode.text();
def errorText = bounce.errorText.text();
def regexPattern = "\\[(internal)]" as String;
def pattern = Pattern.compile(regexPattern) as Pattern;
def matcher = pattern.matcher(errorText) as Matcher;
if(matcher.find()){
errorText = errorText.substring(matcher.start());
bounce.errorText.replaceBody(errorText);
}
regexPattern = "[0-9][.][0-9][.][0-9]" as String;
pattern = Pattern.compile(regexPattern) as Pattern;
matcher = pattern.matcher(errorCode) as Matcher;
if(matcher.find()){
def code = errorCode.substring(matcher.start(),matcher.start()+5);
bounce.errorCode.replaceBody(code);
} else {
regexPattern = "(DSN)=[0-9][0-9][0-9]" as String;
pattern = Pattern.compile(regexPattern) as Pattern;
matcher = pattern.matcher(errorCode) as Matcher;
if(matcher.find()){
def code = errorCode.substring(matcher.end()-3,matcher.end());
bounce.errorCode.replaceBody(code);
} else {
regexPattern = "(SMTP)=[0-9][0-9][0-9]" as String;
pattern = Pattern.compile(regexPattern) as Pattern;
matcher = pattern.matcher(errorCode) as Matcher;
if(matcher.find()){
def code = errorCode.substring(matcher.end()-3,matcher.end());
bounce.errorCode.replaceBody(code);
}
}
}
}
message.setBody(XmlUtil.serialize(root));
return message;
}
def Message changeType(Message message){
def body = message.getBody(java.lang.String) as String;
def root = new XmlSlurper().parseText(body);
root.bounces.each { bounce ->
def type = bounce.type.text();
if (type == "SOFT_BOUNCE") {
bounce.type.replaceBody("Soft");
}
if (type == "HARD_BOUNCE") {
bounce.type.replaceBody("Hard");
}
}
message.setBody(XmlUtil.serialize(root));
return message
}
def Message handleSingleBounce(Message message){
def slurper = new JsonSlurper();
def body = message.getBody(java.lang.String) as String;
def bodyJSON = slurper.parseText(body);
def bounces = bodyJSON.bounces;
def bouncesAsString = JsonOutput.toJson(bounces);
if (!bouncesAsString.startsWith("[")){
def bouncesWithBrackets = slurper.parseText("["+bouncesAsString+"]");
bodyJSON.bounces = bouncesWithBrackets;
message.setBody(JsonOutput.toJson(bodyJSON));
}
return message;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
9 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |