Wednesday, July 24, 2013

Salesforce integration using Apache Camel

This is the first in a series of articles on Salesforce integration using Apache Camel.

The need for Salesforce support was obvious, and to be fair to Camel, it did have the fundamental SOAP/REST, CometD support needed to integrate with Salesforce from scratch. But that requires a considerable amount of work by the developer to setup the low level protocol details, and mapping to and from domain objects to Salesforce message format.

So, the primary goals when designing the Salesforce component were:
  1. Easy Salesforce connection setup (OAuth 2.0 authentication) and management (session re-establishment on expiry, etc.)
  2. Support for Salesforce domain object (SObjects in Salesforce terminology) generation and mapping
  3. Support for all or majority of Salesforce integration APIs (SOAP, REST, Bulk, Streaming)
Salesforce integration APIs for SOAP and REST have their own quirks which make working with them interesting. The SOAP API uses a WSDL and is always tied to a specific Salesforce platform version, and comes with all the pros and cons of a SOAP interface. The REST API is not quite pure REST, more like RESTish, and uses some ad-hoc features like using a different root name (SObject name) for what is essentially the same object (SObject description).

But the REST interface does not require a new WSDL to be compiled with every Salesforce release, and is backward compatible. More importantly, the REST interface also makes it very easy to generate code for Salesforce domain objects (that map to and from JSON/XML), compared to having to generate a WSDL/Schema for user objects and compiling that to add to an application. 

With these goals and ideas the Salesforce component became what it is now. A two piece solution consisting of a maven plugin to generate Salesforce domain objects and a Salesforce component that supports REST, Bulk, and Streaming APIs. 

The maven plugin generates POJOs from Salesforce objects, along with some helper classes that support Salesforce queries, picklists, etc. It uses the excellent Joda Time library for date time fields, and Jackson for JSON support and XStream for XML support. 

The Salesforce component supports easy configuration to use OAuth 2.0 User name password authentication. It uses Jetty HTTP Client to manage Salesforce connections and transparently handles session token refresh. It supports working with both raw JSON/XML and domain objects generated by the Camel Salesforce maven plugin. 

Hopefully Apache Camel users will find this component easy to use and it drastically reduces the time it takes them to integrate with Salesforce. 

Future posts in this series will focus on project setup and using the rich set of features supported by the component. For the impatient among us, there are extensive unit tests for every component feature here.   Enjoy.