Mule 4 and Dataweave: how to omit stacktrace when using fail() from dw::Runtime - mule

I have a DataWeave message transformer, let's say:
%dw 2.0
import fail from dw::Runtime
output application/java
fun isValuePresent(value, message: String) = if ( value == null or isEmpty(value) ) fail(message) else value
---
{
brand: isValuePresent(payload.document[0].brand, p('import.error.missing.brand')),
...
I also have an error handler for this kind of errors.
Errors in Mule have their properties, like: description or detailedDescription.
Now normally, when I am catching other errors (like those from is true component) - everything is fine, error.description holds my error message, everything is fine.
But when an error produced by fail() is produced, I get a very big error description message:
""my error message here
Trace:
at fail (Unknown)
at isValuePresent (line: 13, column: 85)
at main (line: 23, column: 7)" evaluating expression: "%dw 2.0
import fail from dw::Runtime
output application/java
fun isValuePresent(value, message: String) = if ( value == null or isEmpty(value) ) fail(message) else value
---
{
brand: isValuePresent(payload.document[0].brand, p('import.error.missing.brand')),
...
...
etc, etc
It looks like the whole content of my dataweave script is added to the trace. And I just want to have:
my error message here
Trace:
at fail (Unknown)
at isValuePresent (line: 13, column: 85)
at main (line: 23, column: 7)" evaluating expression: "%dw 2.0
Is it possible to achieve this? Or I have I made some mistakes when designing this behaviour? Is there a way to fix this?

I don't think you can do anything about that. It is the way the error is reported with fail() and it is not customizable. Probably it depends on how DataWeave itself reports errors rather than fail() itself.

Related

Munit error while reading external DataWeave script into another file

I am setting up the structure for MUnit tests in our API and I am trying to do the following
folder structure :
src/test/munit
data.dwl
testdata/api-common/attributes.json
testdata/api-common/audit.json
testdata/api-common/common.dwl
testdata/getbalances/getbalancesrequest.json
testdata/getbalances/getbalancesresponse.json
testdata/getbalances/getbalancesrequest.json
testdata/getbalances/getbalancesdata.dwl
Sample dwl code as follows:
common.dwl
import getResourceAsString from MunitTools
var attributes = readUrl('classpath://testdata/api-
common.json')
var audit = readUrl('classpath://testdata/audit.json')
data.dwl
import getResourceAsString from MunitTools
var common = readUrl('classpath://testdata/api-common/common.dwl')
Way I use it inside set event:
<munit-tools:then-return>
<munit-tools:attributes value=“#[output application/java — data::common::attributes]” mediaType="application/java” encoding="UTF-8" />
</munit-tools:then-return>
But I am getting an exception like missing mapping expression var a= 1.
WARNING: Using Weave Reader at Runtime May Cause Performance Issues.
It is strongly advice to either use with onlydatastrue or try other
MimeType. This format was design for debugging and design only.
4444444++++++++***+*+***¢+++++++++++++++++++++++++++++++++++++++++++++++
org.mule.munit.runner. model. TestExecutionException: Error [MULE:
EXPRESSION] while running test 'credit-api-getBalances-test-suite'
:"Exception while reading classpath://testdata/cr...' as
'application/dw' cause by: Missing Mapping Expression ie. var a = 1 3|
var attributes = readur1('
classpath://testdata/credit-api-common/attributes.json") Trace: at
root::main (line: 3, column: 83) 4| var attributes = readur]('
classpath://testdata/credit-api -common/commonTestData.dwl')
ЛАЛЛЛЛЛЛЛАЛЛЛЛЛ. АЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛАЛЛЛЛЛЛАЛЛЛЛЛЛЛЛАЛЛЛЛЛЛЛЛЛЛЕ Trace:
at data:: readUrl (line: 4, column: 26) at data::main (line: 4,
column: 18)" evaluating expression: "output application/ java ...
data: :attributes" at org.mule.munit.runner.flow. TestFlow.
run(TestFlow. java: 320) at org.mule.munit.runner.model.Test.run(Test.
java:94) at org.mule.munit.runner .model.Suite.run (Suite. java: 112)
at org.mule.munit.runner. SuiteRunner. doRun(SuiteRunner. java:61) at
org.mule.munit. runner. SuiteRunner. run (SuiteRunner. java: 46) at
org.mule.munit. runner. remote.api. server. RunMessageHandler.
runSuite(RunMessageHandler. java: 99) at org.mule.munit. runner.
remote. api. server. RunMessageHandler. parseAndRun(RunMessageHandler.
java: 82) at org.mule.munit.runner. remote. api.server.
RunMessageHandler. handle (RunMessageHandler. java: 75) at
org.mule.munit.runner. remote. api. server. Runnerserver.
handleclientMes sage (RunnerServer. java:145) at org.mule.munit.runner
.remote.api.server. RunnerServer. run (RunnerServer. java:91) at
java.til.concurrent. Executors$RunnableAdapter. call (Executors. java:
511) at java.til.concurrent. FutureTask. run(FutureTask. java: 266) at
org. mule.service.scheduler.
internal.AbstractrunnableFutureDecorator.doRun(AbstractRunnableFutureDecorator.java:113)
at org.mule. service. scheduler. internal. RunnableFutureDecorator.
run(RunnableFutureDecorator. java: 54) at java.til.concurrent.
ThreadPoolExecutor. runworker (IhreadPoolExecutor. java: 1149) at
java.til. concurrent.
ThreadPoolExecutor$worker.run(IhreadPoolExecutor.java:624) at java.
lang. Thread. run (Thread. java: 748) Caused by:
lava.til.concurrent.ExecutionException:
org.mule.runtime.api.component.execution. ComponentExecu Missing
Mapping Expression ie, var a ionException: org.mule.
runtime.core.api.expression. ExpressionRuntimeException: "Exception
while reading 'classpath:// 31 var attributes =
readur](classpath://testdata/credit-api-common/attributes.json')
Trace: at root: :main (line: 3, column: 83) 4| var attributes =
readUr](' classpath://testdata/credit-api-common/commonTestData.dwl')
лллллЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛллЛЛЛллллл Trace: at
data::readUrl (line: 4, column: 26) at data: :main (line: 4, column:
18)" evaluating expression: "output application/ java ---
data::attributes". at
java.util.concurrent.CompletableFuture.reportet(CompletableFuture.java:357)
at
java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1908)
at org.mule.munit.runner. flow.
TestFlow$ExceptionAwareCallable.call(TestFlow. java: 384) at org.
mule.munit.runner. flow.
TestFlow$ExceptionAwareCallable.call(TestFlow.java:373) 6 more Caused
by: org.mule.runtime.api.component.
execution.ComponentExecutionException: org.mule.runtime.core. Missing
Mapping Expression 1e. var a = exception: "Exception while reading
'classpath://testdata/cr. as 'application/dw' cause by: 3| var
attributes =
readUr](classpath://testdata/credit-api-common/attributes.json") race:
at root: :main (line: 3, column: 83) 4| var attributes =
readUr]('classpath://testdata/credit-api-common/commonTestData.dwl')
алАлАЛАЛЛЛАЛАЛлЛЛЛЛАЛАЛлЛАЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛЛАЛАлЛлАЛЛ Trace: at
data: :readUrl (line: 4, column: 26) at data::main (line: 4, column:
18)" evaluating expression: "output application/java ... data:
:attributes". Caused by:
org.mule.runtime.core.api.expression.ExpressionRuntimeException:
"Exception while reading classpath://testdata/cr... 'application/dw'
cause by:
Could you please help me how to fix this and what I am doing wrong?
Try telling readUrl() that you are actually trying to reading a JSON file by using its second argument 'contentType'.
Example:
var audit = readUrl('classpath://testdata/audit.json', 'application/json')

Cannot coerce String { class: java.lang.String }

I am trying to send email from the flow and stored all the email addresses in the yaml file like below
# Email
email:
toEmail: "abc.123#gg.org,def.456#gg.org"
fromEmail: "ms-dev#gg.org"
ccAddress: "abc123#gmail.com"
I am trying use the above values in to the send email connector like
<email:send doc:name="Send" doc:id="fd09c56f-eaed-44c4-ab06-aa0417f2fdbf" config-ref="Email_SMTP" subject="Error with SOW integration between D365 and Salesforce " fromAddress='#[p("email.fromEmail")]' toAddresses='#[p("email.toEmail") splitBy ","]' ccAddresses='#[p("email.ccAddress")]'>
<email:body contentType="text/html">
<email:content ><![CDATA[#[vars.emailBody]]]></email:content>
</email:body>
</email:send>
But when debugging Iam getting the error like below
org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : "Cannot coerce String { class: java.lang.String } ("abc123#gmail.com" as String {class: "java.lang.String"}) to Array" evaluating expression: "p("email.ccAddress")".
Element : salesforce-proc-SendEmail_Flow/processors/1 # salesforce-proc:salesforce-proc-implementation.xml:566 (Send)
Element DSL : <email:send doc:name="Send" doc:id="fd09c56f-eaed-44c4-ab06-aa0417f2fdbf" config-ref="Email_SMTP" subject="Error with SOW integration between D365 and Salesforce " fromAddress="#[p("email.fromEmail")]" toAddresses="#[p("email.toEmail") splitBy ","]" ccAddresses="#[p("email.ccAddress")]">
<email:body contentType="text/html">
<email:content><![CDATA[
#[vars.emailBody]
]]></email:content>
</email:body>
</email:send>
Error type : MULE:EXPRESSION
FlowStack : at salesforce-proc-SendEmail_Flow(salesforce-proc-SendEmail_Flow/processors/1 # salesforce-proc:salesforce-proc-implementation.xml:566 (Send))
at listener-flow(listener-flow/errorHandler/0/processors/2 # salesforce-proc:salesforce-proc-implementation.xml:547 (Flow Reference))\
After fixing ccAddresses error I get below error
caf9-11ec-b461-025041000001] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : Error while sending email: Exception reading response
Element : salesforce-proc-SendEmail_Flow/processors/1 # salesforce-proc:salesforce-proc-implementation.xml:566 (Send)
Element DSL : <email:send doc:name="Send" doc:id="fd09c56f-eaed-44c4-ab06-aa0417f2fdbf" config-ref="Email_SMTP" subject="Error with SOW integration between D365 and Salesforce " fromAddress="#[p("email.fromEmail")]" toAddresses="#[p("email.toEmail") splitBy ","]" ccAddresses="#[p("email.ccAddress") splitBy ","]">
<email:body contentType="text/html">
<email:content><![CDATA[
#[vars.emailBody]
]]></email:content>
</email:body>
</email:send>
Error type : EMAIL:SEND
FlowStack : at salesforce-proc-SendEmail_Flow(salesforce-proc-SendEmail_Flow/processors/1 # salesforce-proc:salesforce-proc-implementation.xml:566 (Send))
at listener-flow(listener-flow/errorHandler/0/processors/2 # salesforce-proc:salesforce-proc-implementation.xml:547 (Flow Reference))
Can anyone please suggest what is that I am missing here.
The problem is that ccAddresses expects an array. Because you are using an expression to configure that attribute you need to convert the string value from the configuration file explicitly to an array, for example using the splitBy() function as you did in toAddresses.
Or if you will only use one address simply remove the expression and use a property placeholder (ccAddresses="${email.ccAddress}").

Thymeleaf: "Exception evaluating OGNL expression" in a simple for loop

I have this controller:
it.render(
"my-list.html",
mapOf(
"votes-positive" to repo.votesOf("x"),
)
)
//...
data class Vote(
val name: String,
val type: Type,
) {
enum class Type { POS, NEG }
}
my template file "my-list.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div th:each="vote : ${votes-positive}">
<span th:text="${vote.name}"></span>
</div>
</body>
I'm getting this error when running it, which is driving me crazy:
[qtp119358627-23] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][qtp119358627-23] Exception processing template "my-list.html": Exception evaluating OGNL expression: "vote.name" (template: "my-list.html" - line 21, col 15)
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating OGNL expression: "vote.name" (template: "my-list.html" - line 21, col 15)
Is there a Thymleaf debug mode? Is there a way to print the model tree? I don't know why the expression is wrong.
Try changing votes-positive to something which does not use a hyphen. That is interpreted as a minus sign inside an OGNL subtraction expression.

Mule 4, get uri params with Anypoint application

I'm new in Mulesoft, I'm following Quickstart guide. In Step 2 (https://developer.mulesoft.com/guides/quick-start/developing-your-first-mule-application), I need to receive variables from URI in this way:
[{'id' : attributes.uriParams.productId}]
But when I try my GET I have the following error in console:
**Message : "Cannot coerce Array ([{id: "2" as String {class: "java.lang.String"}}]) to Object 1| [{'id' : attributes.uriParams.productId}] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trace: at main (line: 1, column: 1)" evaluating expression: "[{'id' : attributes.uriParams.productId}]". Error type : MULE:EXPRESSION Element : get:\products(productId):test_daniel-config/processors/1 # test6_db_connection:test_daniel.xml:133 (Select) Element XML : SELECT product.,CONCAT('["', (GROUP_CONCAT(variant.picture SEPARATOR '","')),'"]') AS pictures,CONCAT('[', GROUP_CONCAT('{"',variant.identifierType, '":"', variant.identifier, '"}'),']') AS identifiersFROM product INNER JOIN variant ON product.uuid = variant.productUUIDWHERE product.uuid = :id; #[[{'id' : attributes.uriParams.productId}]] *
Any Ideas? Thanks!
cannot coerce Array to object error pop's up when you are using an array where you were supposed to use an object.
in the exception above the uri-param should be treated as ab object i.e. enclosed in {} but its being treated as an array of objects [{}].
this is causing the error.

Error thrown while using datamapper to map date in Mule

Below is the portion of the mapping in data mapper
dateTimeFormatter = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
output.Date_of_Rate_Float__c = (isnull(input.Date_of_Rate_Float) ? null : dateTimeFormatter.format(input.Date_of_Rate_Float));
output.Loan_Create_Date__c = (isnull(input.loan_create_date) ? null : dateTimeFormatter.format(input.loan_create_date));
output.Estimated_Closing_Date__c = (isnull(input.estimated_closing_date) ? null : dateTimeFormatter.format(input.estimated_closing_date));
this throws the below exception
1. DateConverter does not support default String to 'Date' conversion. (org.apache.commons.beanutils.ConversionException)
org.apache.commons.beanutils.converters.DateTimeConverter:468 (null)
Root Exception stack trace:
org.apache.commons.beanutils.ConversionException: DateConverter does not support default String to 'Date' conversion.
at org.apache.commons.beanutils.converters.DateTimeConverter.toDate(DateTimeConverter.java:468)
at org.apache.commons.beanutils.converters.DateTimeConverter.convertToType(DateTimeConverter.java:343)
at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:156)
at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:544)
at com.mulesoft.datamapper.transform.converter.ScalarValueConversion.convert(ScalarValueConversion.java:126)
at com.mulesoft.datamapper.transform.DataRecordContext.put(DataRecordContext.java:87)
at com.mulesoft.datamapper.transform.DataRecordContext.put(DataRecordContext.java:24)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeSetAccessor(ReflectiveAccessorOptimizer.java:308)
at org.mvel2.compiler.CompiledAccExpression.setValue(CompiledAccExpression.java:54)
at org.mvel2.ast.DeepAssignmentNode.getReducedValueAccelerated(DeepAssignmentNode.java:92)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
at org.mvel2.MVEL.executeExpression(MVEL.java:942)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:50)
at com.mulesoft.datamapper.transform.DataMapperExpressionLanguage.evaluate(DataMapperExpressionLanguage.java:106)
at com.mulesoft.datamapper.transform.MelRecordTransform.transform(MelRecordTransform.java:56)
at org.jetel.component.Reformat.execute(Reformat.java:273)
at org.jetel.graph.Node.run(Node.java:465)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
********************************************************************************
I'am unable to find as what is causing this exception, I would like to seek help in resolving this issue.
Thank you in advance
It looks like a null value is being passed to the format method. To see how you can make it "null safe" you can look at the example at Format a Date, allowing null