I am able to set a socks proxy server by code like this:
System.getProperties().setProperty("socksProxySet", "true");
System.getProperties().setProperty("socksProxyHost", address);
System.getProperties().setProperty("socksProxyPort", port);
Accordind to http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html, I can unset a HTTP, HTTPS and FTP proxy like this:
System.setProperty("http.proxyHost", null);
Question: Can I unset a socks proxy as well?
By doing:
System.getProperties().setProperty("socksProxyHost", null);
I got nothing but a NullPointerException...
Ty
use:
System.clearProperty("http.proxySet");
System.clearProperty("http.proxyHost");
System.clearProperty("http.proxyPort");
this will clear the proxy settings.
You may need to clear socksProxyPort as well.
socksProxySet is imaginary and does nothing; ditto httpProxySet, http.proxySet, https.proxySet, etc. notwithstanding what it says in several books.
However you should really be using java.net.Proxy for this kind of thing if you have to use and then not use a proxy.
Related
I develop a code to access a SOAP-Server via proxy and regarding to the description here I can set a global Proxy. Although my question seems Naive but I have not find any guide how to set Username and Password for this proxy setting in my java code?
you can at runtime get the System's properties and set all what you need to configurate the proxy...
Example:
System.getProperties().put("http.proxyHost", "myProxyURL");
System.getProperties().put("http.proxyPort", "myProxyPort");
System.getProperties().put("http.proxyUser", "myUserName");
System.getProperties().put("http.proxyPassword", "myPassword");
After some days I found the solution in my case and I try to explain it here.
It is important to know which kind of SOAP Client service you have wrote. In my case I used CXF 3.1.7 to generate Java code. To be more explicit I had a WSDL file and Generated the code via wsdl2java plugin in maven with the mentioned version.
In the level of the WebService the follwoing can be done in code to enter the proxy Setting
private void setProxySetting(EventPortType port) {
try{
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.getClient().setProxyServer("***host***");
http.getClient().setProxyServerPort(80);
http.getProxyAuthorization().setUserName("***username***");
http.getProxyAuthorization().setPassword("***password***");
}catch (Exception e) {
logger.error("Please Enter your proxy setting in MyClass class", e);
}
}
The port is comming from the Service Level that I got like this
EventService es = new EventService();
EventPortType port = es.getEventPort();
setProxySetting();
I need set a DNS in my app.
I can't figure out how to add it:
//Http Client
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.addInterceptor(interceptor);
client.dns("172.10.0.100");
You can set the DNS via the WIFI settings and then just do this:
client.dns(Dns.SYSTEM);
now it should get the info from there.
This is an example of setting an alternative DNS strategy or per host overrides
Dns dns = ...
builder.dns(dns);
DnsOverride.kt
DnsSelector.kt
See this post dns-android-okhttp and add dependency which I defined below, and it will work :)
compile 'dnsjava:dnsjava:2.1.7'
I am working with orchid library and this is my code:
(...)
Proxy proxy = new Proxy(Proxy.Type.SOCKS,new InetSocketAddress("localhost",9150));
httpUrlConnetion = (HttpURLConnection) website.openConnection(proxy);
httpUrlConnetion.setRequestProperty("User-Agent","any user-agent");
httpUrlConnetion.setConnectTimeout(5000);
httpUrlConnetion.setReadTimeout(20000);
return Jsoup.parse(IOUtils.toString(httpUrlConnetion.getInputStream()));
And I am getting this warning:
WARNING: Your application is giving Orchid only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4a (e.g. via privoxy or socat) instead. For more information please see https://wiki.torproject.org/TheOnionRouter/TorFAQ#SOCKSAndDNS
I started on this answer to setup orchid.
I see this post but dind't get it working under http.
How to solve it? or any other way to easy use Tor with java?
Thanks!
In your mentioned thread you are using the URL class for resolving the URL to an IP adddress which will use the Native DNS-resolving technique (which is not tunneled through Tor).
You could use SilverTunnel-NG instead, this will also do the DNS-resolving over Tor.
Check out an example implementation here.
I'm trying to access an FTP server through an FTP SITE Proxy to bypass a firewall using it.sauronsoftware.ftp4j.FTPClient I know my username/password is correct because I can connect using FileZilla. I tried using Authenticator, but it has no use. Code:
import java.net.Authenticator;
import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.connectors.FTPProxyConnector;
...
FTPClient client = new FTPClient();
FTPProxyConnector connector = new FTPProxyConnector(String "proxyHost", int proxyPort);
client.setConnector(connector);
Authenticator.setDefault(new Authenticator() {
#Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("proxyUser", "proxyPass".toCharArray());
}});
System.setProperty("ftp.proxyHost", "proxyHost");
System.setProperty("ftp.proxyPort", "proxyPort");
System.setProperty("ftp.proxyUser", "proxyUser");
System.setProperty("ftp.proxyPass", "proxyPass");
System.out.println("Proxy Accessed");
client.connect("ftpHost");
client.login("ftpUser", "ftpPass");
Gives me this error: java.io.IOException: Proxy authentication failed
Things I have tried:
Using the alternate constructor (String, int, String, String).
Removing Authenticator
Using just Authenticator, without the FTPProxyConnector
Authenticating before setting the connector, and vice versa.
However, when I am JUST using the Authenticator, I get a different error saying Connection timed out.
Both errors occur on line client.connect("ftpHost");
ANY help would be appreciated.
Note: The FTP Proxy Connector
EDIT: I found out that the proxy is used to bypass a Firewall-1 Checkpoint -- if this helps.
Check password property name. It's name is ftp.proxyPassword, and not ftp.proxyPass.
System.setProperty("ftp.proxyUser", "proxyUser");
System.setProperty("ftp.proxyPassword", "proxyPass");
Try it and let us know your results!
Check password property name. It's name is ftp.proxyPassword, and not ftp.proxyPass.
System.setProperty("ftp.proxyUser", "proxyUser");
System.setProperty("ftp.proxyPassword", "proxyPass");
Try it and let us know your results!
I found the solution...
I discovered that the FTP client was responding with a different response code:
200-User <username> authenticated by FireWall-1 authentication
In the source code of FTPProxyConnector, a response code of anything other than the regular
230-Connected to server. Logging in...
will throw an error.
I had to decompile the class file for FTPProxyConnector and then modify the source code, then recompile and save it back to the jar. Worked like a charm.
I need to establish and send/read over/from an https connection (to a website of course) but through an http proxy or SOCKS proxy. A few other requirements
supports blocking (I can't use non-blocking/nio)
isn't set as an environment or some other global scope property (there are multiple threads accessing)
I was looking into HttpCore components but I did not see any support for blocking https.
Look at the java.net.Proxy class. That does what you need. You create one, and then pass it to the URLConnection to create the connection.
To support per-thread proxy, your best bet is Apache HttpClient 4 (Http Components Client). Get the source code,
http://hc.apache.org/downloads.cgi
It comes with examples for both HTTP proxy and SOCKS proxy,
ClientExecuteProxy.java
ClientExecuteSOCKS.java
Did you look at Apache HTTP Client? Haven't used it in ages but I did use it to pick a proxy server dynamically. Example from site here:
HttpClient httpclient = new HttpClient();
httpclient.getHostConfiguration().setProxy("myproxyhost", 8080);
httpclient.getState().setProxyCredentials("my-proxy-realm", " myproxyhost",
new UsernamePasswordCredentials("my-proxy-username", "my-proxy-password"));
GetMethod httpget = new GetMethod("https://www.verisign.com/");
try {
httpclient.executeMethod(httpget);
System.out.println(httpget.getStatusLine());
} finally {
httpget.releaseConnection();
}
System.setProperty("http.proxyHost", "proxy.com");
System.setPropery("http.proxyPort", "8080");
URL url = new URL("http://java.sun.com/");
InputStream in = url.openStream();
http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html