Using Mule Studio
Version: 3.5.0
Build Id: 201402101410
I have a very simple flow. I need to pick up a file from one ftp server and transfer it to another ftp server. When the file is written to the target, the filename looks like some kind of UUId rather than the original file name. How do I get the file name to carry through? I have tried #[header:originalFilename] but that throws an error so I assume that maybe it is only for file connectors. Here is my flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:ftp="http://www.mulesoft.org/schema/mule/ftp" 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:context="http://www.springframework.org/schema/context" version="CE-3.4.0"
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.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.mulesoft.org/schema/mule/ftp http://www.mulesoft.org/schema/mule/ftp/current/mule-ftp.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<context:property-placeholder location="environment.properties"/>
<flow name="sli-ftpFlow1" doc:name="sli-ftpFlow1">
<ftp:inbound-endpoint host="${local.ftp.host}" port="${local.ftp.port}" path="${local.ftp.path}" user="${local.ftp.user}" password="${local.ftp.pass}" responseTimeout="10000" doc:name="FTP" pollingFrequency="${local.ftp.pollingFreq}" binary="true" passive="false"/>
<logger message="Transferring file:" level="INFO" doc:name="Logger"/>
<ftp:outbound-endpoint host="${sli.ftp.host}" port="${sli.ftp.port}" path="${sli.ftp.path}" user="${sli.ftp.user}" password="${sli.ftp.pass}" responseTimeout="10000" doc:name="FTP" outputPattern="#[header:originalFilename]"/>
</flow>
</mule>
Stack Trace:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'sli-ftp' +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2014-03-19 22:10:38,058 [[sli-ftp].sli-ftpFlow1.stage1.02] INFO org.mule.api.processor.LoggerMessageProcessor - Transferring file:
2014-03-19 22:10:38,071 [[sli-ftp].connector.ftp.mule.default.dispatcher.01] INFO org.mule.lifecycle.AbstractLifecycleManager - Initialising: 'connector.ftp.mule.default.dispatcher.1035665885'. Object is: FtpMessageDispatcher
2014-03-19 22:10:38,071 [[sli-ftp].connector.ftp.mule.default.dispatcher.01] INFO org.mule.lifecycle.AbstractLifecycleManager - Starting: 'connector.ftp.mule.default.dispatcher.1035665885'. Object is: FtpMessageDispatcher
2014-03-19 22:10:38,078 [[sli-ftp].connector.ftp.mule.default.dispatcher.01] ERROR org.mule.exception.DefaultMessagingExceptionStrategy -
********************************************************************************
Message : Streaming failed. Could not get output stream. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=ftp://esbuser%40newpig.com:<password>#webuatint/SLI-Mock, connector=FtpConnector
{
name=connector.ftp.mule.default
lifecycle=start
this=a40c648
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[ftp]
serviceOverrides=<none>
}
, name='endpoint.ftp.webuatint.21.SLI.Mock', mep=ONE_WAY, properties={outputPattern=#[header:originalFilename]}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: byte[]
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required. (org.mule.api.expression.RequiredValueException)
org.mule.expression.ExpressionUtils:239 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/RequiredValueException.html)
2. Streaming failed. Could not get output stream. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=ftp://esbuser%40newpig.com:<password>#webuatint/SLI-Mock, connector=FtpConnector
{
name=connector.ftp.mule.default
lifecycle=start
this=a40c648
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[ftp]
serviceOverrides=<none>
}
, name='endpoint.ftp.webuatint.21.SLI.Mock', mep=ONE_WAY, properties={outputPattern=#[header:originalFilename]}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: byte[] (org.mule.api.transport.DispatchException)
org.mule.transport.ftp.FtpConnector:602 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.expression.RequiredValueException: Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required.
at org.mule.expression.ExpressionUtils.getPropertyInternal(ExpressionUtils.java:239)
at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:67)
at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:50)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Stack Trace with #[header:originalFilename] in Logger:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'sli-ftp' +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2014-03-20 08:15:35,918 [[sli-ftp].sli-ftpFlow1.stage1.02] ERROR org.mule.exception.DefaultMessagingExceptionStrategy -
********************************************************************************
Message : Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required. (org.mule.api.expression.RequiredValueException). Message payload is of type: byte[]
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required. (org.mule.api.expression.RequiredValueException)
org.mule.expression.ExpressionUtils:239 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/RequiredValueException.html)
2. Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required. (org.mule.api.expression.RequiredValueException). Message payload is of type: byte[] (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:
org.mule.api.expression.RequiredValueException: Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required.
at org.mule.expression.ExpressionUtils.getPropertyInternal(ExpressionUtils.java:239)
at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:67)
at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:50)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Use MEL: #[message.inboundProperties.originalFilename].
I think the scope is the issue.
This was changed in 3.4 -http://www.mulesoft.org/documentation/display/current/Mule+ESB+3.4.0+Release+Notes
Mule 3.4+ originalFilename is in the inbound scope. So use: #[message.inboundProperties.originalFilename]
Mule < 3.4 originalFilename is in the outbound scope. So use: #[message.outboundProperties.originalFilename]
Issue is documented here: https://www.mulesoft.org/jira/browse/MULE-6743
Related
I have a problem with setting Connection Timeout on HTTP Request Connector (not to confuse with Response Timeout) with Mule 3.7.
Configuration I'm using is not changing this arbitrary ~5 second delay between initiating connection and throwing "java.net.ConnectException: Connect timeout", even if https://docs.mulesoft.com/mule-user-guide/v/3.7/tcp-transport-reference suggests that setting connectionTimeout attribute should do the trick.
What am I missing? Is there any other way to specify this timeout? Or is this dependent on the OS?
Flow ilustrating the problem:
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp" xmlns:tls="http://www.mulesoft.org/schema/mule/tls" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" 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/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd
http://www.mulesoft.org/schema/mule/tcp http://www.mulesoft.org/schema/mule/tcp/current/mule-tcp.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:request-config name="HTTP_Request_Configuration" host="123.123.123.123" port="4444" doc:name="HTTP Request Configuration" responseTimeout="30000" usePersistentConnections="false" >
<tcp:client-socket-properties connectionTimeout="30000" timeout="30000"/>
</http:request-config>
<flow name="connectionTimeoutTestFlow">
<quartz:inbound-endpoint jobName="Knock" repeatInterval="60000" responseTimeout="100000" doc:name="Quartz">
<quartz:event-generator-job/>
</quartz:inbound-endpoint>
<logger message="Start Request" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/debug/index.jsp" method="GET" doc:name="HTTP"/>
</flow>
</mule>
Output:
INFO 2016-02-10 12:53:55,736 [[connectionTimeoutTest].connectionTimeoutTestFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Start Request
ERROR 2016-02-10 12:54:01,321 [[connectionTimeoutTest].connectionTimeoutTestFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Error sending HTTP request. Message payload is of type: NullPayload
Type : org.mule.api.MessagingException
Code : MULE_ERROR--2
Payload : {NullPayload}
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html
********************************************************************************
Exception stack is:
1. Connect timeout (java.net.ConnectException)
org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectCompletionHandler:1283 (null)
2. java.net.ConnectException: Connect timeout (java.util.concurrent.ExecutionException)
org.glassfish.grizzly.impl.SafeFutureImpl$Sync:349 (null)
3. java.util.concurrent.ExecutionException: java.net.ConnectException: Connect timeout (java.io.IOException)
org.mule.module.http.internal.request.grizzly.GrizzlyHttpClient:234 (null)
4. Error sending HTTP request. Message payload is of type: NullPayload (org.mule.api.MessagingException)
org.mule.module.http.internal.request.DefaultHttpRequester:287 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
********************************************************************************
Root Exception stack trace:
java.net.ConnectException: Connect timeout
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectCompletionHandler.cancelled(SingleEndpointPool.java:1283)
at org.glassfish.grizzly.impl.SafeFutureImpl.notifyCompletionHandlers(SafeFutureImpl.java:185)
at org.glassfish.grizzly.impl.SafeFutureImpl.done(SafeFutureImpl.java:277)
at org.glassfish.grizzly.impl.SafeFutureImpl$Sync.innerCancel(SafeFutureImpl.java:389)
at org.glassfish.grizzly.impl.SafeFutureImpl.cancel(SafeFutureImpl.java:247)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1351)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1343)
at org.glassfish.grizzly.utils.DelayedExecutor$DelayedRunnable.run(DelayedExecutor.java:158)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:744)
********************************************************************************
you can use a global configuration, defined at the top of your .xml, in which you specify Timeout for all your services, in example:
<configuration defaultTransactionTimeout="300000" defaultResponseTimeout="300000" doc:name="Configuration">
<default-threading-profile poolExhaustedAction="RUN"/>
</configuration>
I hope this helps.
Try to increase the http timeout in the http global config, you can do something like below:
<https:connector
name="HTTP_HTTPS"
cookieSpec="netscape"
validateConnections="false"
sendBufferSize="0"
receiveBufferSize="0"
receiveBacklog="0"
clientSoTimeout="1000"
serverSoTimeout="1000"
socketSoLinger="1000"
doc:name="HTTP-HTTPS"
socketMaxWait="1000"
connectionTimeout="1000"
keepAlive="true">
I have Mule batch commit as:
<batch:step name="Batch_Step1">
<enricher source="#[message.payload]" target="#[recordVars.accountJson]" doc:name="Message Enricher">
<json:object-to-json-transformer doc:name="Object to JSON"/>
</enricher>
<batch:set-record-variable variableName="client_id" value="#[message.payload.client_id]" doc:name="client_id"/>
<batch:commit size="10" doc:name="Batch Commit">
<sfdc:query config-ref="SFDC_Config" query="dsql:SELECT Id FROM Account WHERE Client_ID__c = '#[message.payload.client_id]'" doc:name="Account-Query"/>
<set-payload value="#[message.payload.hasNext() ? message.payload.next(): 'none']" doc:name="sfdc-data"/>
</batch:commit>
</batch:step>
If i don't put batch-commit, application works fine, but If i use batch-commit, I am getting below error message:
INFO 2015-07-29 14:19:44,636 [batch-job-clientaccount-Batch-work-manager.01] com.mulesoft.module.batch.DefaultBatchStep: Found exception processing record on step 'Batch_Step1' for job instance '86987df0-3637-11e5-81ea-0026b9eef95d' of job 'clientaccount-Batch'.
This is the first record to show this exception on this step for this job instance. Subsequent records with the same failureswill not be logged for performance and log readability reasons:
********************************************************************************
Message : Failed to invoke query. Message payload is of type: RegularImmutableList
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. com.google.common.collect.RegularImmutableList cannot be cast to java.util.Map (java.lang.ClassCastException)
org.mule.mvel2.optimizers.impl.refl.nodes.MapAccessor:42 (null)
2. cannot invoke getter: getPayload [declr.class: org.mule.el.context.MessageContext; act.class: org.mule.el.context.MessageContext] (see trace) (java.lang.RuntimeException)
org.mule.mvel2.optimizers.impl.refl.nodes.GetterAccessor:74 (null)
3. Execution of the expression "message.payload.client_id" failed. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.MVELExpressionLanguage:202 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
4. Failed to invoke query. Message payload is of type: RegularImmutableList (org.mule.api.MessagingException)
org.mule.devkit.processor.DevkitBasedMessageProcessor:133 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.ClassCastException: com.google.common.collect.RegularImmutableList cannot be cast to java.util.Map
at org.mule.mvel2.optimizers.impl.refl.nodes.MapAccessor.getValue(MapAccessor.java:42)
at org.mule.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:40)
at org.mule.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Question 2)
Not able to use recordVars inside batch commit.Getting error as:
Exception stack is:
1. No record could be found in payload or in flow variable BATCH_RECORD (java.lang.IllegalStateException)
com.mulesoft.module.batch.record.BatchUtils:56 (null)
2. [Error: No record could be found in payload or in flow variable BATCH_RECORD]
[Near : {... recordVars.client_id ....}]
^
[Line: 1, Column: 1] (org.mule.mvel2.CompileException)
I am trying to use a mule requester component for SFTP. How do I give the file name as part of the request argument? This is my flow:
<flow name="Move_Doc_To_Temp_Location" doc:name="Move_Doc_To_Temp_Location">
<jdbc-ee:inbound-endpoint queryKey="Select_Document" queryTimeout="-1" pollingFrequency="30000" connector-ref="LoanApp_Database" doc:name="Select_Doc_To_be_moved"/>
<set-variable variableName="OriginalPayload" value="#[payload]" doc:name="OriginalPayload"/>
<logger message="#[payload['DocID']] - #[payload['Location']]" level="INFO" category="Document to be moved" doc:name="Logger"/>
<!-- <mulerequester:request config-ref="Mule_Requester" resource="file:///#[payload['Location']]" doc:name="Mule Requester"/> -->
<mulerequester:request config-ref="Mule_Requester" resource="sftp://user:Pwd#Hostname#[payload['Location']]" doc:name="Mule Requester"/>
<file:outbound-endpoint path="C:\Users\jvas\Desktop\testfiles" outputPattern="#[header:originalFilename]" responseTimeout="10000" doc:name="File"/>
</flow>
The location value resolves to /opt/Documents/test.txt. When I specify the filename like this, it throws me an error:
ERROR 2014-07-24 05:51:12,358
[[loanapp_document_flow].Move_Doc_To_Temp_Location.stage1.02]
org.mule.exception.DefaultMessagingExceptionStrategy:
******************************************************************************** Message : Failed to receive event over:
DefaultInboundEndpoint{endpointUri=sftp://muledev:#nylicvmmuledev/opt/Documents/test.txt,
connector=SftpConnector { name=SFTP1 lifecycle=start this=aa033b
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true connected=true
supportedProtocols=[sftp] serviceOverrides= } ,
name='endpoint.sftp.nylicvmmuledev.opt.Documents.test.txt',
mep=ONE_WAY, properties={},
transactionConfig=Transaction{factory=null, action=INDIFFERENT,
timeout=0}, deleteUnacceptedMessages=false, initialState=started,
responseTimeout=10000, endpointEncoding=UTF-8,
disableTransportTransformer=false} (timeout=1000) Code
: MULE_ERROR-92
-------------------------------------------------------------------------------- Exception stack is:
Error 'No such file' occurred when trying to CDW to '/opt/Documents/test.txt'. (java.io.IOException)
org.mule.transport.sftp.SftpClient:102 (null)
Failed to receive event over: DefaultInboundEndpoint{endpointUri=sftp://muledev:#nylicvmmuledev/opt/Documents/test.txt,
connector=SftpConnector { name=SFTP1 lifecycle=start this=aa033b
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true connected=true
supportedProtocols=[sftp] serviceOverrides= } ,
name='endpoint.sftp.nylicvmmuledev.opt.Documents.test.txt',
mep=ONE_WAY, properties={},
transactionConfig=Transaction{factory=null, action=INDIFFERENT,
timeout=0}, deleteUnacceptedMessages=false, initialState=started,
responseTimeout=10000, endpointEncoding=UTF-8,
disableTransportTransformer=false} (timeout=1000)
(org.mule.api.transport.ReceiveException)
org.mule.transport.AbstractMessageRequester:132
(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/ReceiveException.html)
-------------------------------------------------------------------------------- Root Exception stack trace: java.io.IOException: Error 'No such file'
occurred when trying to CDW to '/opt/Documents/test.txt'. at
org.mule.transport.sftp.SftpClient.changeWorkingDirectory(SftpClient.java:102)
at
org.mule.transport.sftp.SftpConnector.createSftpClient(SftpConnector.java:196)
at
org.mule.transport.sftp.SftpConnector.createSftpClient(SftpConnector.java:174)
3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Now I tried removing the file name from the location, and the SFTP was successful, but it has randomly chosen a file. The file has all permissions for SFTP and I am able to do the SFTP via command line successfully. I have referred to the documentation for the SFTP URL and this is what it provides for resolving the file name from the URL : https://datatracker.ietf.org/doc/html/draft-ietf-secsh-scp-sftp-ssh-uri-04#section-4.1
Retrieve file.txt from the user's home directory on the host at
host.example.com using SFTP using username user. This example
assumes that the implementation supports the indication of a path
relative to the home directory using a leading tilde.
sftp://user#host.example.com/~/file.txt
Retrieve file.txt from the absolute path /dir/path on the host at
host.example.com using SFTP using username user.
sftp://user#host.example.com/dir/path/file.txt
The Mule SFTP connector can not take the filename in the address. Instead you need to use a filename filter. However, unfortunately I think the requestor module ignores the filters configured on the endpoint as mentioned here: http://forum.mulesoft.org/mulesoft/topics/mule_module_requester_add_support_for_filenamefilter
You could however use a script to read a file over sftp mid flow. Something like:
<scripting:transformer>
<scripting:script engine="Groovy">
<scripting:text>
def endpointBuilder = muleContext.endpointFactory.getEndpointBuilder(
"sftp://${sftp.username}#${sftp.host}:${sftp.port}/${sftp.path}?identityFile=${app.home}/${sftp.keyPath}&passphrase=${sftp.passphrase}&connector=sftp-csv")
endpointBuilder.addMessageProcessor(new org.mule.routing.MessageFilter(new org.mule.transport.file.filters.FilenameWildcardFilter(sessionVars.expectedFilename)))
def inboundEndpoint = endpointBuilder.buildInboundEndpoint()
inboundEndpoint.request(30000L)
</scripting:text>
</scripting:script>
</scripting:transformer>
I am trying to develop a mule flow which takes a xml in the form of a string from a JMS queue and converts it into a POJO. I am using JAXB annotations to define the mappings between the xml and the class attributes. Below is the sample xml that is received on the JMS queue as a string.
<FCUBS_NOTIFICATION xmlns="http://fcubs.ofss.com/notify/NOTIF_UP_TRANSACTION">
<FCUBS_NOTIF_HEADER>
<MSGID>9132820000357947</MSGID>
</FCUBS_NOTIF_HEADER>
</FCUBS_NOTIFICATION>
My POJO class is as below:
package com.bean;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name="FCUBS_NOTIFICATION")
public class Notification {
private String MSGID;
public String getMSGID() {
return MSGID;
}
#XmlElement(name="MSGID")
public void setMSGID(String mSGID) {
MSGID = mSGID;
}
}
I have a jaxb.index file in the com.bean package consisting of only one bean
Notification
My mule flow config file is as below:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" 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" version="EE-3.4.1" 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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd">
<spring:beans>
<spring:bean name="myJaxb" class="javax.xml.bind.JAXBContext" factory-method="newInstance">
<!-- colon-separated (:) list of package names where JAXB classes exist -->
<spring:constructor-arg value="com.bean"/>
</spring:bean>
</spring:beans>
<jms:activemq-connector name="Active_MQ" specification="1.1" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="JMS-exampleFlow1" doc:name="JMS-exampleFlow1">
<jms:inbound-endpoint queue="NotificationQueue" connector-ref="Active_MQ" doc:name="JMS"/>
<logger message="Payload after picking message from queue is #[message.payload]" level="INFO" doc:name="Logger"/>
<mulexml:xml-to-object-transformer returnClass="com.bean.Notification" doc:name="XML to Object"/>
<logger level="INFO" doc:name="Logger" message="Payload after xml to object transformation is #[message.payload]"/>
</flow>
</mule>
I am using Mule Studio for development and below is the error I get -
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'jms-example' +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO 2013-11-27 16:19:44,225 [[jms-example].JMS-exampleFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Payload after picking message from queue is <FCUBS_NOTIFICATION xmlns="http://fcubs.ofss.com/notify/NOTIF_UP_TRANSACTION"><FCUBS_NOTIF_HEADER><MSGID>9132820000357947</MSGID></FCUBS_NOTIF_HEADER></FCUBS_NOTIFICATION>
ERROR 2013-11-27 16:19:44,227 [[jms-example].JMS-exampleFlow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : FCUBS_NOTIFICATION (com.thoughtworks.xstream.mapper.CannotResolveClassException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. FCUBS_NOTIFICATION (com.thoughtworks.xstream.mapper.CannotResolveClassException)
com.thoughtworks.xstream.mapper.DefaultMapper:56 (null)
2. FCUBS_NOTIFICATION (com.thoughtworks.xstream.mapper.CannotResolveClassException). Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException)
org.mule.transformer.AbstractTransformer:139 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.thoughtworks.xstream.mapper.CannotResolveClassException: FCUBS_NOTIFICATION
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)
at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Is there anything I am missing here ?
Thanks in advance.
The serialization/deserialization in the xml-to-object-transformer is done through XStream, so JAXB won't matter at that point.
You would need an alias:
<mulexml:xml-to-object-transformer returnClass="com.bean.Notification" doc:name="XML to Object">
<mulexml:alias name="FCUBS_NOTIFICATION" class="com.bean.Notification"/>
</mulexml:xml-to-object-transformer>
In my mule application i'm trying to send message (xml) to Rabbit MQ exchange.
In my application i defined:
<scripting:component doc:name="CreateXML">
<scripting:script engine="Groovy"><![
def xml = "" //previously created xml
return xml]]></scripting:script>
</scripting:component>
<amqp:outbound-endpoint
exchangeName="test-exchange.srv"
routingKey="auc.guest1.test"
connector-ref="AMQPRabbitConnector" />
And my connector to Rabbit MQ looks like:
<amqp:connector
name="AMQPRabbitConnector"
virtualHost="dev"
username="guest"
password="guest"
activeDeclarationsOnly="false"/>
when I run my application I'm an getting exception after some time I sent messages:
ERROR 2013-07-05 10:53:34,020 [[fis-bps-pgm-mule].AMQPRabbitConnector.dispatcher.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=amqp://test-exchange.srv, connector=AmqpConnector
{
name=AMQPRabbitConnector
lifecycle=start
this=2bfec68b
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[amqp]
serviceOverrides=<none>
}
}
, name='endpoint.amqp.test-exchange.srv', mep=ONE_WAY, properties={routingKey=auc.guest1.test}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: AmqpMessage
Type : org.mule.api.transport.DispatchException
Code : MULE_ERROR--2
Payload : org.mule.transport.amqp.AmqpMessage#68e64543[consumerTag=<null>,envelope=com.rabbitmq.client.Envelope#7b2fc059,body={60,63,120,109,108,32,118,101,114,115,105,111,110,61,39,49,46,48,39,63,62,10,60,99,114,101,9
I resoloved problem.
In prevous element of the flow, I'm setting outbound properties, without that connector working fine.