Newer Version Available

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

Create a Java Client

Create a Java client that uses Bayeux and CometD to subscribe to the channel.
  1. Download and install the CometD and Jetty .jar files if necessary.
  2. In a new Java project, add the following code to a Java source file named StreamingClientExample.java. This code subscribes to the Streaming channel you created and listens for notifications. Depending on your Java development environment, you might have to rename this file and class to Main.
  3. Edit StreamingClientExample.java and modify the following values:
    File Name Static Resource Name
    USER_NAME Username of the logged-in user
    PASSWORD Password for the USER_NAME (or logged-in user)
    CHANNEL /u/notifications/ExampleUserChannel
    LOGIN_ENDPOINT https://test.salesforce.com (Only if you are using a sandbox. If you are in a production organization, no change is required for LOGIN_ENDPOINT.)
  4. Add the following code to a Java source file named SoapLoginUtil.java. This code sends a username and password to the server and receives the session ID.

    Never handle the usernames and passwords of others. Before using in a production environment, delegate the login to OAuth.

    Important

  5. When you run this client app and generate notifications using the REST resource, the output will look something like: