In my flow i set variable operation as :payload.operation then in Consume node i want to get it's value
Variable value is set corectly
I also include xml of my flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:netsuite="http://www.mulesoft.org/schema/mule/netsuite" xmlns:wsc="http://www.mulesoft.org/schema/mule/wsc"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.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/wsc http://www.mulesoft.org/schema/mule/wsc/current/mule-wsc.xsd
http://www.mulesoft.org/schema/mule/netsuite http://www.mulesoft.org/schema/mule/netsuite/current/mule-netsuite.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="a532976e-413b-4f47-bc8f-3e79e6de1417" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<db:config name="Database_Config" doc:name="Database Config" doc:id="276e5d43-bd49-4a82-b7c6-934288334aca" >
<db:my-sql-connection host="mudb.learn.mulesoft.com" port="3306" user="mule" password="mule" database="training" />
</db:config>
<wsc:config name="Web_Service_Consumer_Config" doc:name="Web Service Consumer Config" doc:id="a5692620-4f26-4b11-be70-b822710d6c0d" >
<wsc:connection wsdlLocation="http://dneonline.com/calculator.asmx?WSDL" service="Calculator" port="CalculatorSoap12" soapVersion="SOAP12" address="http://www.dneonline.com/calculator.asmx"/>
</wsc:config>
<flow name="api-accountsFlow" doc:id="7a942ae2-4422-46ba-b57d-38bd37ec9f82" >
<http:listener doc:name="Get Accounts Listener" doc:id="a1873bcc-b9f1-4cf7-a405-a1c835cdf69c" config-ref="HTTP_Listener_config" path="/calculator" />
<choice doc:name="Choice" doc:id="0b885797-7da1-4932-9183-869b5a670943" >
<when expression='#[payload.operation=="Add" or payload.operation=="Subtract" or payload.operation=="Mul" or payload.operation=="Divide"]'>
<set-variable value="#[payload.operation]" doc:name="Set Variable" doc:id="5c4da028-7ae8-43e6-ac35-84de6c3b4666" variableName="operation" />
<ee:transform doc:name="Transform JSON Request to XML" doc:id="86f3eebe-0050-4800-9c08-7167ded759d9" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
ns ns0 http://tempuri.org/
---
{
("ns0#" ++ vars.operation): {
ns0#intA: payload.val1,
ns0#intB: payload.val2
}
}
]]></ee:set-payload>
</ee:message>
</ee:transform>
<wsc:consume doc:name="Consume" doc:id="091e6ca8-a78d-4a6f-b947-679235f7bfa4" config-ref="Web_Service_Consumer_Config" operation="#[vars.operation]"/>
<ee:transform doc:name="Transform JSON Request to XML1" doc:id="6b77fd85-8af7-4f96-a299-2b64445ede0b" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload
]]></ee:set-payload>
</ee:message>
</ee:transform>
</when>
<otherwise >
<logger level="INFO" doc:name="Logger" doc:id="b4a8341c-a265-4c60-ab58-9b42d899c8fd" />
<set-payload value="=== Operation Not Found ===" doc:name="Set Payload" doc:id="f8436921-0612-44b5-b12d-7dac7bfd7c2d" />
</otherwise>
</choice>
</flow>
</mule>
When i run my flow i get
org.mule.runtime.module.extension.internal.runtime.ValueResolvingException: org.mule.runtime.module.extension.internal.runtime.ValueResolvingException: Unable to resolve value for the parameter: operation
at org.mule.runtime.module.extension.internal.runtime.operation.OperationParameterValueResolver.getParameterValue(OperationParameterValueResolver.java:101)
at org.mule.runtime.module.extension.internal.metadata.MetadataMediator.getMetadataKeyObjectValue(MetadataMediator.java:426)
at org.mule.runtime.module.extension.internal.metadata.MetadataMediator.getMetadata(MetadataMediator.java:181)
at org.mule.runtime.module.extension.internal.runtime.ExtensionComponent.lambda$getMetadata$21(ExtensionComponent.java:656)
at org.mule.runtime.core.api.util.ExceptionUtils.tryExpecting(ExceptionUtils.java:224)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:1102)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:1020)
at org.mule.runtime.module.extension.internal.runtime.ExtensionComponent.lambda$getMetadata$22(ExtensionComponent.java:655)
at org.mule.runtime.module.extension.internal.runtime.ExtensionComponent.runWithMetadataContext(ExtensionComponent.java:793)
at org.mule.runtime.module.extension.internal.runtime.ExtensionComponent.getMetadata(ExtensionComponent.java:654)
at org.mule.runtime.metadata.internal.MuleMetadataService.lambda$getComponentMetadata$7(MuleMetadataService.java:218)
at org.mule.runtime.metadata.internal.MuleMetadataService.exceptionHandledMetadataFetch(MuleMetadataService.java:174)
at org.mule.runtime.metadata.internal.MuleMetadataService.getComponentMetadata(MuleMetadataService.java:217)
at org.mule.runtime.metadata.internal.MuleMetadataService.getOperationMetadata(MuleMetadataService.java:116)
at org.mule.runtime.config.internal.bean.lazy.LazyMetadataService.lambda$getOperationMetadata$4(LazyMetadataService.java:100)
at java.util.Optional.orElseGet(Optional.java:267)
at org.mule.runtime.config.internal.bean.lazy.LazyMetadataService.getOperationMetadata(LazyMetadataService.java:100)
at com.mulesoft.agent.services.metadata.MuleAgentMetadataService.lambda$getOperationMetadata$2(MuleAgentMetadataService.java:75)
at com.mulesoft.agent.services.metadata.MuleAgentMetadataService.withMetadataService(MuleAgentMetadataService.java:145)
at com.mulesoft.agent.services.metadata.MuleAgentMetadataService.getOperationMetadata(MuleAgentMetadataService.java:75)
at com.mulesoft.agent.external.handlers.metadata.MetadataRequestHandler.lambda$getOperationMetadata$3(MetadataRequestHandler.java:206)
at com.mulesoft.agent.util.ResponseHelper.response(ResponseHelper.java:88)
at com.mulesoft.agent.external.handlers.metadata.MetadataRequestHandler.getOperationMetadata(MetadataRequestHandler.java:204)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:134)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:177)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:81)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:256)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:235)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:684)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:358)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:311)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)
at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1656)
at com.mulesoft.agent.rest.RequestLoggingFilter.doFilter(RequestLoggingFilter.java:95)
at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193)
at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1626)
at com.mulesoft.agent.rest.AuthorizationFilter.doFilter(AuthorizationFilter.java:49)
at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193)
at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1626)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:552)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:505)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.Server.handle(Server.java:516)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)
at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.IllegalArgumentException: Required parameter 'operation' was assigned with value '#[vars.operation]' which resolved to null. Required parameters need to be assigned with non null values
at org.mule.runtime.module.extension.internal.runtime.resolver.RequiredParameterValueResolverWrapper.resolve(RequiredParameterValueResolverWrapper.java:67)
at org.mule.runtime.module.extension.internal.runtime.LazyExecutionContext.lambda$lazy$1(LazyExecutionContext.java:61)
at org.mule.runtime.core.api.util.func.CheckedSupplier.get(CheckedSupplier.java:25)
at org.mule.runtime.api.util.LazyValue.get(LazyValue.java:75)
at org.mule.runtime.module.extension.internal.runtime.LazyExecutionContext.getParameter(LazyExecutionContext.java:78)
at org.mule.runtime.module.extension.internal.runtime.operation.OperationParameterValueResolver.lambda$getParameterValue$1(OperationParameterValueResolver.java:95)
at java.util.Optional.orElseGet(Optional.java:267)
at org.mule.runtime.module.extension.internal.runtime.operation.OperationParameterValueResolver.getParameterValue(OperationParameterValueResolver.java:78)
... 81 more
After some tests I think problem may be in this part: ("ns0#" ++ vars.operation): because from postman I get this error:
Error consuming the operation [Subtract], the request body is not a valid XML
I suspect that because the variable is set with the value from a JSON payload it maybe confusing Mule. The image shows the variable operation
is a JSON. Try assigning it as a Java output to remove the JSON format from the string:
<set-variable value="#[output application/java --- payload.operation]" doc:name="Set Variable" doc:id="5c4da028-7ae8-43e6-ac35-84de6c3b4666" variableName="operation" />