Skip to content

Commit

Permalink
Merge pull request #629 from watson-developer-cloud/develop
Browse files Browse the repository at this point in the history
3.7.1
  • Loading branch information
germanattanasio authored Mar 31, 2017
2 parents add98fe + a493dd4 commit b8f2563
Show file tree
Hide file tree
Showing 42 changed files with 1,219 additions and 115 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
Change Log
==========

## Version 3.7.1

_2017-03-31_


* Fix: Enable all cipher suites cf58894 74cae1b
* Fix: `afterEvaluate` source for docs task 0f93ec3
* Fix: Disable HTML escaping, #532 c6497ed
* Fix: CheckStyle d5ccc68 9a7654b 9a7654b
* Fix: Examples link in README.md 430f3a6 by @rborer

* Doc: Exclude tests from javadoc generation 60e80de
* Doc: Update HTTP logging information #496 85e2424

* New: Add aggregate Javadocs plugin b6d1123
* New: Add tradeoff analytics test case for #306 9f40779
* New: Adds an HTTPLogging interceptor #496 620d8d9
* New: Unit tests for Natural Language Understanding 5e89f3a

## Version 3.7.0

_2017-03-19_
Expand Down
45 changes: 37 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ APIs and SDKs that use cognitive computing to solve complex problems.
* [Android](#android)
* [Running in Bluemix](#running-in-bluemix)
* [Default Headers](#default-headers)
* [Debug](#debug)
* [Eclipse and Intellij](#working-with-eclipse-and-intellij-idea)
* [License](#license)
* [Contributing](#contributing)
Expand All @@ -53,7 +54,7 @@ All the services:
<dependency>
<groupId>com.ibm.watson.developer_cloud</groupId>
<artifactId>java-sdk</artifactId>
<version>3.7.0</version>
<version>3.7.1</version>
</dependency>
```

Expand All @@ -62,25 +63,25 @@ Only Retrieve and Rank:
<dependency>
<groupId>com.ibm.watson.developer_cloud</groupId>
<artifactId>retrieve-and-rank</artifactId>
<version>3.7.0</version>
<version>3.7.1</version>
</dependency>
```

##### Gradle

All the services:
```gradle
'com.ibm.watson.developer_cloud:java-sdk:3.7.0'
'com.ibm.watson.developer_cloud:java-sdk:3.7.1'
```

Only Retrieve and Rank:
```gradle
'com.ibm.watson.developer_cloud:retrieve-and-rank:3.7.0'
'com.ibm.watson.developer_cloud:retrieve-and-rank:3.7.1'
```

Only Visual Recognition:
```gradle
'com.ibm.watson.developer_cloud:visual-recognition:3.7.0'
'com.ibm.watson.developer_cloud:visual-recognition:3.7.1'
```

Snapshots of the development version are available in [Sonatype's snapshots repository][sonatype_snapshots].
Expand All @@ -90,7 +91,7 @@ Snapshots of the development version are available in [Sonatype's snapshots repo

Download the jar with dependencies [here][jar].

Now, you are ready to see some [examples](https://github.com/watson-developer-cloud/java-sdk/tree/master/examples/java/com/ibm/watson/developer_cloud).
Now, you are ready to see some [examples](https://github.com/watson-developer-cloud/java-sdk/tree/master/examples/src/main/java/com/ibm/watson/developer_cloud).


## Usage
Expand Down Expand Up @@ -248,6 +249,34 @@ service.setDefaultHeaders(headers);

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

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

```none
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:
```none
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

Expand All @@ -257,7 +286,7 @@ Gradle:

```sh
$ cd java-sdk
$ gradle jar # build jar file (build/libs/watson-developer-cloud-3.7.0.jar)
$ gradle jar # build jar file (build/libs/watson-developer-cloud-3.7.1.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)
Expand Down Expand Up @@ -294,4 +323,4 @@ See [CONTRIBUTING.md](.github/CONTRIBUTING.md).
[apache_maven]: http://maven.apache.org/
[sonatype_snapshots]: https://oss.sonatype.org/content/repositories/snapshots/com/ibm/watson/developer_cloud/

[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-3.7.0/java-sdk-3.7.0-jar-with-dependencies.jar
[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-3.7.1/java-sdk-3.7.1-jar-with-dependencies.jar
4 changes: 2 additions & 2 deletions alchemy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<dependency>
<groupId>com.ibm.watson.developer_cloud</groupId>
<artifactId>alchemy</artifactId>
<version>3.7.0</version>
<version>3.7.1</version>
</dependency>
```

##### Gradle
```gradle
'com.ibm.watson.developer_cloud:alchemy:3.7.0'
'com.ibm.watson.developer_cloud:alchemy:3.7.1'
```

## Alchemy Language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class Concept extends GenericModel {

/** The knowledge graph. */
private KnowledgeGraph knowledgeGraph;

/**
* Gets the knowledge graph.
*
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ subprojects {
afterEvaluate {
if (plugins.hasPlugin(JavaPlugin)) {
rootProject.tasks.docs {
source += files(sourceSets.collect { srcSet -> srcSet.allJava })
source += files(sourceSets.main.allJava)
classpath += files(sourceSets*.compileClasspath)
}
}
Expand Down
4 changes: 2 additions & 2 deletions conversation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<dependency>
<groupId>com.ibm.watson.developer_cloud</groupId>
<artifactId>conversation</artifactId>
<version>3.7.0</version>
<version>3.7.1</version>
</dependency>
```

##### Gradle
```gradle
'com.ibm.watson.developer_cloud:conversation:3.7.0'
'com.ibm.watson.developer_cloud:conversation:3.7.1'
```

## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
Expand All @@ -40,13 +41,15 @@
import com.ibm.watson.developer_cloud.service.exception.UnauthorizedException;
import com.ibm.watson.developer_cloud.service.exception.UnsupportedException;
import com.ibm.watson.developer_cloud.util.CredentialUtils;
import com.ibm.watson.developer_cloud.util.HttpLogging;
import com.ibm.watson.developer_cloud.util.RequestUtils;
import com.ibm.watson.developer_cloud.util.ResponseConverterUtils;
import com.ibm.watson.developer_cloud.util.ResponseUtils;

import jersey.repackaged.jsr166e.CompletableFuture;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.ConnectionSpec;
import okhttp3.Credentials;
import okhttp3.Headers;
import okhttp3.HttpUrl;
Expand Down Expand Up @@ -124,6 +127,14 @@ protected OkHttpClient configureHttpClient() {
builder.writeTimeout(60, TimeUnit.SECONDS);
builder.readTimeout(90, TimeUnit.SECONDS);

builder.addNetworkInterceptor(HttpLogging.getLoggingInterceptor());

ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.allEnabledCipherSuites()
.build();

builder.connectionSpecs(Arrays.asList(spec, ConnectionSpec.CLEARTEXT));

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static Gson createGson(Boolean prettyPrint) {
if (prettyPrint) {
builder.setPrettyPrinting();
}

builder.disableHtmlEscaping();
return builder.create();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2017 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.developer_cloud.util;

import java.util.logging.Logger;

import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;

/**
* HttpLogging logs HTTP request and response data.
*
* Instantiates a new HTTP logging. The logging level will be determinate by the {@link Logger} used in this class.
* Basic HTTP request response will be log if Level is INFO, HEADERS if level is FINE and all the bodies if Level is
* ALL.
*/
public class HttpLogging {
private static final Logger LOG = Logger.getLogger(HttpLogging.class.getName());

private HttpLogging() { }

private static final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
static {
if (LOG.isLoggable(java.util.logging.Level.ALL)) {
loggingInterceptor.setLevel(Level.BODY);
} else if (LOG.isLoggable(java.util.logging.Level.FINE)) {
loggingInterceptor.setLevel(Level.HEADERS);
} else if (LOG.isLoggable(java.util.logging.Level.INFO)) {
loggingInterceptor.setLevel(Level.BASIC);
}
}

public static HttpLoggingInterceptor getLoggingInterceptor() {
return loggingInterceptor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ private void setupLogging() {
(ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
root.setLevel(ch.qos.logback.classic.Level.OFF);
try {
FileInputStream configFile = new FileInputStream("src/test/resources/logging.properties");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream configFile = classLoader.getResourceAsStream("logging.properties");
LogManager.getLogManager().readConfiguration(configFile);
} catch (IOException ex) {
System.out.println("WARNING: Could not open configuration file");
Expand Down
70 changes: 34 additions & 36 deletions core/src/test/java/com/ibm/watson/developer_cloud/util/WaitFor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package com.ibm.watson.developer_cloud.util;

import java.util.concurrent.TimeUnit;
Expand All @@ -21,43 +20,42 @@
*/

public class WaitFor {
/**
* Static method used to wait for a specific condition to be satisfied.
*
* @param condition
* The condition to check
* @param time
* The maximum time to wait for the condition to become true
* @param unit
* The time unit of the {@code time} argument
* @param sleepMs
* The time to wait between checks
*
* @return true if the condition was true before the timeout, false if it wasn't.
*/
public static boolean waitFor(Condition condition, long time, TimeUnit unit, long sleepMs) {
long waitMs = unit.toMillis(time);
long startMs = System.currentTimeMillis();
while (System.currentTimeMillis() - startMs < waitMs) {
if (condition.isSatisfied()) {
return true;
}
try {
Thread.sleep(sleepMs);
} catch (InterruptedException e) {
throw new RuntimeException("WaitFor aborted", e);
}
}
return false;

private WaitFor() {}

/**
* Static method used to wait for a specific condition to be satisfied.
*
* @param condition The condition to check
* @param time The maximum time to wait for the condition to become true
* @param unit The time unit of the {@code time} argument
* @param sleepMs The time to wait between checks
*
* @return true if the condition was true before the timeout, false if it wasn't.
*/
public static boolean waitFor(Condition condition, long time, TimeUnit unit, long sleepMs) {
long waitMs = unit.toMillis(time);
long startMs = System.currentTimeMillis();
while (System.currentTimeMillis() - startMs < waitMs) {
if (condition.isSatisfied()) {
return true;
}
try {
Thread.sleep(sleepMs);
} catch (InterruptedException e) {
throw new RuntimeException("WaitFor aborted", e);
}
}
return false;
}

/**
* The Interface Condition.
*/
public interface Condition {
/**
* The Interface Condition.
* @return true/false indicating whether or not the condition has been met.
*/
public interface Condition {
/**
* @return true/false indicating whether or not the condition has been met.
*/
boolean isSatisfied();
}
boolean isSatisfied();
}
}
4 changes: 2 additions & 2 deletions discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<dependency>
<groupId>com.ibm.watson.developer_cloud</groupId>
<artifactId>discovery</artifactId>
<version>3.7.0</version>
<version>3.7.1</version>
</dependency>
```

##### Gradle
```gradle
'com.ibm.watson.developer_cloud:discovery:3.7.0'
'com.ibm.watson.developer_cloud:discovery:3.7.1'
```

## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Override default enum handling for poorly formed JSON field types schema.
*/
public class FieldAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
if (!Field.class.isAssignableFrom(typeToken.getRawType())) {
Expand Down
Loading

0 comments on commit b8f2563

Please sign in to comment.