I am currently working on a local proxyserver in Java, now to prevent any work for the user I want to set the system-wide proxy settings to the local proxy server using my code.
I tried using;
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "10001");
System.setProperty("proxySet", "true");
But if I am correct these are just the settings for the JVM?
How can I achieve setting a system-wide proxy?
The solution was different for each platform, I currently only implemented the proxy settings on Windows and OSX.
Modify the preferences.plist file on OSX, this is the file located at
/Library/Preferences/SystemConfiguration/preferences.plist
Modify the registry on Windows, editing the following path
Software\Microsoft\Windows\CurrentVersion\Internet Settings
Related
I am writing a Java application that interacts with the Big Query APIs and which will also run in a docker container. I need help in setting up http and https for my application. I am not sure whether specifying only environment variables for docker container is sufficient or only setting the proxy in java code is required or both and how can I do the same.
Thanks in Advance
There are multiple options to achieve this. The cleanest way is to tell the JVM to use system proxies and define the proxy as environment variables for your Docker container. All options are described below.
Option 1: Setting the proxy directly in Java
You can define the proxy directly in your code using System.setProperty(String, String):
System.setProperty("http.proxyHost", "proxy.example.com");
System.setProperty("http.proxyPort", "8080");
Note that the proxy is hardcoded. This solution only works if the proxy stays the same for all environments (local development, deployment on server / cloud).
Option 2: Sepcifying the proxy when invoking the JVM
You can set the proxy as command line parameters when invoking the VM. You don't need additional configurations in your code.
java -Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080 YourApplication
You can also use environment variables here, if you have them set. That way the proxy settings could dynamically change depending on the environment.
Option 3: Using system proxies
The third option is to tell the JVM to use the configured system proxies (which you can do as described below). This is again achieved by setting a command line parameter.
java -Djava.net.useSystemProxies=true YourApplication
Setting the system proxy
To set the system proxies for Docker, you again have two options.
Option a: Use environment variables
You can use environment variables directly in your Dockerfile:
ENV HTTP_PROXY "http://proxy.example.com:8080"
Or you can specify the environment variables in your docker run command:
docker run --env HTTP_PROXY="http://proxy.example.com:8080" your-container
Option b: Configuring the Docker client
On the Docker client, create or edit the file ~/.docker/config.json and set the proxy:
{
"proxies":
{
"default":
{
"httpProxy": "http://proxy.example.com:8080"
}
}
}
This option only configures your local client, you would need to configure other environments accordingly.
i need to connect to vaadin server for validating the vaadin Testbench license.i wrote code in java programme as
System.setProperty("https.proxyHost", "www-proxy.cccc.cccccccc.de");
System.setProperty("http.proxyPort", "1234");
System.setProperty("java.net.useSystemProxies", "true");
System.out.println("in IE");
System.setProperty("webdriver.ie.driver",
"C:\\Users\\ProjectJars\\Selenium\\IEDriiver\\IEDriverServer_Win32_3.9.0\\IEDriverServer.exe");
setDriver(new InternetExplorerDriver());
i am getting the following error ;
Your license for TestBench 4 has not been validated. Check your network connection.
i am behind the proxy , here i need to set the proxy settings to connect to server for validation . i am trying with IE driver. I am not using maven.
i also set Proxy settings in seetings.xml of maven
-<proxy>
<id>optional1</id>
<active>true</active>
<protocol>http</protocol>
<username/>
<password/>
<host>www-ccccc.ccccc.cccccccccc.com</host>
<port>1234</port>
<nonProxyHosts> 111.111.11.1|localhost|111.1.1.1 </nonProxyHosts>
</proxy>
i changed the values and proxy name here .
There is somewhat old, but still relevant discussion about this in Vaadin Forum. Namely you need to configure jvm parameters, so that Java can access internet via proxy
https://vaadin.com/forum/thread/13408660/13871749
More generic document is here
https://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html
We are using TableauSDK (Java) to publish extract into Tableau Server.
Our connection to Tableau server is via proxy. So we just set the java system properties https.proxyHost, https.proxyPort, http.proxyHost and http.proxyPort.
But it seems the proxy settings done in above java system properties does not take effect. Please help us to configure proxy settings in TableauSDK (Java)
The Tableau SDK uses a native library under the hood, which integrates with the Java SDK using JNI.
The native library respects the standard environment variables for proxy configuration, http_proxy and https_proxy. On a Linux, or Mac system, you can simply export these environment variables:
export http_proxy="http://my.proxy.server:3128"
export https_proxy="http://my.proxy.server:3128"
java -jar my-application.jar
If you use a proxy server which requires authentication, the SDK exposes a method to set the username and password:
ServerAPI.initialize();
ServerConnection serverConnection = new ServerConnection();
serverConnection.setProxyCredentials("user", "pass");
serverConnection.connect("https://tableau.url", "user", "password", "siteName");
serverConnection.publish("/path/to/extract", "projectName", "dataSourceName", true); // Overwrite Existing
I suspect this works pretty similarly using the Python SDK.
I've just gone through the web searching how to get system proxy settings. I've found:
System.setProperty("java.net.useSystemProxies", "true");
but it does nothing. I have a proxy settings in my corpo network but the code that shows the proxy list:
ProxySelector.getDefault().select(new URI("http://foo/bar")))
says it's only one proxy "DIRECT". I don't want to provide the proxy settings by hand when it's already done. Is there a way to make JVM to provide proxy settings from OS/browser to the Java program (not applet)?
Ok,I think I got it: my browser proxy is set up by some script, defined in:
Internet Properties/Connections/LAN Settings/Use automatic
configuration script
Probably, that's why Java cannot list proxy properly, even it's used in the browser. Sad, that JVM cannot parse the script and provide these settings...
You have to set the property:
System.setProperty("java.net.useSystemProxies", "true");
in the main method, otherwise it get no effect, then call the getDefault() as you described.
I have global proxy settings made from Java control applet. It takes proxy settings from browser. I need to run a Java application that does not use global proxy settings, it has to use direct connection.
How can I do it with command line arguments?
Did you have a look here: http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html ?
You can set the system properties from the command line: java ... -Dhttp.proxyHost=your-proxy.example.com ...
open java control panel using
javaws -viewer
General-> Network Settings -> direct Connetcion
now direct connection is set