How to get more information about dataweave exception in muleosft - mule

I am getting below dataweave exception while executing a mule flow :
"
INFO 2016-11-06 09:02:42,097 [[abc].HTTP_Listener_Configuration.worker.01] com.mulesoft.weave.mule.utils.MuleWeaveFactory$: MimeType was not resolved '*/*' delegating to Java.
ERROR 2016-11-06 09:02:42,290 [[abc].HTTP_Listener_Configuration.worker.01] org.mule.exception.CatchMessagingExceptionStrategy:
Message : Exception while executing:
"Response": {
^
Unexpected character '\u000a' at index 25 (line 2, position 24), expected '"'
Payload : test
Payload Type : java.lang.String
Element : /Process11/processors/9/1/9 # abc:def.xml:331 (TM_F1)
Element XML : <dw:transform-message doc:name="TM_F1">
<dw:set-payload>%dw 1.0%output application/json---{Data: [{// in_id : flowVars.instanceId,pd: '{AmIds:[{AmId:' ++ flowVars.AmId ++ '}]}'}]}</dw:set-payload>
</dw:transform-message>
Root Exception stack trace:
com.mulesoft.weave.reader.json.JsonReaderException: Unexpected character '\u000a' at index 25 (line 2, position 24), expected '"'
at com.mulesoft.weave.reader.json.JsonTokenizer.fail(JsonTokenizer.scala:193)
at com.mulesoft.weave.reader.json.JsonTokenizer.require(JsonTokenizer.scala:190)
at com.mulesoft.weave.reader.json.JsonTokenizer.readString(JsonTokenizer.scala:80)
"
Is there any possibility to enable more debug options to get more information about this particular exception so that it will be easy to find out the root cause.
The problem here is, even though i am not using the payload in transform message i am getting error because of the payload returned by the previous http call in muleflow.
Mule version is : studio 6.1 and runtime 3.8.
Please help me to solve this issue.
Thanks
sdg

This is not dataweave question. Exception what you have is from JsonReaderException:
com.mulesoft.weave.reader.json.JsonReaderException: Unexpected character '\u000a' at index 25 (line 2, position 24), expected '"'
It means that JSON what you provide has new line (\u000a) ate line 2 position 24. I imagine it is something like this:
"Response": {
"Message" : "67890123
456 the end"
}
Use special characters to represent new line in JSON.
"Response": {
"Message" : "67890123\n456 the end"
}

Enable info logs in log4j and enable debug logs at cloudhub if its an on cloud deployment.
Please Try validating the json as well

Debug is the best option to figure out these kind of errors. Also you may use the logger feature of dataweave to log specific values on console and see whats wrong with the value.

Related

Error propagation from system to process to experience APIs in Mule 4

The system API throws an error - ERROR:TYPE_1 with status code 401.
The process API should give the same error.
The experience API should give the same error.
How can this be achieved?
In the the process API you can write something like this
<flow name="error_flow">
<raise-error doc:name="raise-error" type="ERROR:TYPE_1" description="401 error ocurred">
<error-handler>
<on-error-continue enableNotification="true" type="ERROR:TYPE_1" doc:name ="on error continue" doc:id="on-error-continue">
// here you can write a dwl which gives you a payload like
// {
"errorCode" : 401
"errorType" : "ERROR:TYPE_1"
}
<on-error-continue>
</error-handler>
This payload will reach to your experience layer.

org.openqa.selenium.JavascriptException: javascript error: missing ) after argument list error when updating session storage key value using Selenium

If key value length is 11808 Unable to update session storage key value using selenium automation
Small length key values are setting but long length key values getting JS error
Manually it is working but using selenium automation getting JS error.
setItemInsessionStorage method using:
java.lang.AssertionError: org.openqa.selenium.JavascriptException: javascript error: missing ) after argument list
This error message...
java.lang.AssertionError: org.openqa.selenium.JavascriptException: javascript error: missing ) after argument list
...implies that there is a syntax error within the Javascript line of code.
A bit of more information about your usecase interms of your code block would have helped us to analyze the error in a better way. However in majority of the cases, this error is observed in the following cases:
Incase the " marks are not escaped properly. As an example:
onclick="(canLaunch('" + v.LibraryItemId + " '))"
^ escape character is missing
Ideally, the line should be:
onclick=\"(canLaunch('" + v.LibraryItemId + " '))\"
Incase the function() passed are not closed properly. As an example:
$(document).ready(function(){
}
Ideally, the line should be:
$(document).ready(function(){
});

If response contains the word 'any' then match response contains is failing

Let's say if I am having a scenario like
Scenario: Call a Get API and validate the response
Given path 'myteam'
When method get
Then status 201
And print response
And match response contains { teamFeature: 'pick any feature'}
And my API response is
{
"id": "6c0377cd-96c9-4651-bcc8-0c9a7d962bc3",
"teamFeature": "pick any feature"
}
Then I am getting the error like
example.feature:19 - javascript evaluation failed: feature'}, :1:9 Missing close quote
feature'}
^ in at line number 1 at column number 9
If my API response does not contain the word 'any' and I change the match statement then it is working fine. Looks like I need to escape the the word 'any' somehow.
May I know how can I escape the word 'any'?
Not sure if this is a bug in Karate.
Tried to call
com.intuit.karate.Match match = new com.intuit.karate.Match("pick any feature");
System.out.println(match.contains("pick any feature"));
And received following error
Exception in thread "main" java.lang.RuntimeException: javascript
evaluation failed: pick any feature, :1:5 Expected ; but found
any pick any feature
^ in at line number 1 at column number 5 at com.intuit.karate.ScriptBindings.eval(ScriptBindings.java:152) at
com.intuit.karate.ScriptBindings.updateBindingsAndEval(ScriptBindings.java:142)
at
com.intuit.karate.ScriptBindings.evalInNashorn(ScriptBindings.java:127)
at com.intuit.karate.Script.evalJsExpression(Script.java:423) at
com.intuit.karate.Script.evalKarateExpression(Script.java:337) at
com.intuit.karate.Script.evalKarateExpression(Script.java:203) at
com.intuit.karate.Match.(Match.java:67) at
com.intuit.karate.Match.(Match.java:53)
Yes this is a bug in Karate, we've opened an issue: https://github.com/intuit/karate/issues/678
The workaround suggested by #BabuSekaran will work:
* def response = { foo: 'a any b' }
* def temp = { foo: 'a any b' }
* match response contains temp

Mule flatten arrays with one of the arrays as null

I am learning mule4 and while trying out scatter-gather, i have run into an issue.
There are 3 flows in the scatter gather task, 2 of these flows return valid payload with data but the 3rd flow returns a empty payload.
thus when i am trying to flatten these 3 results , i am running into null pointer issue. i am not able to make out way to handle this. can anybody help please.
My dataweave expression is as below
%dw 2.0
output application/java
---
flatten(payload..payload)
logs
ERROR 2018-10-27 07:10:00,249 [[MuleRuntime].cpuLight.06: [apdev-flights-ws].getAllFlightsFlow.CPU_LITE #5abc6c4c] [event: ] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : "Unexpected end-of-input at payload#[1:1] (line:column), expected false or true or null or {...} or [...] or number but was , while reading `payload`as Json.
1|
^" evaluating expression: "%dw 2.0
output application/java
---
flatten(payload..payload) ".
Error type : MULE:EXPRESSION
Element : getAllFlightsFlow/processors/2 # apdev-flights-ws:implementation.xml:102 (Flatten)
Element XML : <ee:transform doc:name="Flatten" doc:id="46245fd1-5ebd-4b16-b83e-31ea4dbb53e8">
<ee:message>
<ee:set-payload>%dw 2.0
output application/java
---
flatten(payload..payload)</ee:set-payload>
</ee:message>
</ee:transform>
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
INFO 2018-10-27 07:10:00,323 [[MuleRuntime].cpuLight.06: [apdev-flights-ws].getAllFlightsFlow.CPU_LITE #5abc6c4c] [event: ] org.mule.runtime.core.internal.context.notification.Policy: NotificationListener com.mulesoft.mule.debugger.server.DebuggerPipelineMessageNotificationListener#20d9c50f was unable to fire notification PipelineMessageNotification{action=pipeline process complete, resourceId=getAllFlightsFlow, serverId=de-PC..apdev-flights-ws, timestamp=1540604400323} due to an exception: java.lang.NullPointerException.
I believe it's the payload..payload call that's messing you up. If you want to flatten the payload, it should just be:
%dw 2.0
output application/java
---
flatten(payload)

Mule: How to make sure payload is in writable state before doing file outbound

In my <catch-exception-strategy>, I write error payload to file. But sometimes when flow involves web-service calls and host is unavailable or unknown (for e.g. java.net.UnknownHostException is thrown), payload is not anymore an instance of InputStream or String. If I try to log error then to file, following exception is thrown:
exception.AbstractExceptionListener (AbstractExceptionListener.java:299) -
********************************************************************************
Message : Could not find a transformer to transform "SimpleDataType{type=org.apache.commons.httpclient.methods.PostMethod, mimeType='*/*'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}".
Code : MULE_ERROR-65237
--------------------------------------------------------------------------------
Exception stack is:
1. Could not find a transformer to transform "SimpleDataType{type=org.apache.commons.httpclient.methods.PostMethod, mimeType='*/*'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}". (org.mule.api.transformer.TransformerException)
org.mule.registry.MuleRegistryHelper:252 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=org.apache.commons.httpclient.methods.PostMethod, mimeType='*/*'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}".
at org.mule.registry.MuleRegistryHelper.lookupTransformer(MuleRegistryHelper.java:252)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:355)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:313)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
I am thinking of doing a choice block before writing to file to make sure payload is writable. Shall I do something like #[payload instanceof java.io.InputStream]? But then how about cases where payload is DOM or something else? Please advise.
I would use a transformer inside the catch exception strategy and encapsulate there the logic that would consider the input and produce a writable payload.
If you want to check whether there is a transformer available for a specific payload type and output type, I guess you could look up the available transformers from the registry. In Groovy:
transformers = message.getMuleContext().getRegistry().lookupTransformers(
new org.mule.transformer.types.SimpleDataType(payload.getClass()),
new org.mule.transformer.types.SimpleDataType(java.io.InputStream))
if (transformers.size() == 0) {
//set some variable or whatever
}