Set the network route on the RESTEasy client before creating the annotated API object. A typed API proxy is a Java object, not the forward network intermediary.

import jakarta.ws.rs.client.ClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;

ResteasyClientBuilder builder =
    (ResteasyClientBuilder) ClientBuilder.newBuilder();

ResteasyClient client = builder
    .defaultProxy("proxy.example.net", 8080, "http")
    .build();

MyApi api = client
    .target("https://api.example.net")
    .proxy(MyApi.class);

This is RESTEasy 6.2's Jakarta API, with RESTEasy as the installed client provider and MyApi already defined by the application. The proxy arguments are hostname, integer port and proxy transport scheme. For permitted public-API requests, use a matching HTTP endpoint from your service or the HTTP proxy list. Keep the API's destination on target; an HTTPS API can use an HTTP proxy.

Keep the client alive for its typed proxy's calls, then close it at workload completion. Returning the API object from an already closed client scope leaves it without its transport.

Decide who owns that transport. The builder documentation describes the default Apache HTTP Client integration. A supplied ClientHttpEngine changes the boundary: httpEngine supersedes builder SSL and connection-specific configuration. Set proxy and TLS through that engine's supported interface.

Older ClientExecutor-based examples instead configure a wrapped Apache client. Match that generation rather than pasting it into the Jakarta builder.

In either branch, keep the API hostname as TLS identity with verification enabled. Proxy authentication, API login and certificate trust are separate requirements; a route alone does not provide every authentication scheme.

متعلقہ مضامین