As a relative newbie in the Java world, I am finding many things frustratingly obtuse to accomplish that are relatively trivial in many other frameworks. A primary example i
httpunit and htmlunit are 2 customizable and configurable Java http clients able to anything a browser such as simulate firefox, headless browsing, scheduled software clients and agents.
there are libraries and frameworks written on top of NIO/Netty - RxNetty and Vertx which can be helpful to write asynchronous HTTP client
Below is an example code using vertx
public class Client extends AbstractVerticle {
@Override
public void start() throws Exception {
//lambda callback would be called when the response comes back
vertx.createHttpClient().getNow(8080, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode());
resp.bodyHandler(body -> {
System.out.println("Got data " + body.toString("ISO-8859-1"));
});
});
//this code statement will execute before response comes back
System.out.println("I am not blocked");
}
}
you can find the full blown example code from here
Looks like you want (a part of) NIO -- there's a good tutorial here, the asynchronous networking part starts at p. 30 and there are many useful links at the end.
Asyncweb provides an asynchronous http client along with its http server. Available for download from the following location:
https://svn.apache.org/repos/asf/mina/asyncweb/trunk
I just stumbled upon the asynchronous HTTP client implemented within Geronimo. You might also want to take a look it, at http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/ - Caveat: the latest commit seems over a year old.
Another project building an asynchronous HTTP client is xsocket: xsocket.sourceforge.net
Take also a look into http://www.javaworld.com/javaworld/jw-03-2008/jw-03-asynchhttp.html This article discusses async HTTP based on a HttpClient named xLightweb