Browse Category by node.js
View Post

OTN Appreciation Day: #ThanksOTN Twitter feed with Oracle MCS and Oracle JET

As we can implement our Custom APIs using node.js, we can almost use any of the available node modules like for example Oracle MCS: Creating PDF files in Custom APIs.
In a project we are developing we have the requirement to display a twitter timeline of a hashtag.

Today is the OTN Appreciation Day and in this post we are going to make a #ThanksOTN twitter feed using Oracle MCS and Oracle JET.

Continue Reading

View Post

Rio2016 Medal Standings (Part1): Using MCS internal Database

In this 3-part post series I will show how to build an Oracle MAX Application that will display the medal standing in Rio 2016.

This is what we are going to do in order to achieve our goal.

First we are going to use Oracle MCS internal database to store the urls of the flags that we will display in the application and we will also create a custom API to retrieve the records from the database.

Continue Reading

View Post

Oracle MCS: Creating PDF files in Custom APIs

Oracle Mobile Cloud Service allows you to implement Custom API using node.js. This is a powerful feature as it allows you to use any of the existing node.js modules in your implementation.

In this post I am going to show you how to create and download a PDF file that will contain the weather information for the provided city, that we will get calling a REST Connector.


If you don’t know how to create a REST Connector check this post: Oracle Mobile Cloud Service: Create an API that calls a REST web service

First we need to create a connector. This is the URL we are going to use:

http://api.openweathermap.org/data/2.5/forecast/daily
Openweathermap is a free rest api where we can get the weather forecast.

We have to create some rules as we need to pass some parameters into the url. These are default values that we can override when calling the connector.

The next step is to create a Custom API.
We are going to allow annonymous calls to make it easier.

We need an endpoint with a parameter. This enpoint will have a GET method.

The last step is to implement our Custom API.
Now we need to download the JavaScript Scaffold.
At this point you need to have node.js installed (You can donwload if from this link)
After that we need to install pdfkit module.
Before executing ‘npm install pdfkit’ you need to be in the folder where package.json is.
After that node_modules folder will be created.
The next step is to edit package.json file to add the dependencies.
We need to add pdfkit and also we have to add the connector in oracleMobile dependencies.
PDFKit allows us to create PDF files and add text, images vector graphics, links, etc to our pdf.
In this example I am just creating one line (line 41) and inserting text based on the values returned by the connector.
We cannot test the API in MCS tester as the file cannot be downloaded, but we can use postman to do it.
We can see that the downloaded pdf contains Munich weather information for the next 3 days.

MCS: Calling SOAP connector bypassing XML/JSON translator

In the MCS project we are working we have to create some SOAP Connectors to integrate with Siebel. A great thing of MCS is that although we are going to consume a SOAP web service, the XML payload is automatically translated into JSON. You can get more info in MCS Documentation.

I would like to thank Oracle Mobile PM  team, specially Grant Ronald and Frédéric Desbiens for their great help and for sharing best practices about this issue.

As soon as we create a SOAP Connector and try to test it we can see that the body we have to provide is a JSON.

But there are some cases where the translator is not perfect. We had a problem with some services that had an XML structure like this:

The translator seems not to add the  namespaces in the header therefore Siebel cannot parse the request.

The solution is to send a XML instead of a JSON, bypassing the translator.
We can test this in SOAP Connector tester. As we need the required XML, we can get it in any web service client tool like for example SoapUI.

We also have to set “Content-Type: application/xml;charset:UTF-8” and “Accept: application/xml” as header parameters.

If we test the Connector we can see that the web service call is working.

How do we implement the Custom API to send a XML payload to the connector?
The answer is to set the XML we want to send as the body of the request and set the header parameters we previously use to test the connector.

But, is this the recommended approach? Yes it is, but instead of sending a String with the SOAP message it is more secure to send it as a JavaScript object.

In order to implement this we have to follow some steps:

  1. Download and Install Node.js. link
  2. Install xml2js module.
  3. In this example test_rrs is the directory where the package.json file resides.

  4. Add xml2js as a dependency in package.json
  5. Moving to our javascript file, as I already stated before the first idea was to build the SOAP message as a string. This first image is the base implementation and we are going to make some changes to it.
  6. First we need to add var xml2js = require(‘xml2js’); at the top of our implementation.

    This is the tricky part, we need to create a JSON like this.
    ‘ $ ‘ means that we want to add attributes to the XML element.
    ‘ _ ‘ means that we want to have something inside that element.

    The last thing we have to do is to create a xml2js.Builder object and execute buildObject method using the json object we have just create. The result of this method is the body we are going to send.
After the implementation is done we just have to put everything inside the zip file and upload it to MCS.
If you want to know more about xml2js click here.

Oracle Mobile Cloud Service 3 Days Workshop in Madrid

Last week I had the chance to attend a Mobile Cloud Service 3 days workshop in Madrid. This was the first MCS training in Spain where some partners and I were able to get a good insight about what MCS offers and also a complete hands-on.

If you want to know MCS functionality you can check my previous post: Oracle Mobile Cloud Service overview.

Although I already attended Oracle Summer Camps workshop in Lisbon, we are in the middle of a MCS development and  this workshop was a perfect fit for mastering my MCS skills and also any question we made was perfectly answer by Mireille Duroussaud (Senior Principal Product Manager).

We were also able to see some of the features that will bring the next versions of Mobile Cloud Service like Mobile Application Accelerator (Oracle MAX), and hear of others like for example a JavaScript editor for implementing and debugging APIs right in the browser.
I was really impressed about Oracle MAX becasue building a Mobile Application connected to Mobile Cloud Service was just a matter of 10 minutes. Although the things you can do with Oracle MAX are limitted, it is likely possible that we will be able to donwload the source code of the generated application to extend it wich is a nice feature.
I think this is a must-attend workshop it you are planning to start a Mobile Cloud Service project anytime soon. You can also check Oracle Mobile Platform Youtube channel where you can find more than 50 videos about MCS.
  • 1
  • 2