gpt4 book ai didi

Worklight 适配器上的 Java SSL "valid certification path"

转载 作者:太空宇宙 更新时间:2023-11-04 06:10:11 27 4
gpt4 key购买 nike

我正在尝试使用 Worklight 适配器将一些音频二进制数据发送到 https 休息服务,由于不支持发送二进制数据 ( found here ),我编写了自己的 Java 类来使用 wink 执行休息调用。

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 ,它基本上解释了如何使用不受信任的证书创建 keystore )。我在 Worklight as explained here 中导入了我的 keystore (带有不受信任的证书) ,但仍然抛出异常。

鉴于 keystore 是我的问题的解决方案(也不确定),它是否也加载到运行 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

最佳答案

如果您需要从自定义 native java 代码使用 SSL 访问任何资源,您还需要实现对包含后端服务器可信证书的 keystore 的访问。在 worklight.properties 中配置的 keystore 仅由 WL.Server.invokeHttp(input) 的 worklight 适配器实现使用,不会加载到 JVM 中。但是您可以将后端信任证书导入到默认操作系统或 java keystore 中,以便该证书将由 JVM 加载并且可用于所有 java 应用程序。

关于Worklight 适配器上的 Java SSL "valid certification path",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28838464/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com