简体   繁体   English

Quarkus + GraalVM + URLConnection 的奇怪行为

[英]Weird behaviour with Quarkus + GraalVM + URLConnection

I am testing the Quarkus capabilities for Travel Applications and I found a weird behaviour when I try to establish an URLConnection running in a GraalVM application based on Quarkus.我正在测试旅行应用程序的 Quarkus 功能,当我尝试建立在基于 Quarkus 的 GraalVM 应用程序中运行的 URLConnection 时,我发现了一个奇怪的行为。 If I run a Native application:如果我运行本机应用程序:

./target/getting-started-1.0.0-SNAPSHOT-runner

and I Call the REST endpoint:我调用 REST 端点:

curl 'http://localhost:8080/api/v1/covid-restrictions'

then I receive the following error:然后我收到以下错误:

2022-06-01 17:38:43,844 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-0) HTTP Request to /api/v1/covid-restrictions failed, error id: f6130b71-c9fb-4a67-a996-c58fba695117-1: com.amadeus.exceptions.NetworkException: [---]

But when I run the same application as a Jar, everything is fine.但是当我运行与 Jar 相同的应用程序时,一切都很好。

java -jar target/quarkus-app/quarkus-run.jar

One example to see the error here:在此处查看错误的一个示例:

Do I need to configure the Quarkus app in some way for GraalVM?我是否需要以某种方式为 GraalVM 配置 Quarkus 应用程序?

I share the whole StackTrace if it could help:如果有帮助,我会分享整个 StackTrace:

2022-06-01 17:38:43,844 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-0) HTTP Request to /api/v1/covid-restrictions failed, error id: f6130b71-c9fb-4a67-a996-c58fba695117-1: com.amadeus.exceptions.NetworkException: [---]
        at com.amadeus.HTTPClient.fetch(HTTPClient.java:372)
        at com.amadeus.HTTPClient.execute(HTTPClient.java:358)
        at com.amadeus.HTTPClient.unauthenticatedRequest(HTTPClient.java:253)
        at com.amadeus.client.AccessToken.fetchAccessToken(AccessToken.java:67)
        at com.amadeus.client.AccessToken.updateAccessToken(AccessToken.java:53)
        at com.amadeus.client.AccessToken.lazyUpdateAccessToken(AccessToken.java:47)
        at com.amadeus.client.AccessToken.getBearerToken(AccessToken.java:39)
        at com.amadeus.HTTPClient.request(HTTPClient.java:339)
        at com.amadeus.HTTPClient.get(HTTPClient.java:67)
        at com.amadeus.dutyOfCare.diseases.Covid19AreaReport.get(Covid19AreaReport.java:51)
        at org.acme.CovidResource.hello(CovidResource.java:27)
        at org.acme.CovidResource$quarkusrestinvoker$hello_a2fbfead069e804ef1bb0315d16c4dc5e7951978.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:548)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:833)
        at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
        at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)

Many thanks in advance.提前谢谢了。

Juan Antonio胡安安东尼奥

As most APIs nowadays are, the Amadeus library is HTTPS only.与当今的大多数 API 一样,Amadeus 库仅支持 HTTPS。
For Quarkus in native mode, you need to explicitly enable SSL in src/main/resources/application.properties (except for certain extensions, see the link below).对于原生模式的 Quarkus,您需要在src/main/resources/application.properties中显式启用 SSL(某些扩展除外,请参见下面的链接)。

quarkus.ssl.native=true

See https://quarkus.io/guides/native-and-sslhttps://quarkus.io/guides/native-and-ssl

After adding this property you will get a different runtime error:添加此属性后,您将收到不同的运行时错误:

2022-06-02 00:45:25,381 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-0) HTTP Request to /api/v1/covid-restrictions failed, error id: 6d821ce1-23fd-4d88-8f63-992b6453830a-1: com.oracle.svm.core.jdk.UnsupportedFeatureError: Code that was considered unreachable by closed-world analysis was reached.

