how do a merge of sql server with mule? - mule

I have done this with a foreach and execute dll operation, but when try insert o uptdate a string throw a exeption, however with a int values works.
The exeption:`Exception stack is:
1. Invalid column name 'Carlos'. (com.microsoft.sqlserver.jdbc.SQLServerException)
com.microsoft.sqlserver.jdbc.SQLServerException:217 (null)
2. Invalid column name 'Carlos'. (com.microsoft.sqlserver.jdbc.SQLServerException). Message payload is of type: LinkedHashMap (org.mule.api.MessagingException)
org.mule.module.db.internal.processor.AbstractDbMessageProcessor:93 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
********************************************************************************
Root Exception stack trace:
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'Carlos'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1635)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:865)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:762)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:6276)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1793)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:184)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:159)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:2198)
at org.mule.module.db.internal.domain.autogeneratedkey.NoAutoGeneratedKeyStrategy.executeUpdate(NoAutoGeneratedKeyStrategy.java:59)
at org.mule.module.db.internal.domain.executor.UpdateExecutor.doExecuteQuery(UpdateExecutor.java:43)
at org.mule.module.db.internal.domain.executor.UpdateExecutor.doExecuteQuery(UpdateExecutor.java:37)
at org.mule.module.db.internal.domain.executor.AbstractSingleQueryExecutor.execute(AbstractSingleQueryExecutor.java:38)
at org.mule.module.db.internal.processor.ExecuteDdlMessageProcessor.doExecuteQuery(ExecuteDdlMessageProcessor.java:53)
at org.mule.module.db.internal.processor.AbstractSingleQueryDbMessageProcessor.executeQuery(AbstractSingleQueryDbMessageProcessor.java:42)
at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.process(AbstractDbMessageProcessor.java:66)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
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.routing.outbound.AbstractMessageSequenceSplitter.processParts(AbstractMessageSequenceSplitter.java:129)
at org.mule.routing.outbound.AbstractMessageSequenceSplitter.process(AbstractMessageSequenceSplitter.java:59)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
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:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.routing.Foreach.process(Foreach.java:94)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
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:24)
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 o...
********************************************************************************
`
'Carlos' is a value from the payload.
This is the DLL
BEGIN MERGE [FP].[Profile] AS DESTINO USING (SELECT #[payload.ID]) AS
FUENTE (ID) ON (DESTINO.ID=FUENTE.ID) WHEN MATCHED THEN UPDATE SET
[UserId]= #[payload.UserId] WHEN NOT MATCHED THEN INSERT
(ID,UserId,ExternalId,FirstName) VALUES (#[payload.ID],#
[payload.UserId],#[payload.ExternalId],#[payload.FirstName]); END
The XML Flow:
<flow name="insertprofilesindwFlow">
<file:inbound-endpoint path="C:\Users\LBonaventura\Documents\MuleFilesFromDB" responseTimeout="10000" doc:name="Read the file with the profiles" moveToDirectory="C:\Users\LBonaventura\Documents\MuleFilesFromDB" pollingFrequency="864000000"/>
<dw:transform-message metadata:id="57e39ab0-6c79-4118-a57e-fe6561a04e9b" doc:name="Transform Message to map">
<dw:input-payload doc:sample="list_csv_1.csv"/>
<dw:set-payload><![CDATA[%dw 1.0 %output application/java ---payload map ((payload01 , indexOfPayload01) -> {
ID: payload01.ID,
ExternalId: payload01.ID as :string,
UserId: payload01.UserId,
FirstName: payload01.FirstName,
LastName: payload01.LastName,
(DateOfBirth: payload01.DateOfBirth as :string) when payload01.DateOfBirth != "",
(DateOfBirth: null) when payload01.DateOfBirth=="",
(Gender:"M") when payload01.Gender=="1",
(Gender:"F") when payload01.Gender=="0",
(Gender:null) when payload01.Gender=="",
AllowTracking: payload01.AllowTracking,
Email: payload01.AlertEmail,
MainProfile: payload01.Main,
Active: payload01.Active as :boolean,
CreatedOn: payload01.DateAdded as :string,
UpdatedOn: payload01.DateUpdated as :string,
LanguageIso: "ESP",
Deleted: false})]]></dw:set-payload>
</dw:transform-message>
<foreach doc:name="For Each Profile">
<db:execute-ddl config-ref="FOX_DW_DATABASE_CONFIGURATION" doc:name="Upsert in the Database">
<db:dynamic-query><![CDATA[BEGIN MERGE [FP].[Profile] AS DESTINO
USING (SELECT #[payload.ID]) AS FUENTE (ID)
ON (DESTINO.ID=FUENTE.ID)
WHEN MATCHED THEN
UPDATE SET
[UserId]= #[payload.UserId],
[FirstName]=#[payload.FirstName]
WHEN NOT MATCHED THEN
INSERT
(ID,UserId,ExternalId,[FirstName])
VALUES
(#[payload.ID],#[payload.UserId],#[payload.ExternalId],#[payload.FirstName]); END]]></db:dynamic-query>
</db:execute-ddl>
</foreach>
</flow>

When working with dynamic query there is no parameter conversion, for this reason you need to add quotes to string arguments, so in your case it should look something like that:
<db:dynamic-query><![CDATA[BEGIN MERGE [FP].[Profile] AS DESTINO
USING (SELECT #[payload.ID]) AS FUENTE (ID)
ON (DESTINO.ID=FUENTE.ID)
WHEN MATCHED THEN
UPDATE SET
[UserId]= '#[payload.UserId]',
[FirstName]=#[payload.FirstName]
WHEN NOT MATCHED THEN
INSERT
(ID,UserId,ExternalId,[FirstName])
VALUES
(#[payload.ID],'#[payload.UserId]',#[payload.ExternalId],'#[payload.FirstName]'); END]]></db:dynamic-query>
Just one note on security: Pay attention when using dynamic query, you are vulnerable to SQL Injection in this way, so make sure you sanitize this parameters before passing it to the DLL.

Related

Issue facing with Mule maven munit batch testing?

Doing munit(xml) testing for my maven based mule project.
Here is my sample batch only with logger
<batch:job name="sample-mavenBatch">
<batch:input>
<logger message="I am in input phase" level="INFO" doc:name="Logger"/>
</batch:input>
<batch:process-records>
<batch:step name="Batch_Step">
<logger message="I am in processing phase" level="INFO" doc:name="Logger"/>
</batch:step>
</batch:process-records>
<batch:on-complete>
<logger message="I am in complete phase" level="INFO" doc:name="Logger"/>
</batch:on-complete>
</batch:job>
The corresponding test for the flow
<munit:test name="new-test-suite-sample-mavenBatchTest" description="Test">
<munit:set payload="#['rasmita']" doc:name="Set Message"/>
<synchronize:run-and-wait doc:name="Synchronize">
<batch:execute name="sample-mavenBatch" doc:name="Run Batch sample-mavenBatch"/>
</synchronize:run-and-wait>
</munit:test>
This runs me to the following exception
Message
: Object "java.lang.String" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException)
Element : /new-test-suite-sample-mavenBatchTest/processors/1 # b185c7c0-9c20-11e6-9bef-c03fd56639e7
--------------------------------------------------------------------------------
Exception stack is:
Object "java.lang.String" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException) (com.mulesoft.module.batch.exception.BatchException)
org.mule.util.collection.EventToMessageSequenceSplittingStrategy.split(EventToMessageSequenceSplittingStrategy.java:65)
org.mule.util.collection.EventToMessageSequenceSplittingStrategy.split(EventToMessageSequenceSplittingStrategy.java:26)
com.mulesoft.module.batch.engine.queue.BatchQueueLoader.splitAndLoad(BatchQueueLoader.java:63)
(98 more...)
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
ERROR - The test new-test-suite-sample-mavenBatchTest finished with an Error.
Object "java.lang.String" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException) (com.mulesoft.module.batch.exception.BatchException) (org.mule.api.DefaultMuleException).
org.mule.api.MessagingException: Object "java.lang.String" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException) (com.mulesoft.module.batch.exception.BatchException) (org.mule.api.DefaultMuleException).
at sample-mavenBatch.mule:logger{doc:name=Logger, level=INFO, message=I am in input phase}(sample-maven.xml:18)
at sample-mavenBatch.batch:input{}(sample-maven.xml:17)
at new-test-suite-sample-mavenBatchTest.batch:execute{doc:name=Run Batch sample-mavenBatch}(new-test-suite.xml:18)
at new-test-suite-sample-mavenBatchTest.synchronize:run-and-wait{doc:name=Synchronize, timeout=2000, runAsync=false}(new-test-suite.xml:17)
at new-test-suite-sample-mavenBatchTest.munit:set{doc:name=Set Message, payload=rasmita}(new-test-suite.xml:16)
at appleFlow.munit:test{initialState=started, description=Test, ignore=false, abstract=false, id=MunitTestFlow$$EnhancerByMUNIT$$904837f0{new-test-suite-sample-mavenBatchTest}}(new-test-suite.xml:15)
Caused by: org.mule.api.DefaultMuleException: Object "java.lang.String" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException) (com.mulesoft.module.batch.exception.BatchException)
at org.mule.config.RunAndWait.process(RunAndWait.java:52)
at org.mule.config.RunAndWait$$EnhancerByMUNIT$$b91d97ea.CGLIB$process$0(<generated>)
at org.mule.config.RunAndWait$$EnhancerByMUNIT$$b91d97ea$$FastClassByMUNIT$$2ac5af50.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at org.mule.munit.common.processor.interceptor.MunitMessageProcessorInterceptor.invokeSuper(MunitMessageProcessorInterceptor.java:95)
at org.mule.munit.common.processor.interceptor.MunitMessageProcessorInterceptor.process(MunitMessageProcessorInterceptor.java:82)
at org.mule.modules.interceptor.processors.AbstractMessageProcessorInterceptor.intercept(AbstractMessageProcessorInterceptor.java:46)
at org.mule.config.RunAndWait$$EnhancerByMUNIT$$b91d97ea.process(<generated>)
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.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:102)
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:98)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.construct.DynamicPipelineMessageProcessor.process(DynamicPipelineMessageProcessor.java:55)
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.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:98)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:52)
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:98)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
at org.mule.processor.AbstractRequestResponseMessageProcessor.processBlocking(AbstractRequestResponseMessageProcessor.java:56)
at org.mule.processor.AbstractRequestResponseMessageProcessor.process(AbstractRequestResponseMessageProcessor.java:47)
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.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:108)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.construct.Flow$2.process(Flow.java:138)
at org.mule.construct.Flow$2.process(Flow.java:133)
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.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.ErrorHandlingExecutionTemplate.execute(ErrorHandlingExecutionTemplate.java:60)
at org.mule.execution.ErrorHandlingExecutionTemplate.execute(ErrorHandlingExecutionTemplate.java:30)
at org.mule.construct.Flow.process(Flow.java:132)
at org.mule.munit.assertion.processors.MunitTestFlow.process(MunitTestFlow.java:121)
at org.mule.munit.assertion.processors.MunitTestFlow$$EnhancerByMUNIT$$904837f0.CGLIB$process$0(<generated>)
at org.mule.munit.assertion.processors.MunitTestFlow$$EnhancerByMUNIT$$904837f0$$FastClassByMUNIT$$f664bbef.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at org.mule.munit.common.processor.interceptor.MunitMessageProcessorInterceptor.invokeSuper(MunitMessageProcessorInterceptor.java:95)
at org.mule.munit.common.processor.interceptor.MunitMessageProcessorInterceptor.process(MunitMessageProcessorInterceptor.java:82)
at org.mule.modules.interceptor.processors.AbstractMessageProcessorInterceptor.intercept(AbstractMessageProcessorInterceptor.java:46)
at org.mule.munit.assertion.processors.MunitTestFlow$$EnhancerByMUNIT$$904837f0.process(<generated>)
at org.mule.munit.runner.mule.MunitTest.run(MunitTest.java:108)
at org.mule.munit.runner.mule.MunitSuite.run(MunitSuite.java:49)
at org.mule.munit.runner.mule.MunitSuiteRunner$1.runSuite(MunitSuiteRunner.java:53)
at org.mule.munit.runner.mule.MunitSuiteRunner$1.runSuite(MunitSuiteRunner.java:49)
at org.mule.munit.runner.MunitRunner.run(MunitRunner.java:75)
at org.mule.munit.runner.mule.MunitSuiteRunner.run(MunitSuiteRunner.java:49)
at org.mule.munit.remote.MunitRemoteRunner.runTestSuite(MunitRemoteRunner.java:193)
at org.mule.munit.remote.MunitRemoteRunner.run(MunitRemoteRunner.java:102)
at org.mule.munit.remote.MunitRemoteRunner.main(MunitRemoteRunner.java:76)
Caused by: com.mulesoft.module.batch.exception.BatchException: Object "java.lang.String" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException)
at com.mulesoft.module.batch.engine.DefaultBatchEngine.load(DefaultBatchEngine.java:419)
at com.mulesoft.module.batch.DefaultBatchJob.execute(DefaultBatchJob.java:357)
at com.mulesoft.module.batch.processor.BatchExecuteMessageProcessor.process(BatchExecuteMessageProcessor.java:49)
at com.mulesoft.module.batch.processor.BatchExecuteMessageProcessor$$FastClassByCGLIB$$c5698262.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.mule.munit.common.processor.interceptor.WrapperMunitMessageProcessorInterceptor.invokeSuper(WrapperMunitMessageProcessorInterceptor.java:62)
at org.mule.munit.common.processor.interceptor.MunitMessageProcessorInterceptor.process(MunitMessageProcessorInterceptor.java:82)
at org.mule.munit.common.processor.interceptor.WrapperMunitMessageProcessorInterceptor.intercept(WrapperMunitMessageProcessorInterceptor.java:42)
at com.mulesoft.module.batch.processor.BatchExecuteMessageProcessor$$EnhancerByMUNIT$$c5698262.process(<generated>)
at org.mule.config.RunAndWait$1.process(RunAndWait.java:42)
at org.mule.Synchronizer.runAndWait(Synchronizer.java:39)
at org.mule.config.RunAndWait.process(RunAndWait.java:48)
... 86 more
Caused by: java.lang.IllegalArgumentException: Object "java.lang.String" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}"
at org.mule.util.collection.EventToMessageSequenceSplittingStrategy.split(EventToMessageSequenceSplittingStrategy.java:65)
at org.mule.util.collection.EventToMessageSequenceSplittingStrategy.split(EventToMessageSequenceSplittingStrategy.java:26)
at com.mulesoft.module.batch.engine.queue.BatchQueueLoader.splitAndLoad(BatchQueueLoader.java:63)
at com.mulesoft.module.batch.engine.DefaultBatchEngine.load(DefaultBatchEngine.java:402)
... 97 more
where as The same test case works in non-maven mule project.
Please help me. Thanks in advance.
This is the issue of the input set in Munit. As error message clearly says
Object "java.lang.String" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException) (com.mulesoft.module.batch.exception.BatchException) (org.mule.api.DefaultMuleException).
Batch input should be Iterable, but you have provided String #['rasmita']. Instead of this try to pass array list. You can use MEL or dataweave for the same.
Hope this helps.
I resolved my issues in two ways
1) in Set payload as #anupambhusari said use arraylist, so using MEL #[{'rasmita','ananda'}]
2)With transform message which was throwing the below exception org.threeten.bp.zone.ZoneRulesProvider: Provider org.threeten.bp.zone.TzdbZoneRulesProvider
Added the below dependency.
Test <dependency>
<groupId>com.mulesoft.weave</groupId>
<artifactId>mule-plugin-weave_2.11</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
</exclusion>
</exclusions>
</dependency>

