Hello,
How can we set proxy configuration using Java? Proxy setting is not mentioned in the TRKD API developers guide. Is there any code snippet that can be shared to show the mechanism?
Thanks
This article describes configuration of a proxy server for Java.
In order to configure a proxy server for a Java application you should set up the following system properties (seearticleon Oracle site for additional details):
For HTTP traffic:
http.proxyHost(default: <none>)
The host name, or address, of the proxy server
http.proxyPort(default: 80)
The port number of the proxy server.
http.nonProxyHosts(default: localhost|127.*|[::1])
Indicates the hosts that should be accessed without going through the proxy. Typically this defines internal hosts. The value of this property is a list of hosts, separated by the '|' character. In addition the wildcard character '*' can be used for pattern matching. For example -Dhttp.nonProxyHosts=”*.foo.com|localhost” will indicate that every hosts in the foo.com domain and the localhost should be accessed directly even if a proxy server is specified.
For HTTPS traffic:
https.proxyHost(default: <none>)
The host name, or address, of the proxy server
https.proxyPort(default: 443)
The port number of the proxy server.
Note:The HTTPS protocol handler will use the same nonProxyHosts property as the HTTP protocol.
You can use two main approaches how to set environment variables in Java applications (the following examples assume your proxy server host is "localhost" and port is 8888):
Command line option when invoking the VM:
jre -Dhttp.proxyHost=localhost -Dhttp.proxyPort=8080 myApp
jre -Dhttps.proxyHost=localhost -Dhttps.proxyPort=8080 myApp
Using theSystem.setProperty(String, String)method, assuming that you have permission to do so:
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "8888");
System.setProperty("https.proxySet", "true");
System.setProperty("https.proxyHost", "localhost");
System.setProperty("https.proxyPort", "8888");
@Shaikh, Thanks for the reply. With reference to Chapter 53 "Building a java client" in the TRKD API guide, how/where does the above fit in?
@Shaikh, Can you please get back on the my previous question "
With reference to Chapter 53 "Building a java client" in the TRKD API guide, how/where does your solution fit in?
@NWM reviewing portal questions and I see your follow up was not answered. Do you still need help on that point? The response from Waseem indicated both a command line and code approach to setting the java proxy.