WSO2-Call an API to got file from SFTP - wso2-esb

The story is that there is a SFTP server for .csv file, and client wants to call an API to get the .csv data in json format. How do I implement this business scenario with a wso2 esb(4.8.1)? Thanks a lot for any idea.

You can create an ESB API,
Use file connector to search and read the file
Use smooks mediator to convert the content in to XML
Use messageType and ContentType properties to convert the XML payload to JSON

Related

what is the easy way to manually parse the RAML file in mule?

In mule application I am trying to parse RAML file. I knew that APIKit is doing same as it creates flows after parsing the RAML file. But still, what if I want to parse it in middle of the flow manually?
I have seen the raml parsers available but not finding the proper usage of those javascript libraries or java libraries on how to use them in mule application..
Yes you can parse your RAML in your java application using java class or groovy component implementing java.
There are java parser available like RamlModelBuilder which you can use to parse your application RAML like validation of your RAML file, getting APIs name, getting all resources name, method name, scopes, security schema and their names, query parameters, headers and many more...
Just check the example how it is used here. You can simply create a java class and get your RAML parsed
https://github.com/anirban37/Anirban-Custom-Oauth-Policy/blob/master/Anirban-RAML-Oauth-V3/OauthPolicies.xml#L594.
ramlModelResult = new RamlModelBuilder().buildApi(ac.getRaml())
will give you the current RAML file access of the application in the java class
Theres nothing in Mule to work with the RAML file at runtime.
But you can create any Java component that uses RAML Java libraries and invoke that from Mule in your flows.
The Mule4 SDK is one way of extending mule through Java.
For more information on Mule SDK can be found here https://mule4-docs.mulesoft.com/mule-sdk/v/1.1/
You can also invoke Java classes but they need to be decoupled from the Mule API and you need to extract any variables, properties or payload and explicitly pass the values to your class. For example passing a static String and a flow var as arguments to a Java constructor:
<java:new class="com.foo.AppleEater" constructor="MyClass(String, Apple)">
<java:args>#[{name: 'some string arg', apple: vars.apple}]</java:args>
</java:new>
In your class you could use the RAML Java libraries, and pass the file or path to RAML file to load from the classpath.
More on Java integration with Mule 4 here: https://docs.mulesoft.com/mule-runtime/4.1/intro-java-integration

Consume REST API request body (xml) into SAP BO

How can i Consume REST API request body (xml) into SAP BO (IDT) or Crystal report for enterprise 2016.(not Designer)
NOTE - we don't want to introduce any WEB SERVICE here as a solution .
Brief: The requirement is to parse a XML received as part of request body in API and use that XML as a source to IDT and
generate PDF from that using Crystal Reports.
Thanks
I've never done it in the real world, but IDT does support raw XML files as a data source. When creating a new connection, select Generic -> XML Files -> XML File Connector.

How to handle files in an SOA architecture

I have an enterprise service bus with a collection of services. There is an HTML5 user interface that allows customers to perform all sorts of selfcare actions. The UI uses JavaScripts that communicate with the ESB in JSON format through an API server.
Now I want to offer the customer the possibility to upload documents. I can base64 the document and send it as a JSON field, but that doesn't seem right. What is a good pattern I could use?
It does not sound right because it is not right.
In this cases you should a write the file to a write only public FTP given it a GUID name and then send a message to the service giving details about the files. On the service side once a message with the file details is received, store the metadata in your persistence layer and copy the files to a private FTP.
Something like this:
Claim Check Pattern

Best way to parse unknown XML fom web service

I am working on a project where I required to parse XML response coming from web service. I don't know anything about the structure of response. I am given XML elements to gather data for, and the data is relational so elements represents columns in relational table.
I tried the WSDL approach where I can parse for method name and its response type. Based on that I can parse with NSXMLParser. The problem was I didn't find any WSDL parser which does this for me.
Any suggestions?!
Thanks,
Jignesh
I like to use this OpenSource library on GitHub
It will allow you to turn the XML string into an NSDictionary which you can the use dynamically.

Retrieve generic list in JSON format on client side

I send generic list of data by wcf service using REST. I understand that on server side it was serializing, and on client side deserializing. How can I get data before deserialization in JSON format to show it to user ?
Take a look at this page, and drop the automatic (de)serialization.
I use DownloadData method from WebClient class to invoke RESTful service and returned data was converted to string using Encoding class :)