Menu

Home

Ilya Gulevskiy
Attachments
htmlExample.JPG (5807 bytes)
testGUI.JPG (37149 bytes)

jGetFreeProxyList - library to get a list of tested free proxies to java code.

This Java library help when your app need a list of able to work proxies. Just add jGetFreeProxyList to your progect, set up settings if you want and run it. According to settings, after 5 or more seconds you get list of tested free proxies.

For example, your app have to send a lot of HTTP queries for some hosts, but you dont want do it with one IP address to refuse yours ban by IP. You import jGetFreeProxyList into your app, run it in other thread, set up settings and set handlers. Afterwards jGetFreeProxyList receives list of free proxies from sites you set up in settings, make test for every IP and give you list of tested proxies into yours java code. Amount of threads and timeouts can be set up too.

WHATS NEW IN v.1.1:

  • added feature to set up RegExp pattern to parse page with proxies;
  • now, it is possible to stop running process;
  • handlers for exceptions became more reliable and deeper;
  • errors collection became more detalized;
  • development regime is avaliable now.

How it works

  • You set up list of HTTP-pages where publish free proxies;
  • You set up how make html-parsing of this pages;
  • jGetFreeProxyList get this pages, parse it and build list of unchecked proxies;
  • jGetFreeProxyList checks every proxy through popular sites you set up;
  • jGetFreeProxyList return in your app list of checked proxies.

[How it works in library]
[How it use in GUI application]

Getting start

Add jGetFreeProxyList.jar library to your Java progect and import it in code.

Firstly, you need to set handlers and create a instance of jGetFreeProxyList:

// Create instance with listener
jGetFreeProxyList jGetFreeProxyList = new jGetFreeProxyList(

    // Set handlers
    new jGetFreeProxyListListener(){

        // Method will cal every second and give a consumer percentage of work
        public void process(int getProxyPerc, int testProxyPerc){

              // There you can set a progress bar value or other information things.
              // getProxyPerc - percentage of ask urls with proxies
              // testProxyPerc - percentage of test proxies

        }

        // It will called when all work is done. 
        public void done(ArrayList<ProxyItem> testedProxies, WorkErrors errors){

               // testedProxies - list of well-work proxies 
              // errors - structure of errors. null if it was no errors, 
              // but it will almost never happens, because it consists by all responses 
              // of servers when proxy was refused.

        }
    }
);

In second, you have to run processes:

try {

    // There you can adjust settings, see manual.
    // By default jGetFreeProxyList has common settings for correct work.
    // But is better to use your own.

    // Start work
    jGetFreeProxyList.run();
}
catch(Exception e) {

    // Have to call to stop other processes
    jGetFreeProxyList.shutdown();

    System.out.println(e.getMessage());
}

Of course, in GUI application it have to run in different thread. See [How it use in GUI application] or testGUI source code in jGetFreeProxyList archive for more details.

How to setting up

Simple example to setting up jGetFreeProxyList:

// Set up sites to test each proxy. 
Settings.TestByUrls.clear();
Settings.TestByUrls.add(new URL("http://google.com"));
Settings.TestByUrls.add(new URL("http://www.amazon.com/"));
Settings.TestByUrls.add(new URL("http://www.facebook.com/"));

// Set up where get proxies list. Take care: by default, IP has to be in format ip:port. 
Settings.GetProxyUrls.clear();
Settings.GetProxyUrls.add(new InfoUrl(new URL("http://samair.ru/proxy/")));
Settings.GetProxyUrls.add(new InfoUrl(new URL("http://proxydb.net/")));

// For more details see documentation for Settings.

All settings is static, that means you can not run two different instances of jGetFreeProxyList with different settings. But you can run many different instances to check the same settings. It can be useful for reach more assurance.

You can set up RegExp pattern to parse page and get list of proxies. For example, some page has next html with proxy IP and port:

Now, you can add this page to jGetFreeProxyList settings:

InfoUrl iu = new InfoUrl(new URL("https://www.us-proxy.org/"));
String p = "<td>([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})</td>\\s*<td>([0-9]+)</td>";
iu.setPatternString(p);

// When will test new Url and RegExp for parse it, you must check whether it work right
// ArrayList<ProxyItem> testList = iu.test();

Settings.GetProxyUrls.add(iu);

Note, when you add new URL-page and RegExp pattern for parse it, is highly recommend on development stage to check once with InfoUrl.test() method to know whether this pattern work right or not. In the future this check is not need.

Be aware, if returned ArrayList is empty, that means yours RegExp setted by setPatternString(String PatternString) is wrong and you must try other RegExp.

Each public class and methods in this library well-documented. See full documentation in library archive

Test GUI

For test purposes you can run testGUI app. It is GUI-app uses jGetFreeProxyList library and can show you that all work well.

SVN content

SVN-repository contain two progects: jGetFreeProxyList and testGUI.
For your information you can see how possible to use jGetFreeProxyList in:

trunk/jGetFreeProxyList/src/jGetFreeProxyList/jGetFreeProxyList.java main()
trunk/testGUI/src/testgui/MainForm.java jButtonStartActionPerformed()

Project Members:


Related

Documentation: How it use in GUI application
Documentation: How it works in library

MongoDB Logo MongoDB