I want to specify my Quarkus application (v2.8.3.Final) to use an HTTP proxy without changing any code
To attempt this I pass the -Dhttp.proxyHost
and -Dhttp.proxyPort
options to the terminal, like this:
./mvnw quarkus:dev -Dquarkus.http.host=0.0.0.0 -Dquarkus.http.port=9000 -Ddebug=9001 -Dhttp.proxyHost=localhost -Dhttp.proxyPort=6969
- This works for other Java applications that are based on Jersey and Tomcat
- This works on another Quarkus application as well, (created at another point, but I have ensured that the Quarkus versions are the same, v2.8.3.Final in
pom.xml
)
Comparing the working quarkus app and the problematic one
To compare the working quarkus application (A), and the other (B) I have implemented a resource that sends a request to http://google.com
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
.
.
.
@GET
@Path("/google")
@Produces(MediaType.TEXT_PLAIN)
public String google() {
Client client = ClientBuilder.newClient();
return client.target("http://www.google.com")
.request(MediaType.TEXT_PLAIN)
.get()
.readEntity(String.class);
}
and I have ensured that the Quarkus versions are the same. Here is a minimal snippet from pom.xml
<properties>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.8.3.Final</quarkus.platform.version>
</properties>
Application A successfully passes its requests to the proxy server, while B wont. Both applications are very similiar when comparing their pom.xml
files and application.properties
files. I am struggling to point out relevant differences. I would like to at least get some pointers on where I could look to fix this problem.
Other things I have attempted in addition to passing -Dhttp.proxyHost
and -Dhttp.proxyPort
:
In application properties, specify
org.jboss.resteasy.jaxrs.client.proxy.host=http://localhost
,org.jboss.resteasy.jaxrs.client.proxy.port=6969
- result: requests not going through proxy
- source: Quarkus / Restclient with proxy configuration
In application properties, specify
quarkus.rest-client.proxy-address=http://localhost:6969
,- result: requests not going through proxy
- source: https://quarkus.io/guides/all-config
In application properties specify
client/mp-rest/proxyAddress=http://localhost:6969
- result: request not going through proxy
Other ways to pass the system properties
-Dhttp.proxyHost
and-Dhttp.proxyPort
- E.g. by setting the environment variable
JAVA_TOOL_OPTIONS="-Dhttp.proxyHost -Dhttp.proxyPort"
- result: requests not going through proxy
- E.g. by setting the environment variable
Built and started a docker container with Dockerfile.jvm generated from quarkus (which is included when create a new quarkus project), then setting the env variable
HTTP_PROXY=localhost:6969
.- It simply prints that it passes the
-Dhttp.proxyHost
and-Dhttp.proxyPort
options to the application (what I have done from the beginning) - result: requests not going through proxy
- It simply prints that it passes the
System info
- OS: Windows 11, but I do everything within WSL2 (Ubuntu 20.04.3 LTS).
- CPU: Intel Core i7-10850H
CodePudding user response:
Quarkus comes with two REST clients, the old classic version and the newer reactive one. The reactive client has proxy support; the classic does not advertise it. Try to switch to the reactive client.
(copied from comment)