Mulesoft: Default value for not existing deep nodes

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"
}

mule java component throwing IllegalArgumentException

I am running Mule 3.6.2 in STS 3.6.4. I am trying to use a simple Java Component.
public class MyComponent implements Callable {
public MyComponent() {
super();
}
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
return eventContext.getMessage().getPayload();
}
}
and a Simple flow in Input phase of Batch component....
<flow name="MainFlow>
<http:inbound-endpoint exchange-pattern="request-response" host="${app.host}" port="${app.port}" path="test" doc:name="HTTP"/>
<cxf:jaxws-service serviceClass="example.sampleservice.TempService" doc:name="CXF"/>
<component class="com.temp.MyComponent" doc:name="Java"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
At the java component line, I get a
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_75]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_75]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_75]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_75]
at org.mule.model.resolvers.AbstractEntryPointResolver.invokeMethod(AbstractEntryPointResolver.java:148) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.model.resolvers.MethodHeaderPropertyEntryPointResolver.invoke(MethodHeaderPropertyEntryPointResolver.java:109) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.model.resolvers.DefaultEntryPointResolverSet.invoke(DefaultEntryPointResolverSet.java:36) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:339) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.component.AbstractJavaComponent.invokeComponentInstance(AbstractJavaComponent.java:82) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.component.AbstractJavaComponent.doInvoke(AbstractJavaComponent.java:73) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:125) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:59) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.component.AbstractComponent$1$1.process(AbstractComponent.java:241) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:94) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:69) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:50) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:69) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.access$001(InterceptingChainLifecycleWrapper.java:22) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.InterceptingChainLifecycleWrapper$1.process(InterceptingChainLifecycleWrapper.java:66) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:61) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.component.AbstractComponent.process(AbstractComponent.java:159) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:94) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:69) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:102) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.module.cxf.CxfInboundMessageProcessor.processNext(CxfInboundMessageProcessor.java:389) ~[mule-module-cxf-3.6.2.jar:3.6.2]
at org.mule.module.cxf.MuleInvoker$1.process(MuleInvoker.java:88) ~[mule-module-cxf-3.6.2.jar:3.6.2]
at org.mule.module.cxf.MuleInvoker$1.process(MuleInvoker.java:84) ~[mule-module-cxf-3.6.2.jar:3.6.2]
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.execution.ErrorHandlingExecutionTemplate.execute(ErrorHandlingExecutionTemplate.java:59) ~[mule-core-3.6.2.jar:3.6.2]
at org.mule.module.cxf.MuleInvoker.invoke(MuleInvoker.java:83) ~[mule-module-cxf-3.6.2.jar:3.6.2]
I know what the exception means, but unable to understand in this context.
If you want to create simple java component then instead of implementing callable,
try with mule specific annotations.
public myComponent(){
super();
}
public String myComponent(#payload String myPayload) {
<!--your operation goes here-->
system.out.println("created my simple java component!");
return myPayload;
}
Cheers!

