Cross-origin resource sharing on IBM Bluemix

Update: A newer version of this post has been published to the IBM Bluemix blog.

The IBM Bluemix Platform-as-a-Service (based on Cloud Foundry) naturally supports applications that are composed of many services that are in turn deployed to different hostnames.

For example, if you push an application to Bluemix, the name you provide will be prepended to .mybluemix.net resulting in an address such as:

  • http://my-sample-app.mybluemix.net

If your cloud-native app follows the best practices of a microservices architecture you’ll probably have two or more subcomponents that live on discrete hostnames like this.

But what if you have a JavaScript based front-end that needs to aggregate information from the disparate hosts? By default you won’t have access to data on these other subdomains.

The solution is to take advantage of the HTTP headers that are available to allow you to control cross-origin resource sharing (CORS).

To illustrate the problem and the solution, consider the simple Ajax application here:

If you click the red box, you’ll initiate an asynchronous HTTP call in JavaScript to a servlet on another host at:

The source of this servlet shows that no particular HTTP headers are set, thus the JavaScript call never reaches it.

However, if you click the blue box, you’ll initiate a call to a different servlet on that host:

This time the Ajax call will successfully consume data from the service, because the HTTP headers allow services from a different domain to access the servlet.

response.setHeader(
  "Access-Control-Allow-Origin",
  "http://krook-service-consumer.mybluemix.net"
);

response.setHeader(
  "Access-Control-Allow-Methods",
  "POST, GET, DELETE, PUT"
);

response.setHeader(
  "Access-Control-Allow-Headers",
  "x-requested-with,Content-Type"
);

If you need to allow access to all client hostnames, replace the whitelist with a wildcard:

response.setHeader(
  "Access-Control-Allow-Origin",
  "*"
);

There you have it; a simple way to build dynamic JavaScript applications composed of several microservices on IBM Bluemix (or any other Cloud Foundry PaaS).

I used Java in this example, but the same HTTP headers apply whether you’re using Ruby, Node.js, PHP, Python or any other runtime.

Best practices of the daily scrum at NYPHP

28 August 2012 » Agile, New York PHP, PHP

Join us tonight at the New York PHP meeting in midtown Manhattan to hear best practices for agile PHP development from Patricia Ju of Hackerbilt.

As a former scrum-half, I’m particularly interested in the actual rugby ball Hackerbilt brings to the daily standup. :)

RSVP now.

Zend on IBM private/public clouds at NYPHP

21 June 2012 » Cloud, DB2, IBM, New York PHP, PHP, Zend

Next Tuesday, June 26th, I’ll be speaking at the New York PHP user group about the project I led to bring the Zend Application Fabric onto IBM’s on-premise private cloud rack, PureSystems, and onto IBM’s public cloud, SmartCloud Enterprise.

I’ll describe the Zend Application Fabric for highly available PHP clusters, and show how its topology is supported by scaling and failover policies built into the IBM platform. I’ll also show how it integrates with the DB2 based Database-as-a-Service.

Zend Application Fabric

At the core of the Zend/IBM system is an IBM virtual application pattern (based on the TOSCA standard) that specifies how virtual machines are layed out, which other VMs they should link (or react) to based on life cycle events, and when they should scale up or down.

You will learn how to activate the Zend pattern, customize the topology, set a scaling policy, monitor the infrastructure, tweak the Zend configuration, view IBM elasticity and fault tolerance in action, and perform repeatable deployments using a template.

RSVP now, or make a note to catch the live stream.

Zend phpcloud.com at NYPHP

26 March 2012 » Cloud, New York PHP, PHP, Zend

Tomorrow night we’ll again host Edward Kietlinski at New York PHP.

He’ll talk about the latest offerings from Zend to bring your PHP applications to their developer cloud.

Soon, you’ll also be able to deploy your production-ready applications to the IBM SmartCloud.

RSVP now for Tuesday night’s meeting at IBM in midtown Manhattan.

Or, if you can’t make it in person, watch online with Cal Evans.

Migrating PHP applications to DB2

08 March 2012 » DB2, developerWorks, MySQL, PHP, Writing, Zend

IBM developerWorks has just published the final part in our series on migrating a PHP application from MySQL to DB2.

Learn why to move a PHP application to DB2, how to plan the migration, how to execute it, how to support it, and how to handle potential risks based on the experience of an IBM intranet application case study. This four-part series shares lessons from a successful MySQL-to-DB2 migration for a mission-critical PHP intranet application used by 4,000 global users within IBM to support content production for ibm.com.

In addition to sharing our own experience, the series highlights the number of resources available to you to carry out your own migration.

MongoDB and ZendCon at New York PHP

24 October 2011 » MongoDB, New York PHP, PHP, Zend

This month we have a double feature at New York PHP.

PHP on IBM System i consultant Alan Seiden will give us an update on what transpired at last week’s ZendCon.

10gen MongoDB evangelist Steve Francia will provide an overview on using PHP with MongoDB.

RSVP now for the meeting at IBM in midtown Manhattan on Tuesday October 25th or watch online starting at 6:30pm ET.

BlackBerry app for Metro-North schedules

04 May 2011 » BlackBerry, Java, Travel

Well, it took just under two years and quite a bit of marketshare loss, but I found some time to release my long promised native BlackBerry application for Metro-North commuter train schedules.

You can download NYC North Trains for free, over-the-air. I’ve tested it on OS 5 and 6 devices such as the Curve, Style, Storm 2, Bold, Tour and Torch.

Like the simple Web interface I’ve provided for nearly five years, the native app offers an interface to the MTA schedule data optimized for mobile devices.

However, it also offers some features that make the experience quite a bit more convenient for BlackBerry users.

  • Simple schedule selection using BlackBerry dropdowns and date picker
  • The ability to save your preferred origin and destination (and toggle them depending on which way you’re going)
  • Ability to email the schedule results from the device
  • Ability to save a particular departure to your calendar to block your travel time

Of course, this application comes with the standard disclaimer.

Not affiliated with the MTA or the States of New York and Connecticut. This tool uses live information directly from mta.info, so schedules are always based on the latest available information. This tool retains no copies of schedule information from the MTA.

Enjoy and let me know what other enhancements you’d like to see.

Use the IBM Cloud to build your PHP apps

14 March 2011 » Cloud, DB2, developerWorks, New York PHP, PHP, Zend

IBM developerWorks just published an article I wrote about using the Development and Test Cloud to create PHP applications.

The tutorial covers some scenarios that make the cloud compelling for PHP developers and then takes the reader through the installation of Zend Server with DB2 on the IBM Cloud.

If the content looks familiar, you may have seen an earlier version in a print copy I handed out at New York PHP (PDF) late last year.

Speaking of the cloud and NYPHP, don’t forget to join us next week to look at an alternative way to use the cloud to develop PHP applications using Amazon and RightScale.

Next page »