Mulesoft: Default value for not existing deep nodes - mule

I use Data Weave to transform XML and have issue with not existing nodes. For example xml
<a>
<b>
<c>
value
</c>
</b>
</a>
Extracted { one: $.a, two: $a.b, three: $a.b.c } It works fine when all nodes a,b and c exist.
What would be the way to determine when node b is empty and have default value for node c?
This is really simply example. Real data has a lot of deepness levels and each level could be empty. Maybe I should use when/otherwise but then I should repeat whole data structure for each variable.
Here is Mule flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<flow name="xml2flatFlow" doc:description="To run copy src/main/resources/*.xml files to src/test/resources/FileIn
Good working example is xml_in_good.xml
Issues:
1) Should be working with Streams but from Json2Flat there is no way to FileOut. "Load everything to memory" is required but it kills stream. What is the way to make it Stream and work with huge files?
2) FlatFile field have particular length. Transformation should cut the length. Instead it produces exception. Should be option oe way to force the length of the string.
Example: xml_in_bad_too_long.xml
3) Main issue - I cannot figure out how process empty nodes.
Example: xml_in_bad.xml
Provided example is simlpiest. In reality I have very long xpath like payload.a.b.c.d.e.f.g.h
I tried to do when/otherwise, default, h?, internal Java program - nothing works.
I believe that processor File2Json is not necessary but I'd added it to make sure XML processor have no influence on the flow. ">
<file:inbound-endpoint path="src\test\resources\FileIn" moveToDirectory="src\test\resources\FileProcessed" responseTimeout="10000" doc:name="FileIn"/>
<dw:transform-message metadata:id="24cbc998-ba7d-44f7-a3fa-cb502d352e87" doc:name="File2Json">
<dw:input-payload mimeType="application/xml"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload]]></dw:set-payload>
</dw:transform-message>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<dw:transform-message metadata:id="15c2b229-fb5a-4430-be89-c446e79bfa2e" doc:name="Json2Json">
<dw:input-payload doc:sample="C:\Users\Alex\AnypointStudio6\workspace\xml2flat\src\main\resources\too_long.json" mimeType="application/json"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
a: payload.a default {},
b: payload.a.b default {},
c: payload.a.b.c default ""
}]]></dw:set-payload>
</dw:transform-message>
<dw:transform-message metadata:id="8ef7c277-ec47-4564-9ece-eac11c27c891" doc:name="Json2Flat">
<dw:input-payload doc:sample="C:\Users\Alex\AnypointStudio6\workspace\xml2flat\src\main\resources\too_long.json"/>
<dw:set-payload><![CDATA[%dw 1.0
%output text/plain schemaPath = "flatfile.ffd" , segmentIdent = ""
---
[{
field_0: payload.c default "---"
}]]]></dw:set-payload>
</dw:transform-message>
<object-to-string-transformer doc:name="Load everythin to memory"/>
<file:outbound-endpoint path="src/test/resources/FileOut" outputPattern="out.txt" responseTimeout="10000" doc:name="FileOut"/>
</flow>
</mule>
Here is log:
*******************************************************************************************************
* xml2flatSO * default * DEPLOYED *
*******************************************************************************************************
INFO 2016-09-30 13:57:29,271 [[xml2flatSO].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\Users\Alex\AnypointStudio6\workspace\xml2flatSO\src\test\resources\FileIn\xml_in_good.xml
INFO 2016-09-30 13:57:37,892 [[xml2flatSO].xml2flatFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: {
"a": {
"b": {
"c": "GOOD"
}
}
}
INFO 2016-09-30 13:57:42,334 [[xml2flatSO].connector.file.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.file.mule.default.dispatcher.546298364'. Object is: FileMessageDispatcher
INFO 2016-09-30 13:57:42,334 [[xml2flatSO].connector.file.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.file.mule.default.dispatcher.546298364'. Object is: FileMessageDispatcher
INFO 2016-09-30 13:57:42,335 [[xml2flatSO].connector.file.mule.default.dispatcher.01] org.mule.transport.file.FileConnector: Writing file to: C:\Users\Alex\AnypointStudio6\workspace\xml2flatSO\src\test\resources\FileOut\out.txt
INFO 2016-09-30 13:57:52,448 [[xml2flatSO].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\Users\Alex\AnypointStudio6\workspace\xml2flatSO\src\test\resources\FileIn\xml_in_bad.xml
INFO 2016-09-30 13:57:55,979 [[xml2flatSO].xml2flatFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: {
"a": ""
}
ERROR 2016-09-30 13:58:16,403 [[xml2flatSO].xml2flatFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Exception while executing:
b: payload.a.b default {},
^
Type mismatch for 'Value Selector' operator
found :string, :name
required :datetime, :name or
required :localdatetime, :name or
required :object, :name or
required :time, :name or
required :array, :name or
required :date, :name or
required :localtime, :name or
required :period, :name
Payload : {
"a": ""
}
Payload Type : java.lang.String
Element : /xml2flatFlow/processors/3 # xml2flatSO:xml2flat.xml:37 (Json2Json)
Element XML : <dw:transform-message metadata:id="15c2b229-fb5a-4430-be89-c446e79bfa2e" doc:name="Json2Json">
<dw:input-payload doc:sample="C:\Users\Alex\AnypointStudio6\workspace\xml2flat\src\main\resources\too_long.json" mimeType="application/json"></dw:input-payload>
<dw:set-payload>%dw 1.0%output application/json---{a: payload.a default {},b: payload.a.b default {},c: payload.a.b.c default ""}</dw:set-payload>
</dw:transform-message>
--------------------------------------------------------------------------------
Root Exception stack trace:
com.mulesoft.weave.engine.ast.dynamic.UnexpectedOperationTypesException: Type mismatch for 'Value Selector' operator
found :string, :name
required :datetime, :name or
required :localdatetime, :name or
required :object, :name or
required :time, :name or
required :array, :name or
required :date, :name or
required :localtime, :name or
required :period, :name
at com.mulesoft.weave.engine.ast.OpNode$class.doExecuteAutoCoercion(OpNode.scala:79)
at com.mulesoft.weave.engine.ast.BinaryOpNode.doExecuteAutoCoercion(BinaryOpNode.scala:8)
at com.mulesoft.weave.engine.ast.OpNode$class.doExecute(OpNode.scala:33)
at com.mulesoft.weave.engine.ast.BinaryOpNode.doExecute(BinaryOpNode.scala:8)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.BinaryOpNode.execute(BinaryOpNode.scala:8)
at com.mulesoft.weave.engine.ast.selectors.NullSafeNode.doExecute(NullSafeNode.scala:16)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.selectors.NullSafeNode.execute(NullSafeNode.scala:10)
at com.mulesoft.weave.engine.ast.conditional.DefaultNode.doExecute(DefaultNode.scala:13)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.conditional.DefaultNode.execute(DefaultNode.scala:10)
at com.mulesoft.weave.engine.ast.structure.KeyValuePairNode.doExecute(KeyValuePairNode.scala:12)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.structure.KeyValuePairNode.execute(KeyValuePairNode.scala:10)
at com.mulesoft.weave.engine.ast.structure.ObjectNode$$anonfun$4.apply(DynamicObjectNode.scala:39)
at com.mulesoft.weave.engine.ast.structure.ObjectNode$$anonfun$4.apply(DynamicObjectNode.scala:38)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.Iterator$class.foreach(Iterator.scala:742)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1194)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at com.mulesoft.weave.engine.ast.structure.ObjectNode.doExecute(DynamicObjectNode.scala:38)
at com.mulesoft.weave.engine.ast.ValueNode$class.execute(AstNode.scala:38)
at com.mulesoft.weave.engine.ast.structure.ObjectNode.execute(DynamicObjectNode.scala:28)
at com.mulesoft.weave.engine.ast.ValueNode$class.write(AstNode.scala:28)
at com.mulesoft.weave.engine.ast.structure.ObjectNode.write(DynamicObjectNode.scala:28)
at com.mulesoft.weave.engine.Engine.write(Engine.scala:165)
at com.mulesoft.weave.engine.Engine.execute(Engine.scala:88)
at com.mulesoft.weave.engine.Engine.execute(Engine.scala:103)
at com.mulesoft.weave.mule.debug.DebugWeaveExecutorStrategy$$anonfun$execute$1.apply(DebugWeaveExecutorStrategy.scala:30)
at com.mulesoft.weave.mule.debug.DebugWeaveExecutorStrategy$$anonfun$execute$1.apply(DebugWeaveExecutorStrategy.scala:28)
at scala.Option.map(Option.scala:146)
at com.mulesoft.weave.mule.debug.DebugWeaveExecutorStrategy.execute(DebugWeaveExecutorStrategy.scala:28)
at com.mulesoft.weave.mule.WeaveMessageProcessor.execute(WeaveMessageProcessor.scala:117)
at com.mulesoft.weave.mule.WeaveMessageProcessor.process(WeaveMessageProcessor.scala:65)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:108)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:88)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.interceptor.AbstractEnvelopeInterceptor.processBlocking(AbstractEnvelopeInterceptor.java:58)
at org.mule.processor.AbstractRequestResponseMessageProcessor.process(AbstractRequestResponseMessageProcessor.java:47)
at org.mule.processor.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:123)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:208)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:201)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:35)
at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:22)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:67)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:110)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:200)
at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:53)
at org.mule.work.WorkerContext.run(WorkerContext.java:286)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
********************************************************************************
Any suggestion?