Try to register the following reflection classes ( DiseaseAreaReport and all inner classes ) as Amadeus will use GSON and therefore also Java reflection to apply the JSON String data to the DiseaseAreaReport POJO.尝试注册以下反射类( DiseaseAreaReport 和所有内部类),因为Amadeus 将使用 GSON ,因此还会使用 Java 反射将 JSON 字符串数据应用到 DiseaseAreaReport POJO。 https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection

package org.acme;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection(targets = {
        com.amadeus.Amadeus.class,
        com.amadeus.HTTPClient.class,
        com.amadeus.Params.class,
        com.amadeus.Response.class,
        com.amadeus.client.AccessToken.class,
        com.amadeus.dutyOfCare.diseases.Covid19AreaReport.class,
        com.amadeus.exceptions.ResponseException.class,
        // com.amadeus.resources.DiseaseAreaReport and all inner classes
        com.amadeus.resources.DiseaseAreaReport.class,
        com.amadeus.resources.DiseaseAreaReport.Area.class,
        com.amadeus.resources.DiseaseAreaReport.AreaAccessRestriction.class,
        com.amadeus.resources.DiseaseAreaReport.AreaPolicy.class,
        com.amadeus.resources.DiseaseAreaReport.AreaRestriction.class,
        com.amadeus.resources.DiseaseAreaReport.AreaVaccinated.class,
        com.amadeus.resources.DiseaseAreaReport.Border.class,
        com.amadeus.resources.DiseaseAreaReport.DatedInformation.class,
        com.amadeus.resources.DiseaseAreaReport.DatedQuarantineRestriction.class,
        com.amadeus.resources.DiseaseAreaReport.DatedTracingApplicationRestriction.class,
        com.amadeus.resources.DiseaseAreaReport.DeclarationDocuments.class,
        com.amadeus.resources.DiseaseAreaReport.DiseaseCase.class,
        com.amadeus.resources.DiseaseAreaReport.DiseaseInfection.class,
        com.amadeus.resources.DiseaseAreaReport.DiseaseTestingRestriction.class,
        com.amadeus.resources.DiseaseAreaReport.DiseaseVaccination.class,
        com.amadeus.resources.DiseaseAreaReport.EntryRestriction.class,
        com.amadeus.resources.DiseaseAreaReport.ExitRestriction.class,
        com.amadeus.resources.DiseaseAreaReport.GeoCode.class,
        com.amadeus.resources.DiseaseAreaReport.Link.class,
        com.amadeus.resources.DiseaseAreaReport.MaskRestriction.class,
        com.amadeus.resources.DiseaseAreaReport.Sources.class,
        com.amadeus.resources.DiseaseAreaReport.Transportation.class,
        com.amadeus.resources.DiseaseAreaReport.ValidityPeriod.class,
        com.amadeus.resources.Resource.class
})
public class AmadeusReflection {

}

I hope this fixes this issue, if not dig deeper which classes or inner classes are missing to be registered for reflection with a debugger or following the stack trace.我希望这可以解决这个问题,如果不深入挖掘哪些类或内部类缺少注册以使用调试器进行反射或跟踪堆栈跟踪。

PS your test shows the following warnings: PS您的测试显示以下警告:

[WARNING] [io.quarkus.resteasy.reactive.server.deployment.QuarkusServerEndpointIndexer] Quarkus detected the use of JSON in JAX-RS method 'org.acme.CovidResource#hello' but no JSON extension has been added. Consider adding 'quarkus-resteasy-reactive-jackson' or 'quarkus-resteasy-reactive-jsonb'.
[WARNING] [io.quarkus.resteasy.reactive.server.deployment.QuarkusServerEndpointIndexer] Quarkus detected the use of JSON in JAX-RS method 'org.acme.ConfigResource#hello' but no JSON extension has been added. Consider adding 'quarkus-resteasy-reactive-jackson' or 'quarkus-resteasy-reactive-jsonb'.

Consider to add the RESTEasy Reactive Jackson extension in the pom.xml :考虑在pom.xml中添加 RESTEasy Reactive Jackson 扩展:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM