Verify the REST Environment (REST-Based APIs)

You can verify your developer environment with a simple Java test application in Eclipse.

You should have the JDK, Eclipse, and the HttpClient and JSON frameworks installed.

  1. Run Eclipse. Click File | New | Java Project and name the project “SF-REST-Test.”

  2. Click Project | Properties | Java Build Path | Libraries and click Add External JARs. Add the HttpClient .jar files: httpclient, httpcore, commons-codec, and commons-logging (the .jar files will have version information in the filenames). Add the JSON .jar file, which might also have a version number in the .jar filename.

  3. Add a new folder to the src folder by right-clicking src, then select New | Folder and use sfdc_rest as the folder name.

  4. Create a new class by right-clicking sfdc_rest and selecting New | Class. Name the class Main.

  5. Replace the code Eclipse generates for Main.java as described in the following section.

Use the following simple login example code for your Main.java class. Replace YOUR DEVORG USERNAME with your developer organization username, and replace YOUR DEVORG PASSWORD + SECURITY TOKEN with your developer organization password appended with your security token. If you did not set a security token in your organization, just provide your password. Replace YOUR OAUTH CONSUMER KEY with the consumer key from your development organization’s connected app. Replace YOUR OAUTH CONSUMER SECRET with the consumer secret from your development organization’s connected app. A GitHub Gist of this code is available here: https://gist.github.com/anonymous/fcb1bc36ef50c0efbeb5.

The following example output shows a typical successful run of this code.

If the verification Java project runs and displays output that matches your organization, your developer environment is now set up and you can start developing Java applications that integrate with Salesforce REST APIs.