Some Tips for Writing JavaScript Adapters for IBM MobileFirst
Join the DZone community and get the full member experience.
Join For Freei’ve been doing a lot of playing lately with mobilefirst , and one of the cooler features it has is the ability to write adapters in javascript. i blogged about this last week and today i thought i’d share a few tips/notes for folks who may be new to this feature.
first and foremost, it is important to remember that you are not using a full node.js-style stack. you are working with a subset of the rhino container developed by mozilla. this is a javascript engine that runs within the context of a java server. however, this is not a full rhino implementation as some features, like load(), are not implemented. unfortunately we don’t document these differences (yet – i’m filing an enhancement request for this today).
second, you cannot debug via console.log. instead, simply use the wl.logger api as shown below:
function getdetail(id) { wl.logger.info("getdetail, requesting id "+id); return wl.server.invokesqlstatement({ preparedstatement : getdetailstmt, parameters:[id] }); }
and where do those logs show up? type
mfp logs
at the command line to be shown where your logs exist:
then you can simply go to that directory and look at messages.log. i’d simply
tail -f
it while you work to see incoming messages. the log is a bit verbose, but you could use other tools to filter it out.
the third point to consider is that adapters are session-based. that means you can persist data by simply using a global javascript variable, but it will not be global to the server.
finally, and i’ve mentioned these before, but don’t forget that you need to “build/deploy” when you edit your adapter files. you can use the bd shortcut for adapters just like you do for your web assets:
mfp bd
. you can also test your adapters directly from the command line using
mfp invoke
.
Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Chaining API Requests With API Gateway
-
A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
-
Integrating AWS With Salesforce Using Terraform
-
Authorization: Get It Done Right, Get It Done Early
Comments