Giter VIP home page Giter VIP logo

oauth2-servlet's Introduction

Java Servlet example for IBM Watson Analytics

Setup

  1. Download and install Java 8 from http://java.com/en/download/manual.jsp
  2. In a console, type java -version to verify that Java installed correctly and is available to other applications.
  3. Download Apache Tomcat 8.0 in .zip format from http://tomcat.apache.org.
  4. Install Apache Tomcat in one of these ways:
  1. Navigate to the ./<tomcat_folder>/webapps folder and create a folder called demo.
  2. 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).
  3. Move to the ./<tomcat_folder>/webapps/demo/WEB-INF/ folder and create a folder called lib.
  4. 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.
  5. Decompress the Apache HTTP client content in the ./<tomcat_folder>/webapps/demo/WEB-INF/lib/ folder.
  6. 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.
  7. Decompress the Apache Sling Common JSON content in the ./<tomcat_folder>/webapps/demo/WEB-INF/lib/ folder.
  8. 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 properties file

  1. 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

Start the application

  1. In a console, navigate to the ./<tomcat_folder>/bin folder, then type ./startup.sh (on OSX) or startup.bat (on Windows).
    • Tip: For OSX, you will probably need to run chmod u+x *.sh in the bin folder first.
  2. To run the application, open a web browser and navigate to this address: http://localhost:8080/demo.

Notes

  • 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.