Going Reactive at OSCON 2014

This year at OSCON I will be leading a hands-on lab and presenting about Reactive, Play Framework, and Scala. Here are two sessions:

  • Reactive All The Way Down (lab) – 9:00am Monday, July 21

    In this tutorial you will build a Reactive application with Play Framework, Scala, WebSockets, and AngularJS. We will get started with a template app in Typesafe Activator. Then we will add a Reactive RESTful JSON service and a WebSocket in Scala. We will then build the UI with AngularJS.

  • Building Modern Web Apps with Play Framework and Scala – 2:30pm Wednesday, July 23

    Play Framework is the High Velocity Web Framework For Java and Scala. It is lightweight, stateless, RESTful, and developer friendly. This is an introduction to building web applications with Play. You will learn about: routing, Scala controllers & templates, database access, asset compilation for LESS & CoffeeScript, and JSON services.

Hope to see you there!

Posted in Conferences, Play Framework, Reactive, Scala | Leave a comment

Scala vs Java 8 at the Scala Summit

Bruce Eckel will be hosting the Scala Summit in Crested Butte again this summer. The Open Spaces conference will be September 15 – 19 which is a perfect time of year up in the Colorado Rockies. The theme of the Scala Summit this year is Scala vs. The New Features in Java 8. So there will definitely be some fascinating discussions. I’m also looking forward to working on some IoT projects during the hackathons. Bruce and I have a few pcDuino devices that will be fun to get Scala working on. Hope to see you there!

Posted in Conferences, Scala | Leave a comment

Salesforce Gradle Plugin

As part of the Salesforce Wear Developer Pack for Android Wear I created a Gradle plugin that fetches and deploys Salesforce code (Apex). Gradle is the default build tool for Android but it can also be used with many other languages. For instance, here is an example build.gradle file for a project that fetches all of the Apex classes and Visualforce pages:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath 'com.jamesward:force-gradle-plugin:0.1'
    }
}
 
apply plugin: 'force'
 
repositories {
    mavenLocal()
    mavenCentral()
}
 
force {
    username = forceUsername
    password = forcePassword
    unpackagedComponents = ["ApexPage": "*", "ApexClass": "*"]
}

The unpackagedComponents definition uses the Salesforce Metadata Types and pulls everything specified down into the src/main/salesforce/unpackaged directory when you run the forceMetadataFetch Gradle task. The forceMetadataDeploy Gradle task deploys everything in the src/main/salesforce/unpackaged directory to Salesforce.

Try this out:

  • Install Gradle
  • Create a new project directory containing the build.gradle above
  • In your project directory create a new file named gradle.properties containing your Salesforce username & password:

    forceUsername=foo@bar.com
    forcePassword=password
  • Fetch your Salesforce Metadata:

    gradle forceMetadataFetch
  • Make a change and deploy the Metadata:

    gradle forceMetadataDeploy

For a complete example check out the Visualforce + AngularJS + Bootstrap project.

All of the code for the Salesforce Gradle Plugin is on GitHub: https://github.com/jamesward/force-gradle-plugin

Let me know what you think. Thanks!

Posted in Gradle, Salesforce.com | Leave a comment

Create Webhooks on Salesforce.com

Webhooks are the modern, web-oriented way for servers to receive notifications from other servers. For instance, when an event happens on a server, like Salesforce.com, your own custom application can receive the event via a web request.

Salesforce already has a built-in way to handle events called Triggers which run on Salesforce via Apex code. However, you may want to receive these events in your own custom application. In Salesforce it is pretty easy to write the Apex to do this but why not automate that process? I built the Salesforce Webhook Creator to do just that. Here is a short demo:

If you want to test it out, use my Echo Webhook app by entering a URL like:
https://echo-webhook.herokuapp.com/SOME-UNIQUE-ID

All of the code is on GitHub – contributions welcome!

Let me know what you think!

Posted in Salesforce.com | Leave a comment

Cross-Origin Resource Sharing (CORS) for Salesforce.com

By default browsers limit access to cross-origin resources. For instance, if a JavaScript app is loaded from foo.com then it isn’t allowed to access content from bar.com because this would be a significant security hole. Cross-Origin Resource Sharing (CORS) is the way to workaround this limitation in modern browsers.

Salesforce.com has a great REST api but unfortunately it doesn’t yet have native CORS support (but you can vote for this feature). Having CORS support comes in handy with JavaScript UIs on top of the Salesforce REST APIs. Luckily you can easily workaround this by proxying the API requests through the server that is serving the JavaScript UI so that the REST requests are not cross-origin. But it is tedious to set this up for every app, so I created a generic Salesforce CORS proxy.

For demo purposes the CORS proxy is available at: https://sfdc-cors.herokuapp.com

So you can just replace your Salesforce domain name with sfdc-cors.herokuapp.com to use the CORS proxy. Here is an example:

