In the following mule flow, I have implemented Jersey class for REST web service with VM endpoints.
<flow name="APIKeyLoadFlow" doc:name="APIKeyLoadFlow"
initialState="started">
<http:inbound-endpoint exchange-pattern="request-response"
address="${api.load.invoke.url}" doc:name="HTTP"
responseTimeout="${apikey.http.responsetimeout}" />
<logger message="Start Of APIKeyLoadFlow -#[payload]" level="INFO"
doc:name="ENTRY_LOG" />
<request-reply timeout="300000" >
<vm:outbound-endpoint connector-ref="VM_Connector"
exchange-pattern="one-way" path="APIKeyLoadRequest">
</vm:outbound-endpoint>
<vm:inbound-endpoint connector-ref="VM_Connector"
exchange-pattern="one-way" path="APIKeyLoadResponse">
</vm:inbound-endpoint>
</request-reply>
<logger message="End of APIKeyLoadFlow" level="INFO" doc:name="EXIT_LOG" />
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger level="WARN" doc:name="Exception_Log"
message="Exception in ApiKeyFlow #[System.getProperty('line.separator')] Error Description = #[exception.getMessage()]" />
</catch-exception-strategy>
</flow>
<flow name="ApiKeyLoadRestServiceFlow" doc:name="ApiKeyLoadRestServiceFlow">
<vm:inbound-endpoint exchange-pattern="one-way"
path="APIKeyLoadRequest" doc:name="APIKey_Load_Request">
</vm:inbound-endpoint>
<logger message="Start of ApiKeyLoadRestServiceFlow -#[payload]" level="INFO"
doc:name="ENTRY_LOG" />
<jersey:resources doc:name="REST">
<component class="com.elexon.bmrs.apikey.service.impl.ApiKeyLoadImpl" />
</jersey:resources>
<logger message="End of ApiKeyLoadRestServiceFlow" level="INFO"
doc:name="EXIT_LOG" />
<vm:outbound-endpoint exchange-pattern="one-way"
path="APIKeyLoadResponse" doc:name="APIKey_Load_Response">
</vm:outbound-endpoint>
But i am getting below exception while running the request? Kindly let me what is the issue in the implemented flow?
INFO 2015-12-08 13:09:59,792 [[apikey_load_phase3].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: Start Of APIKeyLoadFlow -org.apache.commons.httpclient.ContentLengthInputStream#1517f14
INFO 2015-12-08 13:09:59,813 [[apikey_load_phase3].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'VM_Connector.dispatcher.25489136'. Object is: VMMessageDispatcher
INFO 2015-12-08 13:09:59,813 [[apikey_load_phase3].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'VM_Connector.dispatcher.25489136'. Object is: VMMessageDispatcher
INFO 2015-12-08 13:09:59,830 [[apikey_load_phase3].ApiKeyLoadRestServiceFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Start of ApiKeyLoadRestServiceFlow -org.apache.commons.httpclient.ContentLengthInputStream#1517f14
ERROR 2015-12-08 13:09:59,833 [[apikey_load_phase3].ApiKeyLoadRestServiceFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
Message : Failed to invoke JerseyResourcesComponent{ApiKeyLoadRestServiceFlow.component.14630019}. Component that caused exception is: JerseyResourcesComponent{ApiKeyLoadRestServiceFlow.component.14630019}. Message payload is of type: ContentLengthInputStream
Code : MULE_ERROR--2
Exception stack is:
1. null (java.lang.NullPointerException)
org.mule.module.jersey.JerseyResourcesComponent:116 (null)
2. Failed to invoke JerseyResourcesComponent{ApiKeyLoadRestServiceFlow.component.14630019}. Component that caused exception is: JerseyResourcesComponent{ApiKeyLoadRestServiceFlow.component.14630019}. Message payload is of type: ContentLengthInputStream (org.mule.component.ComponentException)
org.mule.component.AbstractComponent:144 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
Root Exception stack trace:
java.lang.NullPointerException
at org.mule.module.jersey.JerseyResourcesComponent.doInvoke(JerseyResourcesComponent.java:116)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:122)
at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:57)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
The Jersey component needs to be bound to an http endpoint, so not sure it can work behind a VM endpoint as all the http header and request information will be lost when passing a transport barrier etc. You could try copying the headers from inbound to outbound before the vm call, but still not sure this will work.
Related
I'm having a random problem with amqp components in Mule.
This is the scenario:
I set a global AMQP connector to be used for both Mule Flows
<amqp:connector
name="amqpLocalhostConnector"
host="${amqp.host}"
port="${amqp.port}"
fallbackAddresses="${amqp.fallbackAddresses}"
virtualHost="${amqp.virtualHost}"
username="${amqp.username}"
password="${amqp.password}"
ackMode="MANUAL"
prefetchCount="1" />
This flows sends a notification to RabbitMQ
<flow
name="notifyRabbitMQ"
doc:name="notifyRabbitMQ">
<!-- Set the payload with an ID from an element in a database -->
<set-payload
doc:name="Set Payload"
value="123abc"/>
<!-- Send the ID into an amqp message to RabbitMQ -->
<amqp:outbound-endpoint
exchangeName="exchange"
routingKey="file.id"
connector-ref="amqpLocalhostConnector">
</amqp:outbound-endpoint>
</flow>
This flow gets the notification from the RabbitMQ queue and then process it.
<flow
name="processNotification"
doc:name="processNotification"
processingStrategy="synchronous">
<amqp:inbound-endpoint
queueName="files"
connector-ref="amqpLocalhostConnector" />
<byte-array-to-string-transformer doc:name="Message to String (ID)"/>
<set-payload
value="#[app.registry.customFileService.findFile(payload)]"
doc:name="Get File" />
<logger message="SUCCESS!" level="INFO" doc:name="Logger"/>
<amqp:acknowledge-message />
</flow>
When I run the project, sometimes it works fine and sometimes it throws the following error:
ERROR 2015-07-17 12:37:47,620 [[rabbit_notification].amqpLocalhostConnector.receiver.01] org.mule.transport.amqp.AmqpMessageReceiver$AmqpMessageRouterWork: Impossible to route: org.mule.transport.amqp.AmqpMessage#43cac8[consumerTag=amq.ctag-jASX98hPWb7UUiIVHLOeEQ,envelope=Envelope(deliveryTag=2, redeliver=false, exchange=exchange, routingKey=file.id),body={53,53,97,57,50,49,52,98,50,50,50,57,101,56,56,51,55,101,98,54,102,100,56,53},properties=#contentHeader(content-type=null, content-encoding=UTF-8, headers={MULE_SESSION=rO0ABXNyACNvcmcubXVsZS5zZXNzaW9uLkRlZmF1bHRNdWxlU2Vzc2lvbi7rdtEW7GGKAwAEWgAFdmFsaWRMAA1mbG93Q29uc3RydWN0dAAmTG9yZy9tdWxlL2FwaS9jb25zdHJ1Y3QvRmxvd0NvbnN0cnVjdDtMAAJpZHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wAD3NlY3VyaXR5Q29udGV4dHQAJ0xvcmcvbXVsZS9hcGkvc2VjdXJpdHkvU2VjdXJpdHlDb250ZXh0O3hwAXB0ACRjNjI4Zjc0Ny0yYzk5LTExZTUtYjI3YS1lMWM4ZmJjNTUzY2Fwc3IAJWphdmEudXRpbC5Db2xsZWN0aW9ucyRTeW5jaHJvbml6ZWRNYXAbc/kJS0s5ewMAAkwAAW10AA9MamF2YS91dGlsL01hcDtMAAVtdXRleHQAEkxqYXZhL2xhbmcvT2JqZWN0O3hwc3IAJG9yZy5tdWxlLnV0aWwuQ2FzZUluc2Vuc2l0aXZlSGFzaE1hcJ3R2e9nRc4AAwAAeHB3DD9AAAAAAAAQAAAAAHhxAH4ACXh4, MULE_ENCODING=UTF-8, MULE_ROOT_MESSAGE_ID=c628f745-2c99-11e5-b27a-e1c8fbc553ca, MULE_ENDPOINT=amqp://exchange}, delivery-mode=2, priority=0, correlation-id=null, reply-to=null, expiration=null, message-id=c628f745-2c99-11e5-b27a-e1c8fbc553ca, timestamp=Fri Jul 17 12:37:47 ART 2015, type=null, user-id=null, app-id=null, cluster-id=null)]
Does anyone knows why this could be happening?
Thanks in advance.
I have a requirement in Mule in which I need to expose a SOAP web service ..
Now I am implementing it in 2 flows :-
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP" />
<cxf:jaxws-service serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP" />
<object-to-string-transformer doc:name="Object to String"/>
<jms:outbound-endpoint queue="NewQueue" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
<flow name="Flow2" doc:name="Flow2" >
<jms:inbound-endpoint connector-ref="Active_MQ" address="jms://tcp:NewQueue" doc:name="JMS" exchange-pattern="request-response"/>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl" >
<method-entry-point-resolver>
<include-entry-point method="retrieveDataOperation"/>
<include-entry-point method="insertDataOperation"/>
<include-entry-point method="updateDataOperation"/>
<include-entry-point method="deleteDataOperation"/>
</method-entry-point-resolver>
</component>
<logger level="INFO" message="payload :-#[message.payload]" doc:name="Logger"/>
</flow>
In the first flow (ServiceFlow) I am trying to send the SOAP request in an ActiveMQ queue and in second flow (Flow2) ..I am trying to consume the request in MainDataImpl class .. But I am getting an exception while consuming the request :-
Exception stack is:
1. "Message with id "ID:ANIRBAN-PC-49419-1407595657591-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage (org.mule.transport.jms.redelivery.MessageRedeliveredException)
org.mule.transport.jms.redelivery.JmsXRedeliveryHandler:81 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/jms/redelivery/MessageRedeliveredException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.jms.redelivery.MessageRedeliveredException: "Message with id "ID:ANIRBAN-PC-49419-1407595657591-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage
at org.mule.transport.jms.redelivery.JmsXRedeliveryHandler.handleRedelivery(JmsXRedeliveryHandler.java:81)
at org.mule.transport.jms.MultiConsumerJmsMessageReceiver$JmsWorker.preProcessMessage(MultiConsumerJmsMessageReceiver.java:512)
at org.mule.transport.AbstractReceiverWorker$1$1.process(AbstractReceiverWorker.java:117)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Now I want to know how can I resolve the issue as I guess MainDataImpl is expecting the message as object type .. but there is no way to convert the String message into Object ... Any solution for the above issue ??? Please Help
UPDATE AFTER ADDING OBJECT TO XML:-
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP" />
<cxf:jaxws-service serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP" />
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<!-- <vm:outbound-endpoint exchange-pattern="request-response" path="Flow1-WT-Main" doc:name="VM"/> -->
<jms:outbound-endpoint queue="NewQueue" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
<flow name="Flow2" doc:name="Flow2" >
<!-- <vm:inbound-endpoint exchange-pattern="request-response" path="Flow1-WT-Main" doc:name="VM"/> -->
<jms:inbound-endpoint connector-ref="Active_MQ" address="jms://tcp:NewQueue" doc:name="JMS" exchange-pattern="request-response"/>
<mulexml:xml-to-object-transformer doc:name="XML to Object"/>
<async doc:name="Async">
<logger message="Payload :-#[message.payload]" level="INFO" doc:name="Logger"/>
</async>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl" >
<method-entry-point-resolver>
<include-entry-point method="retrieveDataOperation"/>
<include-entry-point method="insertDataOperation"/>
<include-entry-point method="updateDataOperation"/>
<include-entry-point method="deleteDataOperation"/>
</method-entry-point-resolver>
</component>
<logger level="INFO" message="ccccccc :-#[message.payload]" doc:name="Logger"/>
</flow>
Now the exception is :-
INFO 2014-08-09 21:10:33,426 [ActiveMQ Session Task-1] org.mule.api.processor.LoggerMessageProcessor: ccccccc :-com.test.services.schema.maindata.v1.DataResponse#1ca5a88a
INFO 2014-08-09 21:10:33,426 [[Dummysimpleclientwebservice].Flow2.1.02] org.mule.api.processor.LoggerMessageProcessor: Payload :-com.test.services.schema.maindata.v1.DataRequest#3fdc0ab7
ERROR 2014-08-09 21:10:33,433 [ActiveMQ Session Task-1] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Source was not of a supported type. Valid types are Message, String, Map, InputStream, List, byte[], Serializable or OutputHandler, but was DataResponse (javax.jms.JMSException)
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Source was not of a supported type. Valid types are Message, String, Map, InputStream, List, byte[], Serializable or OutputHandler, but was DataResponse(JMS Code: null) (javax.jms.JMSException)
org.mule.transport.jms.JmsMessageUtils:144 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/JMSException.html)
2. Source was not of a supported type. Valid types are Message, String, Map, InputStream, List, byte[], Serializable or OutputHandler, but was DataResponse (javax.jms.JMSException) (org.mule.api.transformer.TransformerException)
org.mule.transport.jms.transformers.AbstractJmsTransformer:79 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
javax.jms.JMSException: Source was not of a supported type. Valid types are Message, String, Map, InputStream, List, byte[], Serializable or OutputHandler, but was DataResponse
at org.mule.transport.jms.JmsMessageUtils.toMessage(JmsMessageUtils.java:144)
at org.mule.transport.jms.transformers.AbstractJmsTransformer.transformToMessage(AbstractJmsTransformer.java:66)
at org.mule.transport.jms.transformers.ObjectToJMSMessage.transformMessage(ObjectToJMSMessage.java:54)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
ERROR 2014-08-09 21:10:34,488 [ActiveMQ Session Task-2] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : "Message with id "ID:ANIRBAN-PC-49768-1407598818233-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. "Message with id "ID:ANIRBAN-PC-49768-1407598818233-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage (org.mule.transport.jms.redelivery.MessageRedeliveredException)
org.mule.transport.jms.redelivery.JmsXRedeliveryHandler:81 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/jms/redelivery/MessageRedeliveredException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.jms.redelivery.MessageRedeliveredException: "Message with id "ID:ANIRBAN-PC-49768-1407598818233-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage
at org.mule.transport.jms.redelivery.JmsXRedeliveryHandler.handleRedelivery(JmsXRedeliveryHandler.java:81)
at org.mule.transport.jms.MultiConsumerJmsMessageReceiver$JmsWorker.preProcessMessage(MultiConsumerJmsMessageReceiver.java:512)
at org.mule.transport.AbstractReceiverWorker$1$1.process(AbstractReceiverWorker.java:117)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
As you guessed it, the problem is that you serialize the inbound message object to a String with object-to-string-transformer and, via a JMS queue, try to feed it to the MainDataImpl object, which takes objects as input parameters for its different operations.
The solution is to simply serialize the inbound object to XML, send it via JMS then deserialize it back to an object.
For this replace the object-to-string-transformer with an object-to-xml-transformer and add a xml-to-object-transformer right after the jms:inbound-endpoint.
EDIT
I didn't realize you're using NewQueue in request-response fashion, because you actually inconsistently declare it. On the jms:outbound-endpoint you do not provide an exchange-pattern which makes it one-way by default ; while on the jms:inbound-endpoint your set the exchange-pattern to request-response, which triggers the execution of the response phase of Flow2.
So: be consistent, use the same exchange-pattern on both JMS endpoints or, even better, declare a global JMS endpoint with the right exchange-pattern and ref-it from the jms:inbound and outbound endpoints.
If you decide to stay with request-response, then you need to do the same for the response, ie. serialize the result of calling MainDataImpl (a DataResponse object) back to XML and in ServiceFlow deserialize it back to object.
So, the working solution is (as per David's suggestion)
1. Need to add <mulexml:object-to-xml-transformer doc:name="Object to XML"/> before JMS outbound and <mulexml:xml-to-object-transformer doc:name="XML to Object"/> after JMS inbound
2. Need to use the same exchange-pattern on both JMS endpoints
We are getting an error while using proxy client to send an XML to a web service. Here is the configuration:
<flow name="CreateDIMEntry" doc:name="CreateDIMEntry">
<vm:outbound-endpoint exchange-pattern="one-way" path="DIM_VM" doc:name="VM"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="D:\Users\vkamat\Desktop\dim\src\main\resources\addenvelopetopayload.xsl" doc:name="XSLT"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="I am here..#[message.payload]" level="INFO" doc:name="Logger"/>
<set-property propertyName="SOAPAction" value="urn:com.org.ProcessActivity" doc:name="Property"/>
<set-property propertyName="Content-Type" value="application/soap+xml" doc:name="Property"/>
<!-- <set-property propertyName="SOAPAction" value="urn:com.org.ProcessActivity" doc:name="Property"/> -->
<cxf:proxy-client doc:name="SOAP" payload="envelope">
</cxf:proxy-client >
<http:outbound-endpoint exchange-pattern="request-response" host="${dim.host}" port="${dim.port}" method="POST" doc:name="HTTP" path="${dim.path}">
</http:outbound-endpoint>
</flow>
when called this flow with testing flow as below, it works fine
<flow name="DimFlow1" doc:name="DimFlow1">
<file:inbound-endpoint path="D:\Documents\test" responseTimeout="10000" doc:name="File"/>
<flow-ref name="CreateDIMEntry" doc:name="Flow Reference"/>
</flow>
But when integrated in another flow, it gives an error, Giving snippet of main flow from where it is getting called
<async doc:name="Async">
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="D:\addenvelopetopayload.xsl" doc:name="XSLT"/>
<logger message="before DIM-- #[message.payload]" level="INFO" doc:name="Logger"/>
<flow-ref name="CreateDIMEntry" doc:name="Flow Reference"/>
</async>
The error encountered is
********************************************************************************
Message : java.lang.reflect.Method cannot be cast to java.lang.String. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ReversibleXMLStreamReader
--------------------------------------------------------------------------------
Exception stack is:
1. java.lang.reflect.Method cannot be cast to java.lang.String (java.lang.ClassCastException)
org.mule.module.cxf.CxfOutboundMessageProcessor:338 (null)
2. java.lang.reflect.Method cannot be cast to java.lang.String. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: ReversibleXMLStreamReader (org.mule.api.transport.DispatchException)
org.mule.module.cxf.CxfOutboundMessageProcessor:150 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.ClassCastException: java.lang.reflect.Method cannot be cast to java.lang.String
at org.mule.module.cxf.CxfOutboundMessageProcessor.getMethodOrOperationName(CxfOutboundMessageProcessor.java:338)
at org.mule.module.cxf.CxfOutboundMessageProcessor.getOperation(CxfOutboundMessageProcessor.java:356)
at org.mule.module.cxf.CxfOutboundMessageProcessor.doSendWithClient(CxfOutboundMessageProcessor.java:212)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Try setting the following before the CXF client:
<set-variable value="#[flowVars['cxf_operation'].getLocalPart()]" variableName="operation" />
David,
Sending you my configuration again, appreciate your inputs in advance:
<flow name="IntegrationFlow" doc:name="IntegrationFlow">
<jdbc-ee:inbound-endpoint queryTimeout="-1" doc:name="Database" connector-ref="jdbcConnector" queryKey="selectAll" pollingFrequency="10000">
<jdbc-ee:transaction action="NONE"/>
</jdbc-ee:inbound-endpoint>
<logger message="************Payload is #[message.payload]*************" level="INFO" doc:name="Logger"/>
<logger message="************Payload is #[message.payload.destination]*************" level="INFO" doc:name="Logger"/>
<logger message="************Payload is #[message.payload.price]*************" level="INFO" doc:name="Logger"/>
<foreach doc:name="Foreach">
<choice doc:name="Choice">
<when expression="#[message.payload.price > 750]">
<!-- <when expression="#[message.payload.price > 750]"> -->
<processor-chain doc:name="Processor Chain">
<jdbc-ee:maps-to-xml-transformer doc:name="Maps to XML"/>
<jms:outbound-endpoint queue="queue1" connector-ref="jmsConnector" doc:name="JMS"/>
</processor-chain>
</when>
<otherwise>
<custom-transformer returnClass="java.util.List" class="org.mule.confluex.java.MapToListTransformer" doc:name="Java"/>
<logger message="Payload is #[message.payload]" level="INFO" doc:name="Logger1"/>
<jdbc-ee:maps-to-csv-transformer mimeType="text/plain" delimiter="," mappingFile="C:\Downloads\Temp\mapping.xml" doc:name="Maps to CSV"/>
<logger message="CSV Payload is #[message.payload]" level="INFO" doc:name="Logger2"/>
<file:outbound-endpoint path="C:\Downloads\toAmazon" responseTimeout="10000" mimeType="text/plain" connector-ref="fileConnector" doc:name="File"/>
<s3:create-object config-ref="Amazon_S3" bucketName="confluexdemo" contentType="text/plain" key="*.*" doc:name="Amazon S3"/>
</otherwise>
</choice>
</foreach>
</flow>
Here is the Run Log:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'ConfluexDemo' +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO 2013-11-24 19:18:32,563 [[ConfluexDemo].IntegrationFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: ************Payload is {DESTINATION=SFO, PRICE=300, ID=0}*************
INFO 2013-11-24 19:18:32,563 [[ConfluexDemo].IntegrationFlow.stage1.03] org.mule.api.processor.LoggerMessageProcessor: ************Payload is {DESTINATION=MLT, PRICE=1200, ID=1}*************
INFO 2013-11-24 19:18:32,611 [[ConfluexDemo].IntegrationFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: ************Payload is SFO*************
INFO 2013-11-24 19:18:32,611 [[ConfluexDemo].IntegrationFlow.stage1.03] org.mule.api.processor.LoggerMessageProcessor: ************Payload is MLT*************
INFO 2013-11-24 19:18:32,658 [[ConfluexDemo].IntegrationFlow.stage1.03] org.mule.api.processor.LoggerMessageProcessor: ************Payload is 1200*************
INFO 2013-11-24 19:18:32,658 [[ConfluexDemo].IntegrationFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: ************Payload is 300*************
ERROR 2013-11-24 19:18:32,704 [[ConfluexDemo].IntegrationFlow.stage1.03] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Execution of the expression "message.payload.price > 750" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: could not access: price; in class: java.lang.String]
[Near : {... message.payload.price > 750 ....}]
^
[Line: 1, Column: 1] (org.mvel2.PropertyAccessException)
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer:690 (null)
2. Execution of the expression "message.payload.price > 750" failed. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.MVELExpressionLanguage:213 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
3. Execution of the expression "message.payload.price > 750" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
[Error: could not access: price; in class: java.lang.String]
[Near : {... message.payload.price > 750 ....}]
^
[Line: 1, Column: 1]
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:690)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanPropertyAO(ReflectiveAccessorOptimizer.java:472)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:374)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
From my perspective it looks like it is a Map Payload when I print it out, it seemingly seems to read a string when I hit the 'when expression. Hopefully this should give the complete picture. Please let me know if anything else is needed.
For the sake of completion I am also including the JDBC definition:
<spring:beans>
<spring:bean id="SetupDatabaseNotificationListener" class="org.mule.confluex.database.SetupDatabaseNotificationListener"></spring:bean>
<spring:bean id="jdbcDataSource" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName" value="org.apache.derby.jdbc.EmbeddedDriver"></spring:property>
<spring:property name="url" value="jdbc:derby:memory:muleEmbeddedDB;create=true"></spring:property>
</spring:bean>
</spring:beans>
<notifications>
<notification event="CONTEXT"></notification>
<notification-listener ref="SetupDatabaseNotificationListener"></notification-listener>
</notifications>
<jdbc-ee:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="jdbcDataSource" doc:name="Database" queryTimeout="-1" transactionPerMessage="false" validateConnections="true">
<jdbc-ee:query key="selectAll" value="Select * from PriceTickets"></jdbc-ee:query>
</jdbc-ee:connector>
With Regards
S
The error is clear: you are passing a String to the foreach processor instead of something that can be iterated (Iterator, Collection, etc.).
The following flow transforms incoming an JSON payload into a SOAP message which is used in a subflow to make a webservice request. Everything works fine -- i'm able to send a response back for the original (incoming) request, but I want to add a final step to transform the SOAP result into JSON before sending it back to the client.
Here is the flow:
<mule ...>
<data-mapper:config name="json2xml_grf" transformationGraphPath="json2xml.grf" doc:name="DataMapper"/>
<flow name="simpleFlow" doc:name="simpleFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<set-property propertyName="Access-Control-Allow-Origin" value="*" doc:name="Property"/>
<choice doc:name="Choice">
<when expression="#[message.inboundProperties['http.method'] != 'OPTIONS']">
<data-mapper:transform config-ref="json2xml_grf" doc:name="DataMapper"/>
<flow-ref name="invokeCalculatorService" doc:name="invokeCalculator"/>
</when>
<otherwise>
<http:response-builder status="200" doc:name="HTTP Response Builder">
...
</http:response-builder>
</otherwise>
</choice>
</flow>
<flow name="invokeService" doc:name="invokeService">
<cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="Proxy Client">
</cxf:proxy-client>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="/Users/jsleeuw/MuleStudio/workspace/calc/src/main/resources/transformsoap.xslt" doc:name="XSLT"/>
<http:outbound-endpoint exchange-pattern="request-response" doc:name="CalculatorService" method="POST" host="service-host" port="30001"/>
</flow>
</mule>
Putting a DataMapper at the end of the subflow like this:
...
<flow-ref name="invokeCalculatorService" doc:name="invokeCalculator"/>
<data-mapper:transform config-ref="xml2json_grf" doc:name="DataMapper"/>
...
Results in this error:
********************************************************************************
Message : Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: DepthXMLStreamReader
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Content is not allowed in prolog. (org.xml.sax.SAXParseException)
org.apache.xerces.util.ErrorHandlerWrapper:-1 (null)
2. org.xml.sax.SAXParseException: Content is not allowed in prolog. (net.sf.saxon.trans.DynamicError)
net.sf.saxon.event.Sender:308 (null)
3. XPath evaluation failed (org.jetel.exception.JetelRuntimeException)
org.jetel.component.tree.reader.xml.XmlXPathEvaluator:81 (null)
4. Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException)
com.mulesoft.mule.module.datamapper.impl.DefaultGraphExecutor:83 (null)
5. Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: DepthXMLStreamReader (com.mulesoft.mule.module.datamapper.processors.DataMapperMessageExecutionException)
com.mulesoft.mule.module.datamapper.processors.DataMapperMessageProcessor:135 (null)
--------------------------------------------------------------------------------
Whereas putting the datamapper at the end of the subflow ends up blocking the response.
How should I go about transforming my response?
From the Content is not allowed in prolog exception it seems that <flow-ref name="invokeCalculatorService" /> doesn't return a payload that is parseable as XML.
This sub-flow returns a org.apache.cxf.staxutils.DepthXMLStreamReader, which is an javax.xml.stream.XMLStreamReader. The only transformer I know of that can deserialize this type to an XML string is: <mulexml:dom-to-xml-transformer />.
Can you add one just before the data-mapper element?