- Download and install Java 8 from http://java.com/en/download/manual.jsp
- In a console, type
java -version
to verify that Java installed correctly and is available to other applications. - Download Apache Tomcat 8.0 in .zip format from http://tomcat.apache.org.
- Install Apache Tomcat in one of these ways:
- Decompress the zip file into a folder.
- Follow the setup documentation available from http://tomcat.apache.org/tomcat-8.0-doc/setup.html.
- Navigate to the
./<tomcat_folder>/webapps
folder and create a folder calleddemo
. - Copy the content of the
./WebContent/
folder content to the./<tomcat_folder>/webapps/demo/
folder (including the index.html and integration.html files, and the WEB-INF and META_INF folders). - Move to the
./<tomcat_folder>/webapps/demo/WEB-INF/
folder and create a folder calledlib
. - Download the Apache HTTP client (zip format) from https://hc.apache.org/downloads.cgi. We built this sample using Apache HTTP Client version 4.2.5.
- Decompress the Apache HTTP client content in the
./<tomcat_folder>/webapps/demo/WEB-INF/lib/
folder. - Download Apache Sling Common JSON (zip format) from http://sling.apache.org/downloads.cgi. We built this sample using Apache Sling Common JSON version 2.0.16.
- Decompress the Apache Sling Common JSON content in the
./<tomcat_folder>/webapps/demo/WEB-INF/lib/
folder. - Register your client id and client secret. Use "http://localhost:8080/demo/oauth2/code" as your redirect URI. You only need to call this operation once unless the client ID changes. Use the following CURL command. Replace the details with your information.
curl -v -X PUT -H "X-IBM-Client-Secret:YOUR_CLIENT_SECRET" -H "X-IBM-Client-Id:YOUR_CLIENT_ID" -H "Content-Type: application/json" -d '{"clientName": "The Sample Outdoors Company", "redirectURIs": 'https://example.com:5443", "ownerName": "John Smith", "ownerEmail": "[email protected]", "ownerCompany": "example.com", "ownerPhone": "555-123-4567"}' https://api.ibm.com/watsonanalytics/run/oauth2/v1/config
- Create a file called
appkey.properties
in the./<tomcat_folder>/webapps/demo/WEB-INF/
folder that matches the following template. Enter your client id and secret. Save it in the application folder. That's where the index.html file is located.
client_id=YOUR_CLIENT_ID
client_secret=YOUR_CLIENT_SECRET
- In a console, navigate to the
./<tomcat_folder>/bin
folder, then type./startup.sh
(on OSX) orstartup.bat
(on Windows).- Tip: For OSX, you will probably need to run
chmod u+x *.sh
in thebin
folder first.
- Tip: For OSX, you will probably need to run
- To run the application, open a web browser and navigate to this address: http://localhost:8080/demo.
- For clarity, this sample application uses
localhost
as part of the URL for the application. However, when you create your own application, do not use localhost. - This sample application is simplified to emphasize the code that you need to work with Watson Analytics. For example, it contains minimal error checking.