you can use default keyword something like
%dw 1.0
%output application/json
---
{ one: payload.a,
two: payload.a.b default "y",
three: payload.a.b.c default "x"
}
Input:-
<a>
<c>value</c>
</a>
Output
{
"one": {
"c": "value"
},
"two": "y",
"three": "x"
}
Hope this helps.

I had open issue case with Mulesoft and they provided this suggestion which works.
Some property should be added to Dataweave then it works as desired.
<dw:reader-property name="nullValueOn" value="blank" />
All three cases do work no matter how much data is provided a.b.c or a.b or a or nothing at all.
%dw 1.0
%output application/json
---
{ one: payload.a,
two: payload.a.b default "y",
three: payload.a.b.c default "x"
}

Related

Can't do validation because mule doesn't see payload

I'm trying to use validation connector to check value field for outcome "good" or "bad". Even if they are written in capital letters. The issue is when I use the validation connector to check payload.value it shows null. This is not the case when I debug on payload that shows the full payload. How can I solve it?
I have my xml code below:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:validation="http://www.mulesoft.org/schema/mule/validation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
---
{Service: {
Id: "N2K99",
Value: "good"
}
}]]></dw:set-payload>
</dw:transform-message>
<validation:matches-regex value="#[payload.Service.Value]" regex="^(good|bad)" doc:name="Validate good or bad string"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
succes: hallo
}]]></dw:set-payload>
</dw:transform-message>
</flow>
</mule>
Error:
Message : Execution of the expression "payload.Service.Value" failed. (org.mule.api.expression.ExpressionRuntimeException).
Payload : <?xml version='1.0' encoding='UTF-8'?>
<Service>
<Id>N2K99</Id>
<Value>good</Value>
</Service>
Element : /testFlow/processors/1 # so-validate-regex
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.NullPointerException
at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:440)
at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:212)
at org.mule.mvel2.ast.ASTNode.optimize(ASTNode.java:160)
at org.mule.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:116)
at org.mule.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
at org.mule.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mule.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mule.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
at org.mule.mvel2.MVEL.executeExpression(MVEL.java:953)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:87)
at org.mule.el.mvel.MVELExpressionLanguage.evaluateInternal(MVELExpressionLanguage.java:228)
at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:163)
at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:142)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:217)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:188)
at org.mule.util.AttributeEvaluator.resolveValue(AttributeEvaluator.java:124)
at org.mule.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver$PassThroughEvaluatorDelegate.resolveValue(TypeSafeExpressionValueResolver.java:147)
at org.mule.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver$CaptureContextEvaluatorDelegate.resolveValue(TypeSafeExpressionValueResolver.java:137)
...
The problem that you are having is because the first DataWeave transformation -which I understand is used to mock the input- returns an XML string. This is Mule 3 so the validation uses a MEL expression to try to evaluate its input #[payload.Service.Value]. MEL doesn't know how to parse the XML so it fails with an error.
To resolve the issue you need only to transform the input into a Java object that MEL can evaluate. For example putting this transformation between the first Transform and the validate resolves the issue:
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload
]]>
</dw:set-payload>
</dw:transform-message>

Mule 4 - Create WSDL web service using Anypoint studio 7

I already read the documentation about the new way to create soap web service using newest mule (https://docs.mulesoft.com/apikit/4.x/apikit-4-soap-prerequisites-task), but it doesn't really help.
Because I try to do following, using that tutorial as example, when user enter the name, the size, the email and send the request in OrderTshirt function, my flow will call method in a java class, probably int OrderTShirt.order(String input) where input concat all the name, size, and email information, and return back the orderId, and submit back to the response to user. How I can approach this?
Here is the code that what I have right now, but I don't know how to use that datawave component really well, can someone give me an example for that?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit-soap="http://www.mulesoft.org/schema/mule/apikit-soap" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/apikit-soap http://www.mulesoft.org/schema/mule/apikit-soap/current/mule-apikit-soap.xsd http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<http:listener-config name="api-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="9999"/>
</http:listener-config>
<apikit-soap:config name="soapkit-config" port="TshirtServicePort" service="TshirtService" wsdlLocation="Tshirt2.wsdl"/>
<flow name="api-main">
<http:listener config-ref="api-httpListenerConfig" path="/TshirtService/TshirtServicePort">
<http:response>
<http:body>#[payload]</http:body>
<http:headers>#[attributes.protocolHeaders default {}]</http:headers>
</http:response>
<http:error-response>
<http:body>#[payload]</http:body>
<http:headers>#[attributes.protocolHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit-soap:router config-ref="soapkit-config">
<apikit-soap:message>#[payload]</apikit-soap:message>
<apikit-soap:attributes>#[
%dw 2.0
output application/java
---
{
headers: attributes.headers,
method: attributes.method,
queryString: attributes.queryString
}]</apikit-soap:attributes>
</apikit-soap:router>
</flow>
<flow name="OrderTshirt:\soapkit-config" doc:id="969489c2-709c-43b7-915c-cc92d9f3c8c9">
<ee:transform doc:name="Transform Message" doc:id="5771f4b9-0060-4658-aa8a-fee10efc02c5" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/java
ns ns0 http://schemas.xmlsoap.org/soap/envelope
---
{
body:{
ns0#orderTshirtResponse:{
orderId:"10"
}
} write "application/xml"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
<flow name="ListInventory:\soapkit-config">
<ee:transform doc:id="431ad9c7-f0bf-4b32-88bc-bbe8c6815317">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
ns soap http://schemas.xmlsoap.org/soap/envelope
---
{
body: {
soap#Fault: {
faultcode: "soap:Server",
faultstring: "Operation [ListInventory:\soapkit-config] not implemented"
}
} write "application/xml"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
<flow name="TrackOrder:\soapkit-config">
<ee:transform doc:id="a09a0cc3-f28a-49aa-bb32-77368340a522">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
ns soap http://schemas.xmlsoap.org/soap/envelope
---
{
body: {
soap#Fault: {
faultcode: "soap:Server",
faultstring: "Operation [TrackOrder:\soapkit-config] not implemented"
}
} write "application/xml"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>

Dataweave Error: You called the function 'Value Selector' with these arguments when converting Excel to JSON

I am using Anypoint 7 and Mule 4.1.
I want to read an Excel (xlsx) file from a folder on my computer and convert it into JSON but I am receiving the error:
You called the function 'Value Selector' with these arguments:
which I think is down to streaming but not sure how to fix it.
Thanks for any help
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:ftp="http://www.mulesoft.org/schema/mule/ftp"
xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/ftp http://www.mulesoft.org/schema/mule/ftp/current/mule-ftp.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<flow name="testFlow" doc:id="3030b14f-b215-4c85-a6a4-96236516c552" >
<scheduler doc:name="Scheduler" doc:id="d0985a96-a23c-4e2c-80ae-d78a9acd938e" >
<scheduling-strategy >
<fixed-frequency timeUnit="SECONDS"/>
</scheduling-strategy>
</scheduler>
<file:read doc:name="Read xlsx file" doc:id="90b40273-ec58-47de-a48b-9812c52a74ea" path="C:\apps\test-api\src\test\resources\input\myTestExcelFile.xlsx" config-ref="File_Config">
<ee:repeatable-file-store-stream />
</file:read>
<ee:transform doc:name="Transform Message" doc:id="36dbec15-6e02-4fdf-8176-025ad7fdce61" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
input payload application/xlsx
output application/json
---
payload.CUSTOMER map ( cUSTOMER , indexOfCUSTOMER ) -> {
custId: cUSTOMER."Customer Code" default "",
custName: cUSTOMER.Name default ""
}
]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Log Message" doc:id="5142b6ff-9d04-4cb2-ba3b-7fec5e52dd9b" message='#[payload]' category="com.test"/>
</flow>
</mule>
ERROR MESSAGE
ERROR 2018-08-03 11:03:34,628 [[MuleRuntime].cpuLight.02: [test-api].testFlow.CPU_LITE #75c313f3] [event: 0-7a8a0890-9704-11e8-900d-a44cc83a8228] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : "You called the function 'Value Selector' with these arguments:
1: Binary
2: Name ("CUSTOMER")
But it expects one of these combinations:
(Array, Name)
(Array, String)
(Date, Name)
(DateTime, Name)
(LocalDateTime, Name)
(LocalTime, Name)
(Object, Name)
(Object, String)
(Period, Name)
(Time, Name)
5| payload.CUSTOMER map ( cUSTOMER , indexOfCUSTOMER ) -> {
^^^^^^^^^^^^^^^^
Trace:
at map (line: 5, column: 1)
at main (line: 5, column: 18)" evaluating expression: "%dw 2.0
input payload application/xlsx
output application/json
---
payload.CUSTOMER map ( cUSTOMER , indexOfCUSTOMER ) -> {
custId: cUSTOMER."Customer Code" default "",
custName: cUSTOMER.Name default ""
}
".
Error type : MULE:EXPRESSION
Element : testFlow/processors/1 # test-api:test.xml:21 (Transform Message)
Element XML : <ee:transform doc:name="Transform Message" doc:id="36dbec15-6e02-4fdf-8176-025ad7fdce61">
<ee:message>
<ee:set-payload>%dw 2.0
input payload application/xlsx
output application/json
---
payload.CUSTOMER map ( cUSTOMER , indexOfCUSTOMER ) -> {
custId: cUSTOMER."Customer Code" default "",
custName: cUSTOMER.Name default ""
}</ee:set-payload>
</ee:message>
</ee:transform>
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
XLSX file
I found that the problem was that I had not set the MIME type on the File connector to application/xlsx
Once I set this, it worked.
In my case I had an uri parameter in the "https request" component sent to sap odata and this led to above errors.
After canceling MIME settings (plain/text) to none the errors were gone.
Thank you for this hint!! I spent a very long time husseling with that and now it works fine :-)

Malformed ERR segments in ACK generated by HL7 EDI connector

I am working on a simple app that receives HL7 messages and returns an HL7 ACK. I started the implementation using the example found here: Acknowledgement example in HL7 DataWeave Examples section
When testing the example code, the ACKs are fine if there are no errors in the HL7, but when there are any errors in parsing the HL7 the ERR segments contain no fields:
MSH|^~\'|LABADT|MCM|ADT1|MCM|198808181126|SECURITY|ACK^A01^ACK|MSG00001-|P|2.6
MSA|AE|MSG00001-
ERR
Also the following warnings are found in the log:
WARN 2018-03-28 10:01:13,110 [[hl7ack].HTTP_Listener_Configuration.worker.01]
com.mulesoft.flatfile.1.3.0.lib.schema.hl7.HL7SchemaWriter: missing required value for component ERR-03: 'HL7 Error Code' for segment ERR at index 2
WARN 2018-03-28 10:01:13,110 [[hl7ack].HTTP_Listener_Configuration.worker.01]
com.mulesoft.flatfile.1.3.0.lib.schema.hl7.HL7SchemaWriter: missing required value for component ERR-04: 'Severity' for segment ERR at index 2
It seems like the schema of the ERR segment generated by the HL7 EDI transformer component does not match the default HL7 schema. Is there something that I am doing wrong? I tried including the ACK schema in the HL7 config, but had the same problem.
Below is Mule app code (same as example):
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp"
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:hl7-edi="http://www.mulesoft.org/schema/mule/hl7-edi"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd http://www.mulesoft.org/schema/mule/tcp
http://www.mulesoft.org/schema/mule/tcp/current/mule-tcp.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/hl7-edi
http://www.mulesoft.org/schema/mule/hl7-edi/current/mule-hl7-edi.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw
http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/ee/tracking
http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8080" doc:name="HTTP Listener Configuration"/>
<hl7-edi:config name="HL7_EDI__Configuration" identKeys="true" doc:name="HL7 EDI: Configuration">
<hl7-edi:schemas>
<hl7-edi:schema>hl7/v2_6/ADT_A01.esl</hl7-edi:schema>
</hl7-edi:schemas>
</hl7-edi:config>
<flow name="Acknowledgment">
<http:listener config-ref="HTTP_Listener_Configuration" path="/ack" allowedMethods="POST" doc:name="HTTP"/>
<hl7-edi:read config-ref="HL7_EDI__Configuration" doc:name="HL7 EDI"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
Name: "ACK",
MSH: payload.ACK.MSH,
Id: "ACK",
Data: {
ACK: payload.ACK
}
}]]></dw:set-payload>
</dw:transform-message>
<hl7-edi:write config-ref="HL7_EDI__Configuration" messageStructure="InMessage" doc:name="HL7 EDI"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
The ACK generated by the HL7 EDI component does not match the HL7 schema. Specifically the ERR structure does not contain the ERR-01 list. I used the following transform (in place of the simple transform above) to generate the correct acknowledgement.
%dw 1.0
%output application/java
---
{
Id: "ACK",
Name: "ACK",
MSH: payload.ACK.MSH,
Data: {
ACK: {
MSH: payload.ACK.MSH,
MSA: payload.ACK.MSA,
ERR: [{
ERR-01: (payload.ACK.ERR map ((eRR , indexOfERR) -> {
ERR-01-01: eRR.ERR-01-01,
ERR-01-02: eRR.ERR-01-02,
ERR-01-03: eRR.ERR-01-03,
ERR-01-04-01: eRR.ERR-01-04-01,
ERR-01-04-02: eRR.ERR-01-04-02,
ERR-01-04-03: eRR.ERR-01-04-03
}))
}]
}
}
}

