mulesoft,如何将flowVars(String变量)转换为HashMap?

时间:2017-04-17 07:11:50

标签: mule

我正在尝试为HTTP请求设置有效负载,但是当我使用groovy脚本设置有效负载时,HTTP请求会引发错误:

ERROR 2017-04-17 12:24:12,260 [[test] .HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:     ************************************************** ******************************     消息:响应代码400映射为失败。     有效载荷:org.glassfish.grizzly.utils.BufferInputStream@6568a94e     元素:/ test / processors / 1/3 @ test:test.xml:59(HTTP)     元素XML:                             HTTP:要求建设者                                                                                                                         -------------------------------------------------- ------------------------------     根异常堆栈跟踪:     org.mule.module.http.internal.request.ResponseValidatorException:响应代码400映射为失败。

我的常规代码是:

   def values = payload.toString().split('\\|')
   message.setInvocationProperty('oauthBody',values[1]);

然后我正在使用flowVars设置有效负载:

#[flowVars.oauthBody]

如果我只是将有效负载字符串放在set payload中:它工作正常。

#[{'username':'test-admin','password':'Password1#','grant_type':'password','scope':'openid,profile,token,email,org'}]

但是当我使用groovy和flowVars时,它会给我一个错误。

如果我做错了,请告诉我。

1 个答案:

答案 0 :(得分:0)

从flowVar设置有效负载时,它包含一个String。

您的设置有效负载

#[{'username':'test-admin','password':'Password1#','grant_type':'password','scope':'openid,profile,token,email,org'}]

导致HashMap。

我不知道你是如何打电话给你的http服务(GET,POST,......)以及另一方面是什么。我想知道为什么它发送HashMap(之前没有将它转换为XML或JSON)。