Repository: camel Updated Branches: refs/heads/master 16a428baf -> 80deaac9e
CAMEL-10804 Create a Salesforce example Adds documentation to the example. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/80deaac9 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/80deaac9 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/80deaac9 Branch: refs/heads/master Commit: 80deaac9e3dea34b5ccdc2e793e592ed1c301fa7 Parents: 16a428b Author: Zoran Regvart <zo...@regvart.com> Authored: Wed Feb 8 18:03:44 2017 +0100 Committer: Zoran Regvart <zo...@regvart.com> Committed: Wed Feb 8 18:03:44 2017 +0100 ---------------------------------------------------------------------- .../camel-example-twitter-salesforce/README.md | 66 +++++++++++++++++++- .../apache/camel/example/mention/Contact.java | 10 +++ .../src/main/resources/application.properties | 9 ++- 3 files changed, 83 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/80deaac9/examples/camel-example-twitter-salesforce/README.md ---------------------------------------------------------------------- diff --git a/examples/camel-example-twitter-salesforce/README.md b/examples/camel-example-twitter-salesforce/README.md index 5c1075f..1346341 100644 --- a/examples/camel-example-twitter-salesforce/README.md +++ b/examples/camel-example-twitter-salesforce/README.md @@ -15,7 +15,71 @@ For that you need to setup and use your own twitter account. ### Configuring Salesforce -TODO: Salesforce is mocked and to setup a real account you need +This example uses Camels own test Salesforce developer account, you would most likely want to +sign up with your own Developer account at <https://developer.salesforce.com/>. After you +have done that, you'll need to create a Connected Application for your integration. + +To do this after logging in to your Salesforce Developer account, navigate to _Apps_ located +under _Build_ and then _Create_, there you should see _Connected Apps_ table in the heading +click on _New_ and fill in the indicated required fields and enable the _OAuth Settings_, for +_Callback URL_ you can use <https://login.salesforce.com/services/oauth2/success>. + +In the _Available OAuth Scopes_ add _Access and manage your data (api)_ and +_Perform requests on your behalf at any time (refresh_token, offline_access)_. + +After clicking _Save_ click on _Manage_ on the top of the page and then click on + _Edit Policies_. Change the _IP Relaxation_ to _Relax IP restrictions_ and click on _Save_. + +**NOTE:** This will get you started quicker, but production you should re-evaluate to comply +with your security needs. + +Next gather your _Consumer Key_ (_clientId_ property), _Consumer Secret_ (clientSecret) and +either use username and password of the developer account; or get the refresh token from +Salesforce (more on this below). + +#### Adding the Twitter screen name custom field + +The example adds a custom field to _Contact_ SObject, to add it to your Salesforce environment +go into _Customize_ under _Build_ and choose _Fields_ under _Contact_. + +In _Contact Custom Fields & Relationships_ click on _New_ and add a field of type `Text` +with field label `Twitter Screen Name`, length of 15 and for uniqueness select +_Do not allow duplicate values_ and set the +_Set this field as the unique record identifier from an external system_. + +#### Getting the OAuth refresh token + +In your browser go to the URL change the `__YOUR_CLIENT_ID_HERE__` with your connected +application _Consumer Key_: + +<https://login.salesforce.com/services/oauth2/authorize?response_type=token&client_id=__YOUR_CLIENT_ID_HERE__&redirect_uri=https://login.salesforce.com/services/oauth2/success&display=touch> + +Allow access to the application, and you'll end up on a page with `refresh_token` after +the `#`, something like: + +`https://login.salesforce.com/services/oauth2/success#access_token=..&refresh_token=`**<refresh_token>**`&instance_url=...&issued_at=...&signature=...&scope=...&token_type=Bearer` + +#### How to generate Salesforce Data Transfer Objects (DTOs) + +The best way to generate Java representation of Salesforce SObjects is to use the +`camel-salesforce-maven-plugin`, for example: + + $ mvn org.apache.camel.maven:camel-salesforce-maven-plugin:generate \ + -DcamelSalesforce.clientId=<client id> \ + -DcamelSalesforce.clientSecret=<client secret> \ + -DcamelSalesforce.userName=<username> \ + -DcamelSalesforce.password=<password> + +You can specify the only the SObjects you'll integrate with using `camelSalesforce.includePattern` parameter, like: + + $ mvn org.apache.camel.maven:camel-salesforce-maven-plugin:generate \ + -DcamelSalesforce.clientId=<client id> \ + -DcamelSalesforce.clientSecret=<client secret> \ + -DcamelSalesforce.userName=<username> \ + -DcamelSalesforce.password=<password> \ + -DcamelSalesforce.includePattern=Contact + +To generate only DTOs needed for Contact, but the parameter value can be specified using regular expressions. ### Build http://git-wip-us.apache.org/repos/asf/camel/blob/80deaac9/examples/camel-example-twitter-salesforce/src/main/java/org/apache/camel/example/mention/Contact.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-twitter-salesforce/src/main/java/org/apache/camel/example/mention/Contact.java b/examples/camel-example-twitter-salesforce/src/main/java/org/apache/camel/example/mention/Contact.java index 747413e..220c912 100644 --- a/examples/camel-example-twitter-salesforce/src/main/java/org/apache/camel/example/mention/Contact.java +++ b/examples/camel-example-twitter-salesforce/src/main/java/org/apache/camel/example/mention/Contact.java @@ -21,11 +21,21 @@ */ package org.apache.camel.example.mention; +import org.apache.camel.component.salesforce.api.dto.AbstractDescribedSObjectBase; import org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +/** + * Contact Data Transfer Object (DTO) needed for Salesforce component. + *<p> + * This is a trivial, hand coded, example of DTO for Contact SObject, + * for production use you would most likely want to generate these + * using {@code camel-salesforce-maven-plugin} as it adds all fields + * and generates {@link AbstractDescribedSObjectBase} based classes, + * which are needed for some of the operations (like composite API). + */ public class Contact extends AbstractSObjectBase { @JsonProperty("LastName") http://git-wip-us.apache.org/repos/asf/camel/blob/80deaac9/examples/camel-example-twitter-salesforce/src/main/resources/application.properties ---------------------------------------------------------------------- diff --git a/examples/camel-example-twitter-salesforce/src/main/resources/application.properties b/examples/camel-example-twitter-salesforce/src/main/resources/application.properties index 8c199bd..92e4154 100644 --- a/examples/camel-example-twitter-salesforce/src/main/resources/application.properties +++ b/examples/camel-example-twitter-salesforce/src/main/resources/application.properties @@ -9,7 +9,14 @@ camel.component.twitter.consumer-secret=VxNQiRLwwKVD0K9mmfxlTTbVdgRpriORypnUbHhx camel.component.twitter.access-token=26693234-W0YjxL9cMJrC0VZZ4xdgFMymxIQ10LeL1K8YlbBY camel.component.twitter.access-token-secret=BZD51BgzbOdFstWZYsqB5p5dbuuDV12vrOdatzhY4E +## This uses Camel test Salesforce developer account please use your own account in your applications + +## Consumer Key of the connected application camel.component.salesforce.loginConfig.clientId=3MVG9szVa2RxsqBZXHfqsW3hf9HQp_N6qdSmpjKMzSJaEL4UP161JlDkE32EigL82ra_jM1WuQgF4rYDgzL3u +## Consumer Secret of the connected application camel.component.salesforce.loginConfig.clientSecret=1039611643161946846 +## refresh_token from OAuth flow camel.component.salesforce.loginConfig.refreshToken=5Aep861HDR3iASSXIX6hI7M1qMWSCs1Ym57WUH1ftjE7RvnM7MvnAXx9EZaw_HIoNCKktNsuhx.xwjLThofuJH4 - +## you can also use: +#camel.component.salesforce.loginConfig.userName=<Salesforce username> +#camel.component.salesforce.loginConfig.password=<Salesforce password>