Issues in JSON to XML and Upload to FTP in Ballerina Integrator

136 Views Asked by At

I am trying samples given in Ballerina integrator tutorials, while running json to xml and then upload into ftp sample facing the issue:

error org.wso2.ei.b7a.ftp.core.util.BallerinaFTPException.

I knew the reason for this issue but don't know where i have to put that command. Please help me to sort out the issue.

Reason for the issue is: ftp credentials are mentioned in conf file, I put conf file under the root directory but it doesn't refer. Need to give

b7a.config.file=src/upload_to_ftp/resources/ballerina.conf

But I don't know where I have to give this?

Thanks in Advance.

2

There are 2 best solutions below

0
On BEST ANSWER

I have passed credentials directly to ftpConfig then its working fine. Conversion happened and converted file has been uploaded into ftp location successfully

ftp:ClientEndpointConfig ftpConfig = { protocol: ftp:SFTP, host: "corpsftp.dfaDFDA.com", port: 22, secureSocket: { basicAuth: { username: "DDFDS", password: "FADFHYFGJ" } } };

Output { "Message": "Employee records uploaded successfully." }

enter image description here

4
On

You can add -b7a.config.file when running the generated jar file.

Official documentation : https://ei.docs.wso2.com/en/latest/ballerina-integrator/develop/running-on-jvm/

However, keeping the ballerina.conf file in the root directory should work. Ballerina looks for the conf file automatically when running. Make sure the conf file is outside the src directory.


For the error that you have mentioned, could you add in logs to see if the json has been converted to xml properly? Since the code is structured in a way that checks if the conversion has occurred, it should print an xml

if (employee is xml) {
            var ftpResult = ftp->put(remoteLocation, employee);
            if (ftpResult is error) {
                log:printError("Error", ftpResult);
                response.setJsonPayload({Message: "Error occurred uploading file to FTP.", Resason: ftpResult.reason()});
            } else {
                response.setJsonPayload({Message: "Employee records uploaded successfully."});
            }
        } else {
            response.setJsonPayload({Message: "Error occurred tranforming json to xml.", Resason: employee.reason()});
        }

The if( employee is xml ) part will check if the conversion is successful.

The same applies after the file is sent to the server. If the file hasnt been sent, then the ftpResult would be an error. Basically, if you got the message { Message : "Employee records uploaded successfully" } then all the checks should have passed.