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.

[code lang=”java”]
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”
);
[/code]

If you need to allow access to all client hostnames, replace the whitelist with a wildcard:
[code lang=”java”]
response.setHeader(
“Access-Control-Allow-Origin”,
“*”
);
[/code]

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.

The Washington Americans

19 June 2014 » Football, Politics

This week presented yet another opportunity to suggest a proposal to rename the Washington Redskins to something less controversial. As I see it, the “Washington Americans” makes the most sense.

It removes a racial slur from the name, expands the appeal of the team to represent the capital city (as a kid, I thought the team hailed from Washington state), and it requires little – if any – change to the existing uniform and logo.

I’m not sure if I’m the first one who came up with the idea, but I’ve sent messages via the redskins.com feedback form a couple of times over the past 10 years.

December 2005

Greetings,

Congrats on the win today, and good luck next week at Seattle.

I just wanted to share my thoughts on your team name. I enjoy the history of the team, and the logo and colors. However, every time I hear the word “redskin,” I cringe (and it’s not just because I’m a New York Giants fan :).

My suggestion is to seize the opportunity and rename the team the Washington Americans. You would honor both native-American heritage, and unify that with your home in the nation’s capital.

Just a suggestion. And again, good luck… Unless you face the Giants in the NFC Championship. :)

December 2009

Greetings,

I wrote a similar note about four years ago through redskins.com, and after watching the prime time Sunday night game last night, I thought I’d write again.

I wanted to share my thoughts on your team name. I enjoy the history of the team, and the logo and colors. However, every time I hear the word “redskin,” I cringe (and it’s not just because I’m a New York Giants fan :).

My suggestion is to seize an opportunity and rename the team the Washington *Americans* without a change to logo or team colors. You’d continue to recognize native-American heritage and team history yet also strengthen the team’s association with your home in the nation’s capital.

Furthermore, by using the name “Americans” by itself, without any hyphenated prefix suggesting exclusion or exception such as “Native-,” makes a statement that all US football fans are united as a single nation with a common history.

Of course, this is just my suggestion. But, in what’s looking to be an off season full of change, I think you have a golden opportunity to break with a negative aspect of the past and look to a greater future of the franchise here.

If you could float the idea by Daniel Snyder I’d very much appreciate it.

I’ve also shared the idea a couple of times on Twitter to a positive reception.

Putting aside whoever it was that first came up with the suggestion to rename the team to the Americans, it’s at least a positive starting point to find common ground in this controversy.

It addresses the most offensive part of the name, reduces the cost of change to logo and uniform, and it expands representation of the city and the sport of American Football during this dreadful onslaught of World Cup “football.” :)

Please vote for my OpenStack talk proposals

27 February 2014 » Cloud, Cloud Foundry, OpenStack

I’ve submitted two abstracts for the OpenStack Atlanta conference that happens in May.

The OpenStack project is interesting in that it allows members of the community to weigh in on the topics they’d like to see at the conference.

If you like my presentation topics, please consider voting for them (ideally with 3 stars: “Would Love To See This!”).

To vote, you need to be a member of the OpenStack Foundation. You can join as an individual member for free.

The community review period ends on March 3rd, so please vote today!