简体   繁体   中英

Mule ESB SFTP connecter dynamic input Path

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.

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.

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM