Set Jena’s Default HTTP Proxy Before Queries Start
Understand HttpEnv’s JVM-wide default client, its startup timing and the clients that can override it for SERVICE calls.
For an embedded Jena application using its modern JDK stack, establish a common fallback before building query executions or starting workers:
import java.net.InetSocketAddress;
import java.net.ProxySelector;
import org.apache.jena.http.HttpEnv;
var http = HttpEnv.httpClientBuilder()
.proxy(ProxySelector.of(
new InetSocketAddress("proxy.example.net", 8080)))
.build();
HttpEnv.setDftHttpClient(http);
Jena's builder preserves its transport defaults while adding the selector. For an embedded workload using permitted public SPARQL endpoints and no proxy account, the HTTP proxy list can supply the selector’s HTTP address. This remains a shared JVM default, not a per-request switch.
| Operation | Client selection order |
|---|---|
| Ordinary HTTP query builder | Explicit client, URL-based registry match, HttpEnv default |
| Built-in federated SERVICE | Matching registry client, query-context client, global default |
A local or registry override can therefore use another route. The HTTP builder resolves its client when build is called and passes that object into execution; replacing the default later does not rewrite an already built execution.
Keep the startup fallback stable. Use the appropriate local/context/registry interface when routes differ.
A standalone Fuseki server also needs its deployed version's supported way to run initialization. Putting this Java code in a file does not make that server execute it.