Mule 3.7 transformer with annotations for custom Objects

I have two custom Classes : Person, Manager. I wrote the following transformer to transform Person to Manager object.
package com.learning.transformers;
import org.mule.api.annotations.ContainsTransformerMethods;
import org.mule.api.annotations.Transformer;
import com.learning.beans.Manager;
import com.learning.beans.Person;
#ContainsTransformerMethods
public class AnnotatedTransformer {
#Transformer
public Manager transformToManager(#Payload Person person){
Manager manager = new Manager();
manager.setPerson(person);
manager.setDesignation("Manager");
return manager;
}
}
My configuraiton file is as follows.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" 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: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/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<spring:beans>
<spring:bean id="anTransformer" name="anT" class="com.learning.transformers.AnnotatedTransformer"/>
</spring:beans>
<flow name="mule-learning-transformersFlow1">
<http:listener config-ref="GlobalHTTPConnector" path="/customTransformation" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="com.learning.beans.Person" doc:name="JSON to Object"/>
<!-- <auto-transformer returnClass="com.learning.beans.Manager" /> -->
<component class="com.learning.components.ManagerLoggingComponent" doc:name="Java" />
</flow>
</mule>
My ManagerLoggingComponent looks like :
package com.learning.components;
import com.learning.beans.Manager;
import com.learning.beans.Person;
import org.mule.api.annotations.param.Payload;
public class ManagerLoggingComponent {
public void logManager(#Payload Manager manager){
Person person = manager.getPerson();
System.out.println("Name: "+person.getName());
System.out.println("Age: "+person.getAge());
System.out.println("Designation: "+manager.getDesignation());
}
}
I first send some json input to the flow. That is converted to Person object using json-to-object transformer. Then my component is placed which expects Manager object. I have registered my annotated transformer as spring bean. Hence I expect Person object to be converted to Manager object before passing it to Component. But it is throwing following exception.
Message : Failed to transform from "json" to
"com.learning.beans.Manager" Type :
org.mule.api.transformer.TransformerException Code :
MULE_ERROR-109 JavaDoc :
http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html
Transformer : JsonToObject{this=d61a0b,
name='JsonToManager', ignoreBadInput=false,
returnClass=SimpleDataType{type=com.learning.beans.Manager,
mimeType='/', encoding='null'},
sourceTypes=[SimpleDataType{type=java.io.Reader, mimeType='/',
encoding='null'}, SimpleDataType{type=java.net.URL, mimeType='/',
encoding='null'}, SimpleDataType{type=java.io.File, mimeType='/',
encoding='null'}, SimpleDataType{type=java.lang.String,
mimeType='/', encoding='null'},
SimpleDataType{type=java.io.InputStream, mimeType='/',
encoding='null'}, SimpleDataType{type=[B, mimeType='/',
encoding='null'}]}
Also, while starting the server I found that it is throwing the following error by which I understand that it is un-registering the transformToManager transformer. That might be the reason for not picking up my custom transformer. This is being observed in mule 3.7. 3.5 is working smoothly.
WARN 2016-03-27 14:01:06,574 [main] org.mule.config.spring.SpringRegistry: Could not apply shutdown lifecycle to object 'AnnotatedTransformer.transformToManager' after being unregistered.
org.mule.api.lifecycle.InitialisationException: An Expression Evaluator for "payload" is not registered with Mule. Make sure you have the the module for this expression type on your classpath. for example, if you are using an xpath expression you need to have the Mule XML module on your classpath.
at org.mule.expression.transformers.AbstractExpressionTransformer.initialise(AbstractExpressionTransformer.java:85) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.config.expression.ExpressionAnnotationsHelper.getTransformerForMethodWithAnnotations(ExpressionAnnotationsHelper.java:53) ~[mule-module-annotations-3.7.3.jar:3.7.3]
at org.mule.config.transformer.AnnotatedTransformerProxy.initialise(AnnotatedTransformerProxy.java:109) ~[mule-module-annotations-3.7.3.jar:3.7.3]
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_72]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_72]
at org.mule.lifecycle.phases.DefaultLifecyclePhase.applyLifecycle(DefaultLifecyclePhase.java:237) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.lifecycle.phases.MuleContextInitialisePhase.applyLifecycle(MuleContextInitialisePhase.java:71) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.lifecycle.RegistryLifecycleManager.applyPhase(RegistryLifecycleManager.java:183) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.registry.AbstractRegistry.unregisterObject(AbstractRegistry.java:163) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.config.spring.SpringRegistry$ConfigurableRegistrationDelegate.doRegisterObject(SpringRegistry.java:451) ~[mule-module-spring-config-3.7.3.jar:3.7.3]
at org.mule.config.spring.SpringRegistry$ConfigurableRegistrationDelegate.registerObject(SpringRegistry.java:405) ~[mule-module-spring-config-3.7.3.jar:3.7.3]
at org.mule.config.spring.SpringRegistry.registerObject(SpringRegistry.java:253) ~[mule-module-spring-config-3.7.3.jar:3.7.3]
at org.mule.registry.AbstractRegistryBroker.registerObject(AbstractRegistryBroker.java:249) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.registry.AbstractRegistryBroker.registerObject(AbstractRegistryBroker.java:262) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.registry.MuleRegistryHelper.registerObject(MuleRegistryHelper.java:816) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.registry.MuleRegistryHelper.registerTransformer(MuleRegistryHelper.java:458) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.config.transformer.AnnotatedTransformerObjectProcessor.process(AnnotatedTransformerObjectProcessor.java:76) ~[mule-module-annotations-3.7.3.jar:3.7.3]
at org.mule.config.spring.processors.TransformerAnnotatedBeanProcessor.postProcessBeforeInitialization(TransformerAnnotatedBeanProcessor.java:30) ~[mule-module-spring-config-3.7.3.jar:3.7.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753) ~[mule-module-spring-config-3.7.3.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:108) ~[mule-module-spring-config-3.7.3.jar:3.7.3]
at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:104) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:172) ~[mule-module-spring-config-3.7.3.jar:3.7.3]
at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:95) ~[mule-module-spring-config-3.7.3.jar:3.7.3]
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.7.3.jar:3.7.3]
............
My request look like
{
"name":"Sai",
"age" : "100000"
}
Any ideas on what is happening here?
Everything is working as expected in Mule 3.5. Problem is with mule 3.7.
Update 1 : Full log of Excetion:
Message : Failed to transform from "json" to "com.learning.beans.Manager"
Type : org.mule.api.transformer.TransformerException
Code : MULE_ERROR-109
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html
Transformer : JsonToObject{this=13de431, name='JsonToManager', ignoreBadInput=false, returnClass=SimpleDataType{type=com.learning.beans.Manager, mimeType='*/*', encoding='null'}, sourceTypes=[SimpleDataType{type=java.io.Reader, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.net.URL, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.io.File, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.lang.String, mimeType='*/*', encoding='null'}, SimpleDataType{type=java.io.InputStream, mimeType='*/*', encoding='null'}, SimpleDataType{type=[B, mimeType='*/*', encoding='null'}]}
********************************************************************************
Exception stack is:
1. null (java.lang.NullPointerException)
java.io.Reader:78 (null)
2. Failed to transform from "json" to "com.learning.beans.Manager" (org.mule.api.transformer.TransformerException)
org.mule.module.json.transformers.JsonToObject:133 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
********************************************************************************
Root Exception stack trace:
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:97)
at org.mule.module.json.transformers.JsonToObject.transformMessage(JsonToObject.java:119)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:141)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:69)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:425)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:373)
at org.mule.expression.MessagePayloadExpressionEvaluator.evaluate(MessagePayloadExpressionEvaluator.java:79)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:318)
at org.mule.expression.transformers.ExpressionArgument.evaluate(ExpressionArgument.java:116)
at org.mule.expression.transformers.ExpressionTransformer.transformMessage(ExpressionTransformer.java:51)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:141)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:69)
at org.mule.transformer.AbstractTransformer.transform(AbstractTransformer.java:366)
at org.mule.impl.model.resolvers.AnnotatedEntryPointResolver.getPayloadFromMessageWithAnnotations(AnnotatedEntryPointResolver.java:175)
at org.mule.impl.model.resolvers.AnnotatedEntryPointResolver.getPayloadForMethod(AnnotatedEntryPointResolver.java:161)
at org.mule.impl.model.resolvers.AnnotatedEntryPointResolver.invoke(AnnotatedEntryPointResolver.java:130)
at org.mule.model.resolvers.DefaultEntryPointResolverSet.invoke(DefaultEntryPointResolverSet.java:36)
at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:339)
at org.mule.component.AbstractJavaComponent.invokeComponentInstance(AbstractJavaComponent.java:82)
at org.mule.component.AbstractJavaComponent.doInvoke(AbstractJavaComponent.java:73)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:120)
at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:55)
at org.mule.component.AbstractComponent$1$1.process(AbstractComponent.java:236)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
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:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.component.AbstractComponent.process(AbstractComponent.java:154)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
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.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
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.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:102)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
at org.mule.processor.BlockingProcessorExecutor.e...
********************************************************************************
Update 2 : I started getting the below exception suddenly. I didn't change any code. It is showing the below exception some times and above exception some other times.
Message : The object transformed is of type: "SimpleDataType{type=java.lang.String, mimeType='*/*', encoding='null'}", but the expected return type is "SimpleDataType{type=com.learning.beans.Manager, mimeType='application/json', encoding='null'}". The current MuleMessage is null! Please report this to mule-esb#mulesoft.com
Type : org.mule.api.transformer.TransformerMessagingException
Code : MULE_ERROR--2
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html
Payload : {NullPayload}
********************************************************************************
Exception stack is:
1. The object transformed is of type: "SimpleDataType{type=java.lang.String, mimeType='*/*', encoding='null'}", but the expected return type is "SimpleDataType{type=com.learning.beans.Manager, mimeType='application/json', encoding='null'}". The current MuleMessage is null! Please report this to mule-esb#mulesoft.com (org.mule.api.transformer.TransformerMessagingException)
org.mule.transformer.AbstractMessageTransformer:179 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
********************************************************************************
Root Exception stack trace:
org.mule.api.transformer.TransformerMessagingException: The object transformed is of type: "SimpleDataType{type=java.lang.String, mimeType='*/*', encoding='null'}", but the expected return type is "SimpleDataType{type=com.learning.beans.Manager, mimeType='application/json', encoding='null'}". The current MuleMessage is null! Please report this to mule-esb#mulesoft.com
at org.mule.transformer.AbstractMessageTransformer.checkReturnClass(AbstractMessageTransformer.java:179)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:158)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:69)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:425)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:373)
at org.mule.expression.MessagePayloadExpressionEvaluator.evaluate(MessagePayloadExpressionEvaluator.java:79)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:318)
at org.mule.expression.transformers.ExpressionArgument.evaluate(ExpressionArgument.java:116)
at org.mule.expression.transformers.ExpressionTransformer.transformMessage(ExpressionTransformer.java:51)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:141)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:69)
at org.mule.transformer.AbstractTransformer.transform(AbstractTransformer.java:366)
at org.mule.impl.model.resolvers.AnnotatedEntryPointResolver.getPayloadFromMessageWithAnnotations(AnnotatedEntryPointResolver.java:175)
at org.mule.impl.model.resolvers.AnnotatedEntryPointResolver.getPayloadForMethod(AnnotatedEntryPointResolver.java:161)
at org.mule.impl.model.resolvers.AnnotatedEntryPointResolver.invoke(AnnotatedEntryPointResolver.java:130)
at org.mule.model.resolvers.DefaultEntryPointResolverSet.invoke(DefaultEntryPointResolverSet.java:36)
at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:339)
at org.mule.component.AbstractJavaComponent.invokeComponentInstance(AbstractJavaComponent.java:82)
at org.mule.component.AbstractJavaComponent.doInvoke(AbstractJavaComponent.java:73)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:120)
at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:55)
at org.mule.component.AbstractComponent$1$1.process(AbstractComponent.java:236)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
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:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.component.AbstractComponent.process(AbstractComponent.java:154)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
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.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
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.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:102)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.m...
********************************************************************************

