Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quarkus-rest-client can't be used with @ApplicationScoped beans for native images #8042

Closed
codependent opened this issue Mar 21, 2020 · 1 comment
Labels
area/rest-client kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@codependent
Copy link

Describe the bug
The whole context of this problem can be found on Stackoverflow: https://stackoverflow.com/questions/60787675/quarkus-rest-client-cant-be-used-with-applicationscoped-beans-for-native-image

There's a sample project with instructions to reproduce the problem at: https://github.com/codependent/quarkus-rest-client

Expected behavior
The native image should be generated

Actual behavior
Native image generation error:

Error: No instances of sun.security.provider.NativePRNG are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:  object java.security.SecureRandom
        object sun.security.ssl.SSLContextImpl$TLSContext
        object sun.security.ssl.SSLSocketFactoryImpl
        object org.apache.http.conn.ssl.SSLConnectionSocketFactory
        object java.util.concurrent.ConcurrentHashMap$Node
        object java.util.concurrent.ConcurrentHashMap$Node[]
        object java.util.concurrent.ConcurrentHashMap
        object org.apache.http.config.Registry
        object org.apache.http.impl.conn.DefaultHttpClientConnectionOperator
        object org.apache.http.impl.conn.PoolingHttpClientConnectionManager
        object org.apache.http.impl.client.HttpClientBuilder$2
        object java.lang.Object[]
        object java.util.ArrayList
        object org.apache.http.impl.client.InternalHttpClient
        object org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine
        object org.jboss.resteasy.client.jaxrs.internal.ResteasyClientImpl
        object org.codependent.RestClient_ClientProxy
        object org.codependent.RestClient_Bean
        object java.lang.Object[]
        object java.util.ArrayList
        object io.quarkus.arc.impl.ArcContainerImpl
        object io.quarkus.arc.runtime.ArcRecorder$2
        field io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory.CONTAINER

com.oracle.svm.core.util.UserError$UserException: No instances of sun.security.provider.NativePRNG are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:  object java.security.SecureRandom
        object sun.security.ssl.SSLContextImpl$TLSContext
        object sun.security.ssl.SSLSocketFactoryImpl
        object org.apache.http.conn.ssl.SSLConnectionSocketFactory
        object java.util.concurrent.ConcurrentHashMap$Node
        object java.util.concurrent.ConcurrentHashMap$Node[]
        object java.util.concurrent.ConcurrentHashMap
        object org.apache.http.config.Registry
        object org.apache.http.impl.conn.DefaultHttpClientConnectionOperator
        object org.apache.http.impl.conn.PoolingHttpClientConnectionManager
        object org.apache.http.impl.client.HttpClientBuilder$2
        object java.lang.Object[]
        object java.util.ArrayList
        object org.apache.http.impl.client.InternalHttpClient
        object org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine
        object org.jboss.resteasy.client.jaxrs.internal.ResteasyClientImpl
        object org.codependent.RestClient_ClientProxy
        object org.codependent.RestClient_Bean
        object java.lang.Object[]
        object java.util.ArrayList
        object io.quarkus.arc.impl.ArcContainerImpl
        object io.quarkus.arc.runtime.ArcRecorder$2
        field io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory.CONTAINER

Configuration

Screenshots

Environment (please complete the following information):

  • Output of uname -a or ver: 19.3.0 Darwin Kernel
  • Output of java -version: 11.0.6 AdoptOpenJDK
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.3.0.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): 3.6.3
@codependent codependent added the kind/bug Something isn't working label Mar 21, 2020
@geoand
Copy link
Contributor

geoand commented Mar 23, 2020

Hi,

Your reproducer project isn't really using the MicroProfile REST Client which the quarkus-rest-client extension provides - you are instead using the JAXRS client.

In any case, I got your reproducer working with the following changes:

diff --git a/src/main/java/org/codependent/RestClient.java b/src/main/java/org/codependent/RestClient.java
index 4bdebac..c3e0100 100644
--- a/src/main/java/org/codependent/RestClient.java
+++ b/src/main/java/org/codependent/RestClient.java
@@ -9,14 +9,17 @@ import javax.ws.rs.core.Response;
 @ApplicationScoped
 public class RestClient {
 
-    private final Client httpClient;
+    private Client client;
 
-    public RestClient() {
-        this.httpClient = ResteasyClientBuilder.newBuilder().build();
+    public Response get() {
+        return getClient().target("https://postman-echo.com/get").request().get();
     }
 
-    public Response get() {
-        return httpClient.target("https://postman-echo.com/get").request().get();
+    private Client getClient() {
+        if (client == null) {
+            client = ResteasyClientBuilder.newBuilder().build();
+        }
+        return client;
     }
 
 }
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 3c1ac56..30a003c 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,2 +1,3 @@
 # Configuration file
-# key = value
\ No newline at end of file
+# key = value
+quarkus.native.enable-https-url-handler=true

@geoand geoand closed this as completed Mar 23, 2020
@geoand geoand added the triage/invalid This doesn't seem right label Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants