我从gmail服务器获取数据并修改收入响应以匹配我们的模型,下面是XML连接器
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="readMail"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<property expression="json-eval($.id)" name="id"/>
<property expression="json-eval($.format)" name="format"/>
<property expression="json-eval($.metadataHeaders)" name="metadataHeaders"/>
<gmail.init>
<userId>pk@gmail.com</userId>
<refreshToken>1/kjvw78oyrwUR3SOeUUEowA</refreshToken>
<clientSecret>zSx8GJT44q554</clientSecret>
<clientId>48015251641-sm4k53u.apps.googleusercontent.com</clientId>
<accessToken>ya29.HNPGCpInGt5Z</accessToken>
<apiUrl>https://www.googleapis.com/gmail</apiUrl>
</gmail.init>
<gmail.readMail>
<id>{$ctx:id}</id>
<format>{$ctx:format}</format>
<metadataHeaders>{$ctx:metadataHeaders}</metadataHeaders>
</gmail.readMail>
<payloadFactory media-type="xml">
<format>
<jsonArray>
<channel>Email</channel>
<date_time>$1</date_time>
<channel_message>$2</channel_message>
<channel_message_ID>$3</channel_message_ID>
<created_by>$4</created_by>
</jsonArray>
</format>
<args>
<arg evaluator="json" expression="$.payload.headers[18].value"/>
<arg evaluator="json" expression="$.snippet"/>
<arg evaluator="json" expression="$.id"/>
<arg evaluator="json" expression="$.payload.headers[24].value"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" value="application/json"/>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
如果我们不参与收入回应并且回复是
,那么效果很好{
"id": "15d9882a2083",
"threadId": "15d984cccda1f63b",
"labelIds": [
"UNREAD",
"IMPORTANT",
"CATEGORY_PERSONAL",
"INBOX"
],
"snippet": "Hello Test, I am waiting for your response. Thanks Kumar 7795821986 From: Pawan, Kumar Sent: Monday, July 31, 2017 4:29 PM To: 'kmp@gmail.com' <kmp@gmail.com> Subject:",
"historyId": "2445",
"internalDate": "1501502285000",
"payload": {
"partId": "",
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Delivered-To", 0
"value": "kmps@gmail.com"
},
{
"name": "Received", 1
"value": "by 10.182.97.199 with SMTP id ec7csp3710677obb; Mon, 31 Jul 2017 04:58:06 -0700 (PDT)"
},
{
"name": "X-Received",
"value": "by 10.84.167.2 with SMTP id c2mr17110575plb.336.1501502286621; Mon, 31 Jul 2017 04:58:06 -0700 (PDT)"
},
{
"name": "ARC-Seal",
"value": "i=1; a=rsa-sha256; t=1501502286; cv=none; d=google.com; s=arc-20160816; b=n/+kZs18GcQlkEXGX0aQgxMgd9VUgWXoKThXzWCWKXdmlgc8qxvsj4OMGboEnQtQPL l9VzbkJ9o3TZDTmCi+krVuinmQMrD3APtzosvsYRQ3xoto1DPbUQ0QgLVRnauA9QNaBaIvLvI2OPVIdpy7ESjSfC4wnve/seSSdgN0h5xuzZw3vkVTzsRsiD1Mvn2H1LfanIjzv88/8/o8JRFLxl KjoQ=="
},
{
"name": "ARC-Message-Signature",
"value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:spamdiagnosticmetadata:spamdiagnosticoutput :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:to:from:dkim-signature :arc-authentication-results; bh=YpP6f56u11c7PZ8c3cD7kRP5/WQY7G0dC3crOi3Z+LY=; b=aKZNvlh8Z+oxbt6J3yiZ7 hv6h6s4fAT/ibB3BX2wImb6fCDBuIaoRdO1c6QLvV9m6mh+Rcj/mQfAhpignalmB2IHd GRhl72dfDHAinr7/uKESKuMUNe6WDCKxOlhT6qEjBZG2JUiAJ+WBldl4Qfk1ZDxTzGIO 1+6kVlgcBlTxVcNeX2BgriW/ekbo64SVW7xzJc/nlHI8IwolAhoYy0qaGymcqpWZbg34 3vkQ=="
},
{
"name": "Return-Path",
"value": "<Kumar.Pawan@gmail.com>"
},
{
"name": "Received-SPF",
"value": "pass (google.com: domain of kumar.pawan@gmail.com designates 216.32.181.177 as permitted sender) client-ip=216.32.181.177;"
},
{
"name": "Received",
"value": "from DM2PR0707.prod.outlook.com (10.160.246.151) by DMprd07.prod.outlook.com (10.160.246.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1282.10; Mon, 31 Jul 2017 11:58:05 +0000"
},
{
"name": "Received",
"value": "from DM2PR0701MB1120.namprd07.prod.outlook.com ([fe80::a093:3faf:5648:ce8c]) by DM2PR0701MB1120.namprd07.prod.outlook.com ([fe80::a093:3faf:5648:ce8c%14]) with mapi id 15.01.1282.023; Mon, 31 Jul 2017 11:58:05 +0000"
},
{
"name": "From", 13
"value": "\"Pawan, Kumar\" <Kumar.Pawan@gmail.com>"
},
{
"name": "To",
"value": "\"kmps@gmail.com\" <kmps@gmail.com>"
},
{
"name": "Subject",
"value": "RE: Testing The Application"
},
{
"name": "Thread-Topic",
"value": "Testing The Application"
},
{
"name": "Thread-Index",
"value": "AdMJ6/U2XdgtmEKwRzq9Td+H2hW+sQACDUaQ"
},
{
"name": "Date",
"value": "Mon, 31 Jul 2017 11:58:05 +0000"
},
{
"name": "Message-ID",
"value": "<DM2PR0701MB1120326F0CF8DA020E0E9D51120.namprd07.prod.outlook.com>"
},
{
"name": "Accept-Language",
"value": "en-IN, en-US"
},
{
"name": "Content-Language",
"value": "en-US"
},
{
"name": "X-MS-Has-Attach",
"value": "serrrttff"
},
{
"name": "X-MS-TNEF-Correlator",
"value": "werwerr"
},
{
"name": "x-originating-ip", 25
"value": "[249.251.141.1208]"
},
{
"name": "x-ms-publictraffictype",
"value": "Email"
},
{
"name": "x-microsoft-exchange-diagnostics",
"value": "1;DM2PR0701MB1118;7:TmcDBJD9ajlXGPZrK+7Ndm78rj+jgvwW2Qstv7LgTbDvfB9cimMen+iYXcEQ0CX+jpOpuHsGUww1a1IRz5w4nDZHSUwWI59LksydNMIiYX8FYfuWLiDQ7iABcOJwWFR7ehcVl+ilZL8DM5imk6agJZvRaujZyoaUY="
},
{
"name": "x-ms-office365-filtering-correlation-id",
"value": "d667a587a-4fa9-08d4d80b6759"
},
{
"name": "x-microsoft-antispam",
"value": "UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DM2PR0701MB1118;"
},
{
"name": "x-ms-traffictypediagnostic", 30
"value": "DM2PR0701MB18:"
},
{
"name": "x-exchange-antispam-report-test",
"value": "UriScan:(2174852155);"
},
{
"name": "x-microsoft-antispam-prvs",
"value": "<DM2PR0701MB1118CCF26D1E3309721A714899B20@DM2PR0701MB1118.namprd.com>"
},
{
"name": "x-exchange-antispam-report-cfa-test",
"value": "BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(100000805101)(100110500095);SRVR:DM2PR0701MB1118;"
},
{
"name": "x-forefront-prvs",
"value": "03853D523D"
},
{
"name": "x-forefront-antispam-report",35
"value": "SFV:NSPM;SFS:(10009020)(6009001)(39450400003)(39840400002)(398(5250100002)(9686003)(55016002)(189998001)(99286003)(1411001)((5001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR0701MB1118;H:DM2PR0701MB1120.namprd07.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en;"
},
{
"name": "spamdiagnosticmetadata",
"value": "NPM"
},
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=\"_000_DM2PR0701MB1120326F0CF8DA0299B20DM2PR0701MB1120_\""
},
{
"name": "MIME-Version",
"value": "1.0"
},
{
"name": "X-OriginatorOrg", 41
"value": "gmail.com"
},
{
"name": "X-MS-Exchange-CrossTenant-originalarrivaltime",
"value": "31 Jul 2017 11:58:05.4191 (UTC)"
},
{
"name": "X-MS-Exchange-CrossTenant-fromentityheader",
"value": "Hosted"
},
{
"name": "X-MS-Exchange-CrossTenant-id",
"value": "8d894c2b-238f-490b-8dd1-d93898c5bf83"
},
{
"name": "X-MS-Exchange-Transport-CrossTenantHeadersStamped", 45
"value": "DM2PR0701MB18"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=\"us-ascii\""
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 309,
"data": "SGVsbG8gVGVzdCwNCg0KSSBhbSB3YWl0aW5nIGZvciB5b3VyIHJlc3BvbnNlLg0KDQpUaGFua3MNClBhd2gZ2xhZCB0aGF0IHlvdSBjYW1lIHRvIG1lZXQgbWUuDQoNCg0KVGhhbmtzDQpQYXdhbiBLdW1hcg0KNzc5NTgyMTk4Ng0K"
}
},
{
"partId": "1",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=\"us-ascii\""
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 3360,
"data": "PGh0bWwgeG1sbnM6dj0idXJuOnNjaubWljcm9zb2Z0LmNvbS9vZmZpY2UvMjAwNC8xMi9vbW1sIiB4bE6MiA0IDUgMyA1IDQgNiAzIDIgNDt9DQpAZm9udC1mYWNlDQoJe2ZvbnQtZmFtaWx5OkNhbGlicmk7"
}
}
]
},
"sizeEstimate": 12167
}
问题是我试图将收入回复转换为我的模型的那一刻,并且该特定字段的请求以特殊字符开头。它开始给出错误。 例如,我希望created_by为“Return-Path”的值。但是因为它以特殊字符开头,所以它给出了错误&lt;在支持中缺失。
答案 0 :(得分:0)
如何将CDATA添加到您的有效负载工厂以“转义”此&lt;&gt; ?
<payloadFactory media-type="xml">
<format>
<jsonArray>
<channel>Email</channel>
<date_time>$1</date_time>
<channel_message>$2</channel_message>
<channel_message_ID>$3</channel_message_ID>
<created_by><![CDATA[$4]]></created_by>
</jsonArray>
</format>
<args>
<arg evaluator="json" expression="$.payload.headers[18].value"/>
<arg evaluator="json" expression="$.snippet"/>
<arg evaluator="json" expression="$.id"/>
<arg evaluator="json" expression="$.payload.headers[24].value"/>
</args>
</payloadFactory>