$ curl -i -H 'Authorization: Bearer YOUR_SESSION_ID' https://sfdc-cors.herokuapp.com/services/data/v30.0/query/?q=select%20Id%20from%20Account
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *

The HTTP Response contained the necessary CORS header on the GET request. An OPTIONS request also returns the right response headers to allow the request.

This app is open source so you can easily deploy it on your own Heroku app or in your own environment for production usage.

One of the other nice features of this proxy is that it figures out which Salesforce instance to connect to. So you no longer need to specify something like na9.salesforce.com – instead just use one domain name for all of your apps and instances.

I hope this is useful for you. Let me know if you have any questions or feedback.

Posted in Salesforce.com | Leave a comment

Integrating Clouds & Humans with Salesforce and Android Wear

Right out of the gate in my new job at Salesforce.com and I have been working on a pretty exciting new project to integrate clouds and humans using Salesforce.com and Android Wear. This week Salesforce launched six new open source developers packs for wearables. I created the Salesforce Wear Pack for Android Wear to help developers start building cloud-driven wearable apps for emerging devices like smart watches. Check out a short demo of the sample app I built:

All of the code and instructions for getting this application running in your development environment are in the QuoteDiscountApproval sample app.

This project was a ton of fun and I’ve learned a bunch of new things about Android, Gradle, and Salesforce.com which will provide some great fodder for upcoming blogs. So check out the Salesforce Wear Pack for Android Wear and stay tuned for more blog posts on these topics.

Posted in Android, Salesforce.com | 1 Response

Testing Webhooks Was a Pain – So I Fixed the Glitch

Popularized by GitHub, Webhooks are the modern way for apps to receive notifications / events from other servers. But testing Webhooks has always been pretty painful, especially if you want to automate those tests. So I created a little app to make it easier. Before we get into that lets cover the basics…

A Webhook is a way for you to define a URL that is called by another service when a particular event occurs. For example, you can configure your repo on GitHub to have a Webhook that calls http://foo.com/pr when a new Pull Request is created. The old alternative to this is polling (bad).

Testing Webhooks is painful because the service calling your Webhook can’t reach your localhost and it can be hard to get the payload of the request. So I created a very simple app to help with this. To use it set the Webhook URL to:

https://echo-webhook.herokuapp.com/SOMETHING_UNIQUE

Now when the other service does its POST to that URL the request body is cached and can be retrieved via a GET to the same URL. Here is a simple curl test:

curl -H "content-type: application/json" -d '{"foo": "bar"}' https://echo-webhook.herokuapp.com/foobar
curl https://echo-webhook.herokuapp.com/foobar
{"foo":"bar"}

Your app can get the payload of the Webhook request and if needed pass it to your localhost Webhook for testing. All of the code for this app is on GitHub: https://github.com/jamesward/echo-webhook (Note: If you don’t want your data going through my app just git push that repo to your own Heroku app.)

I hope this is useful for others! Let me know if you have any questions or problems.

Posted in Tools | 1 Response

Building JavaScript Client Apps with gulp

Yesterday I started playing around with gulp which is a build tool for JavaScript applications. My goal was to have a build for a fully client-side application built with AngularJS and Bootstrap. In modern JavaScript apps we now need a build tool to compile various pieces, manage libraries, do production transformations (like minification), and to provide a nice development cycle when working on a project. I created a Gulp Starter project that has the following:

  • Very simple example AngularJS & Bootstrap app
  • Asset pipeline for LESS, JavaScript, images, and HTML that does basic compilation and syntax checking in development mode and minification for production mode
  • Development server with LiveReload integration
  • Production server used to test the production assets
  • Transparent Bower integration (for managing client-side dependencies)

Check out a seven minute walk-through of the Gulp Starter project:



Now to get started check out the README in the Gulp Starter GitHub project.

I’m new to this world so I’d love any feedback you have. Thanks!

Posted in AngularJS, Bower, gulp, JavaScript, LESS | 7 Responses

Presenting Going Reactive with Java 8 Next Week in Boulder & Denver

Next week I will be presenting Going Reactive with Java 8 at the Boulder and Denver Java User Groups. Here is the session description:

Java 8′s lambdas make building Reactive applications a whole lot easier and cleaner. Through copious code examples this session will show you how to build event-driven, scalable, resilient, and responsive applications with Java 8, Play Framework and Akka. On the web side you will learn about using lambdas for async & non-blocking requests & WebSockets. You will also learn how the actor model in Akka pairs well with lambdas to create an event-driven foundation that provides concurrency, clustering and fault-tolerance.

Sign up for Tuesday, May 13, 2014 in Boulder or Wednesday, May 14, 2014 in Denver. Hope to see you there!

Posted in Java, Reactive | Leave a comment


  • View James Ward's profile on LinkedIn