Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆


Subscribe to our mailing list

java-sdk

:gift::gift: Java SDK to use the IBM Watson services.

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star half bd79095782ee4930099175e5ce7f4c89fa3ddabcd56fffcc7c74f6f2a2d46b27 (1 ratings)
Rated 4.5 out of 5
Subscribe to updates I use java-sdk


Statistics on java-sdk

Number of watchers on Github 467
Number of open issues 6
Average time to close an issue 6 days
Main language Java
Average time to merge a PR about 23 hours
Open pull requests 22+
Closed pull requests 60+
Last commit about 1 year ago
Repo Created almost 4 years ago
Repo Last Updated about 1 year ago
Size 213 MB
Homepage http://watson-dev...
Organization / Authorwatson-developer-cloud
Latest Releasejava-sdk-5.1.0
Contributors16
Page Updated
Do you use java-sdk? Leave a review!
View open issues (6)
View java-sdk activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating java-sdk for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)
What people are saying about java-sdk Leave a review
Its simple to implement

Watson APIs Java SDK

Build Status Slack Maven Central CLA assistant

Java client library to use the Watson APIs.

Table of Contents * [Installation](#installation) * [Maven](#maven) * [Gradle](#gradle) * [Usage](#usage) * [Getting the Service Credentials](#getting-the-service-credentials) * IBM Watson Services * [Assistant](assistant) * [Discovery](discovery) * [Language Translator](language-translator) * [Natural Language Classifier](natural-language-classifier) * [Natural Language Understanding](natural-language-understanding) * [Personality Insights](personality-insights) * [Speech to Text](speech-to-text) * [Text to Speech](text-to-speech) * [Tone Analyzer](tone-analyzer) * [Tradeoff Analytics](tradeoff-analytics) * [Visual Recognition](visual-recognition) * [Changes for v4.0](#changes-for-v40) * [Using a Proxy](#using-a-proxy) * [Android](#android) * [Running in IBM Cloud](#running-in-ibm-cloud) * [Default Headers](#default-headers) * [Debug](#debug) * [Eclipse and Intellij](#working-with-eclipse-and-intellij-idea) * [License](#license) * [Contributing](#contributing)

Installation

Maven

All the services:

<dependency>
    <groupId>com.ibm.watson.developer_cloud</groupId>
    <artifactId>java-sdk</artifactId>
    <version>5.1.0</version>
</dependency>

Only Discovery:

<dependency>
    <groupId>com.ibm.watson.developer_cloud</groupId>
    <artifactId>discovery</artifactId>
    <version>5.1.0</version>
</dependency>
Gradle

All the services:

'com.ibm.watson.developer_cloud:java-sdk:5.1.0'

Only Assistant:

'com.ibm.watson.developer_cloud:assistant:5.0.1'
Development Snapshots

Snapshots of the development version are available in Sonatype's snapshots repository.

Gradle

Add repository to your project Gradle file

allprojects {
    repositories {
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    }
}

And then reference the snapshot version on your app module gradle Only Speech to Text:

'com.ibm.watson.developer_cloud:speech-to-text:5.1.0-SNAPSHOT'
JAR

Download the jar with dependencies here.

Now, you are ready to see some examples.

Usage

The examples within each service assume that you already have service credentials. If not, you will have to create a service in IBM Cloud.

If you are running your application in IBM Cloud (or other platforms based on Cloud Foundry), you don't need to specify the credentials; the library will get them for you by looking at the VCAP_SERVICES environment variable.

Getting the Service Credentials

You will need the username and password (api_key for Visual Recognition) credentials, and the API endpoint for each service. Service credentials are different from your IBM Cloud account username and password.

To get your service credentials, follow these steps:

  1. Log in to IBM Cloud
  2. In the IBM Cloud Catalog, select the service you want to use.
  3. Click Create.
  4. On the left side of the page, click Service Credentials, and then View credentials to view your service credentials.
  5. Copy url, username and password(api_key for AlchemyAPI or Visual Recognition).

Changes for v4.0

Version 4.0 focuses on the move to programmatically-generated code for many of the services. See the changelog for the details.

Migration

This version includes many breaking changes as a result of standardizing behavior across the new generated services. Full details on migration from previous versions can be found here.

Android

The Android SDK utilizes the Java SDK while making some Android-specific additions. This repository can be found here. It depends on OkHttp and gson.

Using a Proxy

Override the configureHttpClient() method and add the proxy using the OkHttpClient.Builder object.

For example:

Assistant service = new Assistant("2018-02-16") {
  @Override
  protected OkHttpClient configureHttpClient() {
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", 8080));
    return super.configureHttpClient().newBuilder().proxy(proxy).build();
  }
};

service.setUsernameAndPassword("<username>", "<password>");

WorkspaceCollection workspaces = service.listWorkspaces().execute();
System.out.println(workspaces);

For more information see: OkHTTPClient Proxy authentication how to?

Running in IBM Cloud

When running in IBM Cloud (or other platforms based on Cloud Foundry), the library will automatically get the credentials from VCAP_SERVICES. If you have more than one plan, you can use CredentialUtils to get the service credentials for an specific plan.

PersonalityInsights service = new PersonalityInsights("2016-10-19");
String apiKey = CredentialUtils.getAPIKey(service.getName(), CredentialUtils.PLAN_STANDARD);
service.setApiKey(apiKey);

Default Headers

Default headers can be specified at any time by using the setDefaultHeaders(Map<String, String> headers) method.

The example below sends the X-Watson-Learning-Opt-Out header in every request preventing Watson from using the payload to improve the service.

PersonalityInsights service = new PersonalityInsights("2016-10-19");

Map<String, String> headers = new HashMap<String, String>();
headers.put(HttpHeaders.X_WATSON_LEARNING_OPT_OUT, 1);

service.setDefaultHeaders(headers);

// All the api calls from now on will send the default headers

Specifying a service URL

You can set the correct API Endpoint for your service calling setEndPoint().

For example, if you have the conversation service in Germany, the Endpoint may be https://gateway-fra.watsonplatform.net/conversation/api.

You will need to call

Assistant service = new Assistant("2018-02-16");
service.sentEndPoint("https://gateway-fra.watsonplatform.net/conversation/api")

401 Unauthorized error

Make sure you are using the service credentials and not your IBM Cloud account/password. Check the API Endpoint, you may need to update the default using setEndPoint().

Debug

HTTP requests can be logging by adding a loggging.properties file to your classpath.

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s %4$s: %5$s%n
.level=SEVERE
# HTTP Logging - Basic
com.ibm.watson.developer_cloud.util.HttpLogging.level=INFO

The configuration above will log only the URL and query parameters for each request.

For example:

Mar 30, 2017 7:31:22 PM okhttp3.internal.platform.Platform log
INFO: --> POST https://gateway.watsonplatform.net/tradeoff-analytics/api/v1/dilemmas?generate_visualization=false http/1.1 (923-byte body)
Mar 30, 2017 7:31:22 PM okhttp3.internal.platform.Platform log
INFO: <-- 200 OK https://gateway.watsonplatform.net/tradeoff-analytics/api/v1/dilemmas?generate_visualization=false (104ms, unknown-length body)
Mar 30, 2017 7:31:23 PM okhttp3.internal.platform.Platform log
INFO: --> POST https://gateway.watsonplatform.net/tradeoff-analytics/api/v1/dilemmas?generate_visualization=true http/1.1 (12398-byte body)
Mar 30, 2017 7:31:35 PM okhttp3.internal.platform.Platform log
INFO: <-- 200 OK https://gateway.watsonplatform.net/tradeoff-analytics/api/v1/dilemmas?generate_visualization=true (12311ms, unknown-length body)

Warning: The logs generated by this logger when using the level FINE or ALL has the potential to leak sensitive information such as Authorization or Cookie headers and the contents of request and response bodies. This data should only be logged in a controlled way or in a non-production environment.

Build + Test

To build and test the project you can use Gradle (version 1.x).

Gradle:

cd java-sdk
gradle jar  # build jar file (build/libs/watson-developer-cloud-5.1.0.jar)
gradle test # run tests
gradle check # performs quality checks on source files and generates reports
gradle testReport # run tests and generate the aggregated test report (build/reports/allTests)
gradle codeCoverageReport # run tests and generate the code coverage report (build/reports/jacoco)

Working with Eclipse and Intellij IDEA

If you want to work on the code in an IDE instead of a text editor you can easily create project files with gradle:

gradle idea     # Intellij IDEA
gradle eclipse  # Eclipse

Open Source @ IBM

Find more open source projects on the IBM Github Page

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.md.

Code of Conduct

See CODE_OF_CONDUCT.md.

Other

If you are having difficulties using the APIs or you have a question about the IBM Watson Services, please ask a question on dW Answers or Stack Overflow.

java-sdk open issues Ask a question     (View All Issues)
  • over 2 years Move the android-sdk as a module of this project and switch from maven to gradle
  • over 2 years I have an error on createServiceCall method in watson conversationservice.java
  • over 2 years SpeechToText sending inputstream in chunks
java-sdk open pull requests (View All Pulls)
  • add example of categorical column
  • add constructor method with username and password. #298
  • [text-to-speech] Added custom voice models & custom translations
  • [text-to-speech] add customization example
  • TypedRelation service call in Alchemy Language Java SDK not returning entities
  • Add Solr resize API to R&R
  • ENH: Added the customization id for a custom language model
  • [WIP] Asynchronous recognition in Speech to Text
  • :new: Proxy support
  • Move Tone analyzer example to the top level
  • Add Similarity Search
  • First stab at a fully generated SDK for Discovery-V1.
  • Update to Conversation SDK to support 2017-04-21 service version
  • Adds onTranscriptionComplete() to the Speech to Text WebSocket interface
  • Improved fully generated SDK for Discovery-V1.
  • Add a Gradle task to generate an API diff report
  • Add newest generated code for Visual Recognition
  • Add newest generated code for Natural Language Classifier
  • Generated discovery-v1 service
  • Generated conversation-v1 service
  • Generated Visual Recognition service using vr-form-params swagger
  • [DO NOT MERGE] Example of generator changes
java-sdk questions on Stackoverflow (View All Questions)
  • Error with credentials file in IVONA SpeechCloud Java SDK
  • Wepay Java SDK and GAE is giving an exception
  • How to use appengine java sdk with android studio in linux
  • How to upgrade appengine-java-sdk installed in .gradle folder
  • Error putting item in DynamoDB with AWS Java SDK and Hadoop
  • authorize.net Java SDK 1.8.6 concurrency, not working?
  • Microstrategy Web API - JAVA SDK
  • Box API Java SDK search function is returning limited no. of files
  • Can I authenticate a user account in strompath using Stormpath Java SDK?
  • How can I install Eclipse and Java SDK on Ubuntu?
  • Cannot list image publishers from Azure java SDK
  • AWS Java SDK - AWS authentication requires a valid Date or x-amz-date header
  • JetS3t vs AWS Java SDK
  • Couchbase java sdk 1.4.7 numeric key in view Query not returning results
  • EC2 Java SDK - User data script
  • How to use classes from Java SDK when designing with ArgoUML?
  • Exception in thread "main" java.lang.NullPointerException at com.auth.net.commons.authorize.net.GetSettledBatchList.main in Auth.net Java SDK
  • get list of UNSETTLED_TRANSACTION using Auth.net anet-java-sdk API?
  • How can I get the Java SDK and BlueJ to behave properly on a mapped Network drive?
  • Amazon DynamoDB Java SDK won't use proxy settings
  • Set development mode for view query in Couchbase Java SDK 2 globally?
  • Azure Java SDK: ServiceException: ForbiddenError:
  • Query all items in DynamoDB from a given hash key with a hash-range schema using java sdk
  • Tomcat and java SDK problem
  • Azure Java SDK - Where have classes gone
  • Azure Java SDK - Where to get values for serviceName and deploymentName on new Portal
  • Reading sheet contents using SmartSheet Java SDK
  • VersionOne Java SDK - "Could not process Request" after mulitple retrievals
  • SignatureDoesNotMatch in AWS Java SDK for S3
  • launch instance using "beginCreatingDeployment" method from Azure Java sdk
java-sdk list of languages used
java-sdk latest release notes
java-sdk-5.1.0 5.1.0

Introduction of the Assistant service

Changelog

https://github.com/watson-developer-cloud/java-sdk/wiki/Changelog

java-sdk-5.0.1 5.0.1

Changelog

https://github.com/watson-developer-cloud/java-sdk/wiki/Changelog

Migration Guide

https://github.com/watson-developer-cloud/java-sdk/wiki/Migration

java-sdk-4.2.0 4.2.1

Changelog

https://github.com/watson-developer-cloud/java-sdk/wiki/Changelog

Other projects in Java