dswitzer
01/12/2024, 2:59 PMhttpClient = createObject("java", "java.net.http.HttpClient").newBuilder()
.build()
;
I get the following exception:
Unable to make public java.net.http.HttpClient jdk.internal.net.http.HttpClientBuilderImpl.build() accessible: module java.net.http does not "exports jdk.internal.net.http" to unnamed module @12212325
What I notice is when I dump out createObject("java", "<http://java.net|java.net>.http.HttpClient"), it's showing that almost all the methods have duplicate method signatures, but with different return types.
Is this just a bug in Lucee or is there something I'm missing?dswitzer
01/12/2024, 3:07 PMdswitzer
01/12/2024, 3:33 PMnewBuilder() is <http://jdk.internal.net|jdk.internal.net>.http.HttpClientBuilderImpl and I think that relates to the issue, because the object returned is from the internals.dswitzer
01/12/2024, 5:01 PM--add-opens=<http://java.net|java.net>.http/jdk.internal.net.http=ALL-UNNAMED argument to my CATALINA_OPTS arguments, this resolves the issue.
However, should this be necessary?agentk
01/13/2024, 2:49 AMjdk.internals directly, but I can't really speak about the specifics of the Java HttpClient and why the builder is returning what it's returning though.
I've had plenty of similar issues around having to open up modules on the JVM level when doing Android as well as in the Java/CFML world directly.dswitzer
01/15/2024, 12:15 PM--add-opens=<http://java.net|java.net>.http/jdk.internal.net.http=ALL-UNNAMED JVM arguments in order to use the HttpClient JDK.
You don't need it to just use HttpClient in native Java.agentk
01/15/2024, 11:28 PMdswitzer
01/16/2024, 12:13 PMdswitzer
01/16/2024, 12:14 PMdswitzer
01/16/2024, 9:30 PMopens jdk.internal.net.http .
So if I would move all my logic into a Java class helper, it appears to work fine.
This would lead me to believe that there's a problem with the way that Lucee's classloaders are working.
@zackster Do you have any ideas?dswitzer
01/16/2024, 10:07 PMvar httpClient = createObject("java", "java.net.http.HttpClient").newBuilder()
.followRedirects(createObject("java", "java.net.http.HttpClient$Redirect")[arguments.followRedirects ? "NORMAL" : "NEVER"])
.connectTimeout(Duration.ofMillis(this.getConnectTimeout()))
.build()
;
However. if I create a simple Java class and then create an instance of it from createObject(), I can create an instance of the builder object:
package HttpClient;
import java.net.http.HttpClient;
import java.time.Duration;
public final class HttpClientProxy {
public static final HttpClient createHttpClient(boolean followRedirects, long connectTimeout){
return HttpClient.newBuilder()
.followRedirects(followRedirects ? HttpClient.Redirect.NORMAL : HttpClient.Redirect.NEVER)
.connectTimeout(Duration.ofMillis(connectTimeout))
.build()
;
}
}dswitzer
01/17/2024, 10:53 PMagentk
01/18/2024, 12:54 AM