MULE example: Sending a CSV file through Email using SMTP

Hej,
I'm new in MULE, I try to learn "how to" following examples from Mule's sida: https://www.mulesoft.com/exchange#!/sending-csv-email-smtp?searchTerm=email
I think I did everything well, project is deploing good, but when file is taken exception is thrown and I'v got communicate:
Exception stack is:
1. Cannot coerce a :binary to a :array (com.mulesoft.weave.model.values.coercion.exception.UnsupportedTypeCoercionException)
com.mulesoft.weave.model.values.formatting.ArrayFormatTypeCoercionValue:31 (null)
2. Exception while executing:
payload map {
^
Cannot coerce a :binary to a :array (com.mulesoft.weave.mule.exception.WeaveExecutionException)
com.mulesoft.weave.mule.WeaveMessageProcessor:124 (null).
Abybody have idea what's happened. Anybody had same problem with that example?
Use the following mimeType in your DataWeave :- <dw:input-payload doc:sample="list_csv.csv" mimeType="application/csv"/>
So, the full code will be some thing like as follows:-
<smtp:gmail-connector doc:name="Gmail" name="Gmail" validateConnections="true"/>
<flow name="csv-to-smtpFlow">
<file:inbound-endpoint doc:name="Poll files" metadata:id="a75d5954-7fb4-4721-85f6-7ee66b793750" path="E:\test" responseTimeout="10000"/>
<dw:transform-message doc:name="Transform CSV to Map" metadata:id="84d175de-b3c6-4480-af9d-150e736f051e">
<dw:input-payload doc:sample="list_csv.csv" mimeType="application/csv"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload map {
name: $.name,
orderId: $.orderId,
pricePerUnit: $.pricePerUnit as :number,
units: $.units as :number,
totalPrice: ($.units * $.pricePerUnit ) as :number
}]]></dw:set-payload>
</dw:transform-message>
<logger doc:name="Log the processed objects" level="INFO" message="Processing objects: #[payload]"/>
<smtp:outbound-endpoint connector-ref="Gmail" doc:name="Send an email via SMTP" from="${mail.from}" host="${smtp.host}" password="${smtp.password}" port="587" responseTimeout="10000" subject="${mail.subject}" to="${mail.to}" user="${smtp.user}"/>
</flow>
This will solve your issue