当 运行 在 IDE 之外时,HttpClient .send() 抛出 IOException
HttpClient .send() throws IOException when running outside the IDE
我尝试通过 HttpClient 获取 Github 存储库的最新发布标签。
计划是向 github.com/user/repository/releases/latest 发送请求并获取重定向的 uri 以确定最新的发布标签。
当程序在我的 IDE 中 运行ning 时,一切正常。但是由于某些原因,当程序被 jlinked + jpackaged 时抛出 IOException。
我已经尝试 运行 作为管理员来排除这种可能性。
我的代码:
private static String latestVersionTag() {
HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).build();
HttpRequest request = HttpRequest
.newBuilder(URI.create("https://github.com/{placeholderUser}/{placeholderRepo}/releases/latest"))
.timeout(Duration.ofSeconds(5))
.build();
try {
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
String path = response.uri().getPath();
return path.substring(path.lastIndexOf('/') + 1);
} catch (IOException | InterruptedException e) {
return null;
}
}
编辑:我运行jlinked图像没有打包得到堆栈跟踪(之前没想到,抱歉)
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:576)
at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:123)
at launchofexile/com.github.cptblacksheep.launchofexile.UpdateChecker.latestVersionTag(UpdateChecker.java:76)
at launchofexile/com.github.cptblacksheep.launchofexile.UpdateChecker.checkForNewVersion(UpdateChecker.java:35)
at launchofexile/com.github.cptblacksheep.launchofexile.UpdateChecker.startupCheckForNewVersion(UpdateChecker.java:28)
at launchofexile/com.github.cptblacksheep.launchofexile.LaunchOfExileMain.initialize(LaunchOfExileMain.java:285)
at launchofexile/com.github.cptblacksheep.launchofexile.LaunchOfExileMain.main(LaunchOfExileMain.java:475)
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:358)
at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:293)
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:204)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:172)
at java.base/sun.security.ssl.SSLEngineImpl.decode(SSLEngineImpl.java:736)
at java.base/sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:691)
at java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:506)
at java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:482)
at java.base/javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:679)
at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader.unwrapBuffer(SSLFlowDelegate.java:529)
at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader.processData(SSLFlowDelegate.java:433)
at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader$ReaderDownstreamPusher.run(SSLFlowDelegate.java:268)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler$LockingRestartableTask.run(SequentialScheduler.java:205)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:149)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:230)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
握手失败,因为您的自定义 run-time 图像缺少必要的加密模块。添加:
--add-modules jdk.crypto.cryptoki,jdk.crypto.ec
何时 运行 jlink
应该可以解决问题。
我不确定您是否绝对需要 两个 模块,或者如果您不需要两个模块,则两者中哪一个是必需的。也有可能其中一个requires
另一个,导致另一个被隐式拉入。
我尝试通过 HttpClient 获取 Github 存储库的最新发布标签。
计划是向 github.com/user/repository/releases/latest 发送请求并获取重定向的 uri 以确定最新的发布标签。
当程序在我的 IDE 中 运行ning 时,一切正常。但是由于某些原因,当程序被 jlinked + jpackaged 时抛出 IOException。
我已经尝试 运行 作为管理员来排除这种可能性。
我的代码:
private static String latestVersionTag() {
HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).build();
HttpRequest request = HttpRequest
.newBuilder(URI.create("https://github.com/{placeholderUser}/{placeholderRepo}/releases/latest"))
.timeout(Duration.ofSeconds(5))
.build();
try {
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
String path = response.uri().getPath();
return path.substring(path.lastIndexOf('/') + 1);
} catch (IOException | InterruptedException e) {
return null;
}
}
编辑:我运行jlinked图像没有打包得到堆栈跟踪(之前没想到,抱歉)
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:576)
at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:123)
at launchofexile/com.github.cptblacksheep.launchofexile.UpdateChecker.latestVersionTag(UpdateChecker.java:76)
at launchofexile/com.github.cptblacksheep.launchofexile.UpdateChecker.checkForNewVersion(UpdateChecker.java:35)
at launchofexile/com.github.cptblacksheep.launchofexile.UpdateChecker.startupCheckForNewVersion(UpdateChecker.java:28)
at launchofexile/com.github.cptblacksheep.launchofexile.LaunchOfExileMain.initialize(LaunchOfExileMain.java:285)
at launchofexile/com.github.cptblacksheep.launchofexile.LaunchOfExileMain.main(LaunchOfExileMain.java:475)
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:358)
at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:293)
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:204)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:172)
at java.base/sun.security.ssl.SSLEngineImpl.decode(SSLEngineImpl.java:736)
at java.base/sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:691)
at java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:506)
at java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:482)
at java.base/javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:679)
at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader.unwrapBuffer(SSLFlowDelegate.java:529)
at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader.processData(SSLFlowDelegate.java:433)
at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader$ReaderDownstreamPusher.run(SSLFlowDelegate.java:268)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler$LockingRestartableTask.run(SequentialScheduler.java:205)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:149)
at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:230)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
握手失败,因为您的自定义 run-time 图像缺少必要的加密模块。添加:
--add-modules jdk.crypto.cryptoki,jdk.crypto.ec
何时 运行 jlink
应该可以解决问题。
我不确定您是否绝对需要 两个 模块,或者如果您不需要两个模块,则两者中哪一个是必需的。也有可能其中一个requires
另一个,导致另一个被隐式拉入。