How to configure freebase java client to connect through a proxy? - java

I am looking for a way to configure the freebase java api to connect to freebase through a proxy. I have set up sytem properties
System.setProperty("http.proxyHost", "proxy");
System.setProperty("http.proxyPort", "8080");
System.setProperty("http.proxySet", "true");
but it doesn't have any effect. Could anybody help?

It could be that an authentication is required, in this case please add
System.setProperty( "http.proxyUser", "user" );
System.setProperty( "http.proxyPassword", "password" );
or the hostname (proxy) isn't resolve this could be checked by ping hostname, you could add the IP-address instead. For further anaysis you should add the stacktrace of your exception.
HttpURLConnection has a method isUsingProxy() which could be useful for diagnostic log messages.
Further details you might find here

Nop, it does not work. I do not need to do authentication. I have found another solution. I have modified the freebase client -- the source code is freely available. The freebase client uses HttpClient4 , so you need to create HttpProxy object (and set your proxy details), and provide it to HttpClient.

Related

How to set Proxy setting for vaadin TestBench in Selenium Java?

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

Java Equivilent of InternetSetOption

I am looking for a way to programmatically change Windows Internet Options (proxy settings more specific). I saw in C# there is a class called InternetSetOption which I believe will do want I need. I was wondering is there a Java equivalent?
If not is there anyway I can in Java change Windows network proxy settings INSTANTLY because changing registry would work but you need to reboot or restart explorer.exe which aren't options for this application.
I think I found what you are looking for here.
Here is some example code:
//Set the http proxy to webcache.mydomain.com:8080
System.setProperty("http.proxyHost", "webcache.mydomain.com");
System.setPropery("http.proxyPort", "8080");
// Next connection will be through proxy.
URL url = new URL("http://java.sun.com/");
InputStream in = url.openStream();
// Now, let's 'unset' the proxy.
System.setProperty("http.proxyHost", null);
// From now on http connections will be done directly.
Now,this works reasonably well, even if a bit cumbersome, but it can get tricky if your application is multi-threaded. Remember, system properties are “VM wide” settings, so all threads are affected. Which means that the code in one thread could, as a side effect, render the code in an other thread inoperative.
EDIT:
Here is some more specific examples:
Let's look at a few examples assuming we're trying to execute the main method of the GetURL class:
$ java -Dhttp.proxyHost=webcache.mydomain.com GetURL
All http connections will go through the proxy server at webcache.mydomain.com listening on port 80 (we didn't specify any port, so the default one is used).
$ java -Dhttp.proxyHost=webcache.mydomain.com -Dhttp.proxyPort=8080
-Dhttp.noProxyHosts=”localhost|host.mydomain.com” GetURL
In that second example, the proxy server will still be at webcache.mydomain.com, but this time listening on port 8080. Also, the proxy won't be used when connecting to either localhost or host.mydonain.com.
EDIT 2:
Perhaps something along these lines then:
System.setProperty( "http.proxyHost", "webcache.mydomain.com" );
System.setProperty( "http.proxyPort", "8080" );
System.setProperty( "https.proxyHost", "webcache.mydomain.com" );
System.setProperty( "https.proxyPort", "8080" );

Using Proxy server for Java application

So i have a java app that uses Google Analytics API to gather some info. I am putting this application to run in my oracle cloud managed server which has a firewall and blocks any web calls to work. So, they setup a proxy for me to use....I've never set up a proxy to work with a java application before, I've been reading at tutorials like this: http://docs.oracle.com/javase/1.5.0/docs/guide/net/proxies.html
And i have no idea how to set this up...anyone want to point me in the right direction?
You must tell your application that there's a proxy somewhere.
As the documentation says, you must set some properties in your virtual machine. You can do it programatically:
//Set the http proxy to webcache.mydomain.com:8080
System.setProperty("http.proxyHost", "webcache.mydomain.com");
System.setPropery("http.proxyPort", "8080");
// Next connection will be through proxy.
URL url = new URL("http://java.sun.com/");
InputStream in = url.openStream();
// Now, let's 'unset' the proxy.
System.clearProperty("http.proxyHost");
// From now on http connections will be done directly.
Or use https.proxy... if the connection is HTTPS.
Besides, if you have access to the application server start script, you could add those properties as VM properties with -Dhttp.proxyHost....
The solution in my case was to configure the JVM with a HTTPS proxy:
System.setProperty("https.proxyHost", "proxy");
System.setProperty("https.proxyPort", "3128");

SOAP connections through a proxy using URLEndpoint

I've had to update a previous java application that requests a SOAP response from an external web service. This service is outside our firewall which now requires us to go through a proxy instead of hitting the URL directly.
Currently the Java App uses URLEndpoint that takes a string for the URL. Usually when I am getting to a URL through a proxy I create a URL like so:
URL url = new URL("http", "theproxy.com", 5555, finalUrl);
The problem is URLEndpoint only takes a string for the url, I tried to convert URL to string using toExternalForm() but it malformed the URL.
Any ideas as to a way around this?
EDIT: I can't use System.setProperty as this runs with a whole heap of other Java applications in tomcat.
second edit: I can't set a system properties as it will override all other applications running on the server, I can't use jsocks as the proxy we run through squid proxy which does not support socks4/5
Any help appreciated.
That's not how proxy's work. The way a proxy works is that you take your normal URL:
http://example.com/service
and instead of looking up "example.com" and port 80, the message is sent to your proxy host instead (http://theproxy.com:5555).
Java has built in proxy handling using http.proxyHost and http.proxyPort System properties.
So in your case you would need to do:
System.setProperty("http.proxyHost", "theproxy.com");
System.setProperty("http.proxyPort", "5555");
Then your code should, ideally, "Just Work".
Here is a page documenting the proxy properties.
Use Apache HttpClient and do as show in this example.
About the URL constructor with individual proxy setting:
http://edn.embarcadero.com/article/29783
(sorry don't have privileges to comment)

Launch options to force Java socket connections to localhost?

I'm trying to find a way to force any connection attempts a Jar makes to an external IP through my proxy server, which is running on localhost(Also a Java application).
Once the proxy server receives the connection it will open a connection with the external IP and begin routing the IO to and from the client/server.
I've been Googling this for 2 days, and I haven't had any luck, I believe I'm using the wrong terms in my search attempts.
If you've got any ideas, please let me know, I'll try anything.
Thanks in advance. - Sean.
If is that a "real" Proxy the you could specify the proxy to use using java system properties.
You have two alternatives:
Specify the proxy in the command line
Hardcode it into your app
Well you actually have three
Specify a .properties file, and read from there, and set it as System property ( which is pretty much option 2 but more dynamic )
From command line you'll use:
java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=8080 -jar YourJar.jar
With that all the http connections you perform will go through localhost at port 8080
The second is add this at the main method of your program:
public static void main( String [] args ) {
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "8080");
.....
}
Which does the same.
Finally loading from myapp.properties
public static void main( String [] args ) {
try { // there are cleaner ways of course
ResorceBundle bundle = ResourceBundle.getBundle("myapp");
System.setProperty("http.proxyHost", bundle.getString("proxy.server"));
System.setProperty("http.proxyPort", bundle.getString("proxy.port"));
} catch( MissingResourceException missingResourceException ){}
....
}
You just have to make sure myapp.properties is available from the classpath
More information about this functionality here
If you are asking about general (NOT HTTP / FTP specific!) proxying of Socket connections, then the simple answer is that it is not supported by Java.
When you configure a proxy for HTTP and FTP traffic, the proxying happens at the application protocol level. The Java-side proxy properties tell the URLConnection layer to connect to your designated proxy rather than the IP address from the URL your application is trying to connect to. The Java Socket level is unaware that this is happening. It just sees a requests to connect to the proxy.
This work because the HTTP and FTP protocols specifically support proxying. For instance, the first 'line' of an HTTP GET request message gives the full URL of the page that the client is requesting. If the GET request goes to a proxy, the proxy can figure out where is has to send it.
Looking at the problem of proxying at the Socket level, the first observation is that the standard Java class libraries don't support this. The second observation is that it is actually unimplementable ... unless you implement this as an alternative transport layer. The reason is that IP and TCP/IP simply do not support the notion of explicitly proxying or relaying messages / streams. And even if you did implement such a transport, it doesn't fit into the standard Socket model.
So, if you are really asking about proxying all of the network traffic for a Java application, this can only be implemented outside of the JVM; i.e. at the network transport level of the JVM's (physical or virtual) host operating system.
If it's HTTP traffic or FTP traffic, you could try the following system properties:
http.proxyHost (default: )
http.proxyPort (default: 80 if http.proxyHost specified)
http.nonProxyHosts (default:
See this link for details:
http://java.sun.com/docs/books/tutorial/networking/urls/_setProxy.html

Categories

Resources