使用 mule 4 在在线数据库中创建记录时邮递员出现乱码
Getting gibberish in postman when creating records in online database with mule 4
我正在使用 phpmyadmin 在线数据库。我已经应用 client_id 和 client_secret API 管理器安全并部署到 cloudhub。
最初,我能够获取或更新数据库中的数据,但在部署到 cloudhub 后,运行 在邮递员中出现以下错误。
它是一个 put 方法,有 body
{
“资源”:
{
“客户编号”:“5”,
“姓名”:“山姆”
},
"destination":{
"CustomerId" : "4",
"Name" : "Jassie"
}
}
这是设置为变量的查询。
"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ "'" ++ payload.source.CustomerId ++ "'" ++ "," ++ "'" ++ payload.destination.CustomerId ++ "'" ++ ")"
{
"message": ""org.mule.weave.v2.exception.UnexpectedFunctionCallTypesException: 你用这些参数调用了函数 '++': \n 1: String ("SELECT CustomerId,Country FROM Customers WHERE CustomerId IN ('")\n 2: Null (null)\n\nBut 它需要以下组合之一:\n (Array, Array)\n (Date, Time)\n (Date, LocalTime)\n (Date,时区)\n (LocalDateTime, TimeZone)\n (LocalTime, Date)\n (LocalTime, TimeZone)\n (Object, Object)\n (String, String)\n (Time, Date)\n (TimeZone, LocalDateTime )\n (TimeZone, Date)\n (TimeZone, LocalTime)\n\n6| "SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ "'" ++ payload.source.CustomerId++ "'" ++ "," ++ "'" ++ payload.destination.CustomerId++ "'" ++ ")"\n ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n跟踪:\n 在 ++(行:6 , 列: 1)\n at ++ (line: 6, column: 75)\n at ++ (line: 6, column: 103)\n at ++ (line: 6, column: 110)\n at ++ (line: 6, column: 117)\n at ++ (line: 6, column: 124)\n at ++ (line: 6, column: 157)\n at main (line: 6, col umn: 164)\n" 计算表达式: "%dw 2.0\noutput application/java\n---\n//"(" ++ "'" ++ payload.source.CustomerId++ " '" ++ "," ++ "'" ++ payload.destination.CustomerId++ "'" ++ ")"\n\n"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " + + "(" ++ "'" ++ payload.source.CustomerId++ "'" ++ "," ++ "'" ++ payload.destination.CustomerId++ "'" ++ ")""。 “
}
从问题来看,您似乎正在尝试从 CustomerId 构造查询,该查询可以包装在源或目标中。您的代码有一些 null "" 值,这在连接时是不可接受的。
以下是我将如何通过导入字符串模块构建 DW。
%dw 2.0
import unwrap from dw::core::Strings
output application/java
---
"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ unwrap(write(payload..CustomerId , "application/json", {"indent": false}), "") ++ ")"
这是示例请求和响应。
你可以试试这个...
%dw 2.0
output application/json
---
"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN ('" ++
(payload.source.CustomerId as String default "")++ "', '" ++
(payload.destination.CustomerId as String default "") ++ "')"
使用输出 application/java 或 application/json 取决于您将使用它的功能。您面临的错误可能是由于您发送的空值所致。将其默认为 "" 将避免 dataWeave 失败。
此外,始终尝试将尽可能多的硬编码字符串值组合在一对 "" 中。
我正在使用 phpmyadmin 在线数据库。我已经应用 client_id 和 client_secret API 管理器安全并部署到 cloudhub。
最初,我能够获取或更新数据库中的数据,但在部署到 cloudhub 后,运行 在邮递员中出现以下错误。
它是一个 put 方法,有 body { “资源”: { “客户编号”:“5”, “姓名”:“山姆”
},
"destination":{
"CustomerId" : "4",
"Name" : "Jassie"
}
}
这是设置为变量的查询。 "SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ "'" ++ payload.source.CustomerId ++ "'" ++ "," ++ "'" ++ payload.destination.CustomerId ++ "'" ++ ")"
{ "message": ""org.mule.weave.v2.exception.UnexpectedFunctionCallTypesException: 你用这些参数调用了函数 '++': \n 1: String ("SELECT CustomerId,Country FROM Customers WHERE CustomerId IN ('")\n 2: Null (null)\n\nBut 它需要以下组合之一:\n (Array, Array)\n (Date, Time)\n (Date, LocalTime)\n (Date,时区)\n (LocalDateTime, TimeZone)\n (LocalTime, Date)\n (LocalTime, TimeZone)\n (Object, Object)\n (String, String)\n (Time, Date)\n (TimeZone, LocalDateTime )\n (TimeZone, Date)\n (TimeZone, LocalTime)\n\n6| "SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ "'" ++ payload.source.CustomerId++ "'" ++ "," ++ "'" ++ payload.destination.CustomerId++ "'" ++ ")"\n ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n跟踪:\n 在 ++(行:6 , 列: 1)\n at ++ (line: 6, column: 75)\n at ++ (line: 6, column: 103)\n at ++ (line: 6, column: 110)\n at ++ (line: 6, column: 117)\n at ++ (line: 6, column: 124)\n at ++ (line: 6, column: 157)\n at main (line: 6, col umn: 164)\n" 计算表达式: "%dw 2.0\noutput application/java\n---\n//"(" ++ "'" ++ payload.source.CustomerId++ " '" ++ "," ++ "'" ++ payload.destination.CustomerId++ "'" ++ ")"\n\n"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " + + "(" ++ "'" ++ payload.source.CustomerId++ "'" ++ "," ++ "'" ++ payload.destination.CustomerId++ "'" ++ ")""。 “ }
从问题来看,您似乎正在尝试从 CustomerId 构造查询,该查询可以包装在源或目标中。您的代码有一些 null "" 值,这在连接时是不可接受的。
以下是我将如何通过导入字符串模块构建 DW。
%dw 2.0
import unwrap from dw::core::Strings
output application/java
---
"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ unwrap(write(payload..CustomerId , "application/json", {"indent": false}), "") ++ ")"
这是示例请求和响应。
你可以试试这个...
%dw 2.0
output application/json
---
"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN ('" ++
(payload.source.CustomerId as String default "")++ "', '" ++
(payload.destination.CustomerId as String default "") ++ "')"
使用输出 application/java 或 application/json 取决于您将使用它的功能。您面临的错误可能是由于您发送的空值所致。将其默认为 "" 将避免 dataWeave 失败。
此外,始终尝试将尽可能多的硬编码字符串值组合在一对 "" 中。