我正在尝试使用Worklight适配器将一些音频二进制数据发送到https休息服务,并且因为不支持发送二进制数据(found here)我编写了自己的Java类来使用其余的调用眨眼。
Java代码确实有效(它是一个简单的wink客户端,通过https进行用户/密码验证,在独立的Java项目中进行测试和工作),在Worklight中我不必导入wink库,因为它们已经可用在服务器运行时中。
当我在Worklight中使用相同的Java代码时,我遇到了这个例外:
[ERROR ] FWLSE0099E: An error occurred while invoking procedure [project CitizerCare]WatsonSpeechToText/recognizeSpeechFWLSE0100E: parameters: [project CitizerCare]
java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
FWLSE0101E: Caused by: [project CitizerCare]java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetorg.apache.wink.client.ClientRuntimeException: java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
下到“由...引起”的链条,我得到了:
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我在线搜索,这似乎与SSL证书验证(problem and solution here有关,它基本上解释了如何使用不受信任的证书创建密钥库)。我在Worklight as explained here中导入了我的密钥库(带有不受信任的证书),但仍然抛出了异常。
鉴于密钥库是我的问题的解决方案(也不确定),它是否也在运行Java适配器代码的JVM中加载?我真的不明白这种行为,考虑到使用普通HTTP适配器我能够查询其他https休息服务而没有任何问题!即使气馁,也有办法在Java中禁用SSL证书验证?
这里调用了一部分代码:
public class WatsonSTT {
private final static ClientConfig config = new ClientConfig();
static {
config.connectTimeout(60000*10).readTimeout(60000*10);
BasicAuthSecurityHandler basicAuthSecHandler = new BasicAuthSecurityHandler();
basicAuthSecHandler.setUserName(username);
basicAuthSecHandler.setPassword(password);
config.handlers(basicAuthSecHandler);
}
public static String query(String contentType, String base64data) throws JsonProcessingException, IOException {
DoubleSession session = createSession();
[...]
}
private static DoubleSession createSession() throws JsonProcessingException, IOException {
RestClient client = new RestClient(config);
Resource resource = client.resource(restAddress + "/sessions");
resource.accept(MediaType.APPLICATION_JSON);
resource.header("Accept", "application/json");
resource.contentType("application/json");
resource.header("Content-Length", "0");
ClientResponse response = resource.post(""); // Exception thrown
[...]
}
}
对worklight.properties的修改:
ssl.keystore.path=conf/jssecacerts.keystore
ssl.keystore.type=jks
ssl.keystore.password=changeit
答案 0 :(得分:1)
如果您需要使用自定义本机Java代码中的SSL访问任何资源,您还需要实现对包含后端服务器的受信任证书的密钥库的访问。
在worklight.properties
中配置的密钥库仅由WL.Server.invokeHttp(input)
的worklight适配器实现使用,它未加载到JVM中。
但是您可以将后端信任证书导入默认操作系统或java密钥库,以便证书将由JVM加载,并且可用于所有Java应用程序。
答案 1 :(得分:0)
对于SSL问题,请尝试将证书导入此处的缺省密钥库:$ {server.output.dir} /resources/security/key.jks与在MobileFirst SSL Store中找到的ssl密钥库路径 - ssl.keystore。路径= CONF / MFP-default.keystore。这对我有用。