ClassNotFoundException: java.net.http.HttpResponse in WF 18 / Java 11

127 Views Asked by At

In a JEE app deployed in Wildfly 18.0.1.Final with OpenJDK 64-Bit Server VM 11.0.15+9-LTS, I run into a ClassNotFoundException on java.net.http.HttpResponse (actually, one of the dependency is using it, and fails on java.net.http.HttpResponse$BodyHandler but I tried using java.net.http.HttpResponse directly in my code and ran into the same issue).

I tried to add the java.net.http module in WEB-INF/jboss-deployment-structure.xml in the WAR but it does not change a thing.

<jboss-deployment-structure>
  <module name="deployment.java.net.http" />
</jboss-deployment-structure>

The stacktrace ends with:

Caused by: java.lang.NoClassDefFoundError: java/net/http/HttpResponse$BodyHandler        at deployment.orbis-events-4u.war//io.apicurio.registry.rest.client.impl.RegistryClientImpl.<init>(RegistryClientImpl.java:67)
        at deployment.orbis-events-4u.war//io.apicurio.registry.rest.client.impl.RegistryClientImpl.<init>(RegistryClientImpl.java:63)
        at deployment.orbis-events-4u.war//io.apicurio.registry.rest.client.RegistryClientFactory.create(RegistryClientFactory.java:34)
        at deployment.orbis-events-4u.war//io.apicurio.registry.serde.AbstractSchemaResolver.configure(AbstractSchemaResolver.java:84)
        at deployment.orbis-events-4u.war//io.apicurio.registry.serde.DefaultSchemaResolver.configure(DefaultSchemaResolver.java:59)
        at deployment.orbis-events-4u.war//io.apicurio.registry.serde.SchemaResolverConfigurer.configure(SchemaResolverConfigurer.java:75)
        at deployment.orbis-events-4u.war//io.apicurio.registry.serde.AbstractKafkaSerDe.configure(AbstractKafkaSerDe.java:68)
        at deployment.orbis-events-4u.war//io.apicurio.registry.serde.avro.AvroKafkaSerializer.configure(AvroKafkaSerializer.java:81)
        at deployment.orbis-events-4u.war//org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:375)
        ... 62 more
Caused by: java.lang.ClassNotFoundException: java.net.http.HttpResponse$BodyHandler from [Module "deployment.orbis-events-4u.war" from Service Module Loader]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
        ... 71 more

I'm very surprised that access to java.net.http module is not available out of the box. Is there something I can do in the configuration of my app? Is it a known WF issue?

1

There are 1 best solutions below

0
zapho On

The content of jboss-deployment-structure.xml I was using is incorrect.

Issue is solved with the following content:

<jboss-deployment-structure>
  <deployment>
    <dependencies>
      <module name="java.net.http"/>
    </dependencies>
</deployment>