Newer Version Available

This content describes an older version of this product. View Latest

Run a Java Client with OAuth Bearer Token Login

Run a Java client that uses EMP Connector to subscribe to the channel with OAuth authentication.

Prerequisites

Obtain an OAuth bearer access token for your Salesforce user. You supply this access token in the connector example.

See Set Up Authentication with OAuth 2.0. Also see Authenticate Apps with OAuth in Salesforce Help and Understanding Authentication in the REST API Developer Guide.

Let’s run an example that uses OAuth bearer token login.
  1. Get the EMP Connector project from GitHub. See Download and Build the Project.
  2. In the /src/main/java/com/salesforce/emp/connector/example folder, open the BearerTokenExample.java Java source file.
  3. Run the BearerTokenExample class, and provide the following argument values.
    Argument Value
    username Username of the logged-in user.
    password Password for the username (or logged-in user).
    channel /u/notifications/ExampleUserChannel
    The sample fetches the earliest saved events within the past 24 hours. Optionally, to receive different events, you can include a replay ID as the last argument. Valid values are:
    • –1—Get all new events sent after subscription.
    • –2—Get all new events sent after subscription and all past events within the past 24 hours.
    • Specific number—Get all events that occurred after the event with the specified replay ID.
  4. When you run this client app and generate notifications using the REST resource, the output will look something like:
In the next step, you learn how to generate notifications using REST.