尝试调用 Watson Translation Service

Trying to call Watson Translation Service

我正在尝试通过 Java 中的 REST 调用来调用 IBM Watson 服务。我在 Eclipse 中有一个 Web 项目,它是通过 Bluemix Tools 发布的。我也使用 .jar 文件。但是当我尝试一个简单的代码时:

LanguageTranslation service = new LanguageTranslation();
service.setUsernameAndPassword("{username}","{password}");

List <IdentifiedLanguage> langs = service.identify("this is a test");
System.out.println(langs);

我得到这个异常:

Unable to extract the trust manager on okhttp3.internal.Platform@ab895790, sslSocketFactory is class com.ibm.jsse2.SSLSocketFactoryImpl
[WARNING ] Application {http://webapp.aw/}ResourceServlet has thrown exception, unwinding now
[WARNING ] Exception in handleFault on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSDefaultFaultOutInterceptor@ac51d486
Unable to extract the trust manager on okhttp3.internal.Platform@ab895790, sslSocketFactory is class com.ibm.jsse2.SSLSocketFactoryImpl
Unable to extract the trust manager on okhttp3.internal.Platform@ab895790, sslSocketFactory is class com.ibm.jsse2.SSLSocketFactoryImpl

我认为您的 JAR 文件可能已过时。您可以尝试从 here.

下载最新版本吗

完成后,将 JAR 文件添加到项目的构建路径,然后试试这个:

LanguageTranslation service = new LanguageTranslation();
service.setUsernameAndPassword("username", "password");

ServiceCall<List<IdentifiedLanguage>> langs = service.identify("this is a test");
System.out.println(langs.execute());

似乎与 Bluemix 上使用的 JVM 和库的最新 (3.0.0.RC1) 版本不兼容。

我可以在本地 运行 示例代码就好了。只是不在 Bluemix 上。

我的解决方法是使用较旧的 2.10 版本库:

https://github.com/watson-developer-cloud/java-sdk/releases/tag/java-sdk-2.10.0

那里一切正常(但是您需要从翻译调用的末尾删除 .execute() 以与旧库兼容)。