Munit test case fails when trying to mock sfdc endpoint

I am trying to mock an sfdc-endpoint .But in my actual flow this endpoint return some value.When i am trying to return any value through mocking this endpoint it is throwing an exception as:
org.mule.api.MessagingException: Execution of the expression "payload.size()" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
at org.mule.el.mvel.MVELExpressionLanguage.evaluateInternal(MVELExpressionLanguage.java:202)
at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:154)
at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:133)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:215)
at org.mule.expression.DefaultExpressionManager$2.match(DefaultExpressionManager.java:476)
at org.mule.util.TemplateParser.parse(TemplateParser.java:149)
at org.mule.util.TemplateParser.parse(TemplateParser.java:126)
at org.mule.expression.DefaultExpressionManager.parse(DefaultExpressionManager.java:472)
at org.mule.expression.DefaultExpressionManager.parse(DefaultExpressionManager.java:431)
at org.mule.api.processor.LoggerMessageProcessor.log(LoggerMessageProcessor.java:88)
at org.mule.api.processor.LoggerMessageProcessor.process(LoggerMessageProcessor.java:67)
at org.mule.api.processor.LoggerMessageProcessor$$EnhancerByMUNIT$$5003da6e.CGLIB$process$1(<generated>)
at org.mule.api.processor.LoggerMessageProcessor$$EnhancerByMUNIT$$5003da6e$$FastClassByMUNIT$$60cdcd72.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at org.mule.munit.common.mp.MunitMessageProcessorInterceptor.invokeSuper(MunitMessageProcessorInterceptor.java:66)
at org.mule.munit.common.mp.MunitMessageProcessorInterceptor.process(MunitMessageProcessorInterceptor.java:59)
at org.mule.modules.interceptor.processors.AbstractMessageProcessorInterceptor.intercept(AbstractMessageProcessorInterceptor.java:44)
at org.mule.api.processor.LoggerMessageProcessor$$EnhancerByMUNIT$$5003da6e.process(<generated>)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:97)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.construct.DynamicPipelineMessageProcessor.process(DynamicPipelineMessageProcessor.java:54)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:51)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:40)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.construct.AbstractPipeline$1.process(AbstractPipeline.java:109)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.construct.Flow$1.process(Flow.java:82)
at org.mule.construct.Flow$1.process(Flow.java:77)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
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:54)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.ErrorHandlingExecutionTemplate.execute(ErrorHandlingExecutionTemplate.java:59)
at org.mule.execution.ErrorHandlingExecutionTemplate.execute(ErrorHandlingExecutionTemplate.java:30)
at org.mule.construct.Flow.process(Flow.java:76)
at org.mule.construct.Flow$$EnhancerByMUNIT$$bb7e3368.CGLIB$process$0(<generated>)
at org.mule.construct.Flow$$EnhancerByMUNIT$$bb7e3368$$FastClassByMUNIT$$45e5ae9e.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at org.mule.munit.common.mp.MunitMessageProcessorInterceptor.invokeSuper(MunitMessageProcessorInterceptor.java:66)
at org.mule.munit.common.mp.MunitMessageProcessorInterceptor.process(MunitMessageProcessorInterceptor.java:59)
at org.mule.modules.interceptor.processors.AbstractMessageProcessorInterceptor.intercept(AbstractMessageProcessorInterceptor.java:44)
at org.mule.construct.Flow$$EnhancerByMUNIT$$bb7e3368.process(<generated>)
at org.mule.munit.runner.functional.FunctionalMunitSuite.runFlow(FunctionalMunitSuite.java:261)
at mule_work_with_form.TestGetEmployeeFlow.validateEchoFlow(TestGetEmployeeFlow.java:56)
Caused by: org.mule.mvel2.PropertyAccessException: [Error: unable to resolve method: java.lang.String.size() [arglength=0]]
[Near : {... payload.size() ....}]
^
[Line: 1, Column: 1]
at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1084)
at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:993)
at org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:343)
I am using Munit-3.5-m2 .
Not sure if you can not mock the connector.
You see, the exception is pointing to a MEL error when executing a MEL expression and it's complaining that whatever the payload is when reaching that expression it doesn't have a size() method.
It actually says that the payload is a string and that has not size method:
Caused by: org.mule.mvel2.PropertyAccessException: [Error: unable to resolve method: java.lang.String.size() [arglength=0]]
[Near : {... payload.size() ....}]
I reckon you're expecting that payload to be a list or a collection.
I'll start looking the error there.
If you still find problems with that please share the code of the failing test and the one of the flow trying to be tested.
HTH