Reputation: 31
I want to give the input path from database in mule S FTP INBOUND Connector where it will pick up file according to database Path. But I am unable to solve this issue ; Is this possible or not...? Anybody can you please answer on this ? please.
Upvotes: 0
Views: 1014
Reputation: 511
Use a poll component in mule. Inside the poll component add a Java Component. And make the Java class implements Callable.
In the OnCall method make a custom Endpoint like this :
public Object onCall(MuleEventContext eventContext) throws Exception {
EndpointBuilder endpointBuilder = muleEventContext
.getMuleContext()
.getEndpointFactory()
.getEndpointBuilder(
protocol+"://" + username + ":"
+ password+ "@"
+ host + ":"+port
+ path );
InboundEndpoint inboundEndPoint = endpointBuilder
.buildInboundEndpoint();
Now these user name and password you can fetch from DB. Either put a REST layer on top of DB and expose Webservices to fetch Data and using an HTTP client fetch the data and dynamically populate username,password,host and path.
Upvotes: 2
Reputation: 51
Yes it is possible by writing a groovy script. In the groovy script you can reference a flowVar(ex: imageRef) that will have the path of the file to retrieve:
<scripting:component doc:name="Script">
<scripting:script engine="Groovy">
<![CDATA[def ftpFileUri = "ftp://${ftp.username}:${ftp.password}@${ftp.host}/${ftp.path}" + message.getInvocationProperty('imageRef') + ".jpg";
muleContext.client.request(ftpFileUri, 30000L);]]>
</scripting:script>
</scripting:component>
In your case, prior to this you would just need to query the database and store the value in your flowVar.
also if the file does not exist, you can catch the groovy exception in a "an exception strategy" and log it with:
<logger message="#[groovy:message.getExceptionPayload().getRootException().getMessage()]" level="ERROR" doc:name="Logger"></logger>
Upvotes: 0
Reputation: 526
You cannot use MEL to define which path your SFTP is going to use. Yet you can load the path from a properties file as follows. HTH.
<sftp:endpoint name="SFTP-Endpoint"
connector-ref="SFTP" host="${sftp.host}" user="${sftp.user}"
password="${sftp.jdeBillingReportPassword}" port="${sftp.port}"
path="${sftp.path}" />
Upvotes: 0