Java proxy settings - java

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

Related

Proxy settings for Big Query Java client

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.

TableauSDK proxy settings

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.

Get Eclipse code working with Authenticated Proxy

I'm trying to get my Java code in Eclipse to access the internet, through an authenticated proxy. My code is simply reading a website source using http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html
I get this error:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
Here are the things I already tried:
- In Preferences, setting the HTTP and HTTPS proxy, clearing SOCKS, and going to Manual
- In Eclipse.ini, adding
-Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient
-Dhttp.proxyPort=8080
-Dhttp.proxyHost=XXX
-Dhttp.proxyUser=XXX
-Dhttp.proxyPassword=XXX
-Dhttp.nonProxyHosts=localhost|127.0.0.1
You need to be aware that what you are setting, is the settings for the JVM in which Eclipse runs. Your programs are started in another JVM where these settings do not apply.
Running your application creates a launch configuration, which you can open and add the system properties you need. They will then apply when that launch configuration is launched.
(also, Eclipse has a very elaborate network settings panel in the preferences window where you can configure this for Eclipse itself).

JProfiler7.1.2 not working on windows

I have installed Jprofiler 7.1.2 & tomcat 5.0.19 on WINDOWS XP. I have created one session with 127.0.0.1 as host & 8849 as port.
After clicking on OK button getting message as
Could not connect to 127.0.0.1:8849. Please make sure that the remote address is correct, the remote program is started properly, and the network route allows socket connections.
What else do I need to setup? What should I put in the start & stop commands for profiled JVM settings?
That session will connect to a JVM where the profiling agent is already loaded.
To profile a JVM where the profiling agent has not been loaded, use
Session->Quick attach
in the JProfiler main menu.
The following check list can be used to resolve the issue:
Check if the JAVA_HOME is set to same version u r using for the application
Validate for right values/parameters for %JAVA_OPTS%
Set check box ON for VM Alive (under Settings -> Profile Settings)

How to get default proxy settings in java program (not applet)?

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.

Categories

Resources