DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

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

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
  1. DZone
  2. Coding
  3. JavaScript
  4. Some Tips for Writing JavaScript Adapters for IBM MobileFirst

Some Tips for Writing JavaScript Adapters for IBM MobileFirst

Raymond Camden user avatar by
Raymond Camden
·
Apr. 08, 15 · Interview
Like (0)
Save
Tweet
Share
2.51K Views

Join the DZone community and get the full member experience.

Join For Free

i’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:

shot1

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 .

JavaScript engine

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

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: