Async Java HTTP client
3976 단어 client
Async Java HTTP client
I spent some of my spare time writing Rssminer , an intelligent RSS reader, I want it to be smart enough to highlight stories I like, and help me discover stories I may like.
I plan to do it by downloading as many web pages as possible from the Internet, extract RSS links it contains, download them, then apply machine learning algorithms on them. It’s ambitious.
The first thing need to be solved is an Http client. JDK’s URLConnection is blocking, 20 threads devoted to it, still not fast enough, and there are some keepalive timer come out of the way. The non-blocking AsyncHttpClient is tried, it works great, but it lacks
socks proxy
support, and I want to control everything. So, I write my own async HTTP client, by using a great library netty , which provides a async socket framework and HTTP codec.
// Http client sample usage
HttpClientConfig config = new HttpClientConfig();
header = new HashMap<String, Object>();
HttpClient client = new HttpClient(config);
URI uri = new URI("http://onycloud.com");
final HttpResponseFuture future = client.execGet(uri, header);
resp.addListener(new Runnable() {
public void run() {
HttpResponse resp = future.get(); // async
}
});
HttpResponse resp = future.get(); // blocking
The source code is concise, about 1000 lines of code(about 600 lines excluding import statements and blank lines), can be found on github .
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
어떻게 WebClient를 이용하여 CSRF가 제어하는 사이트에 시뮬레이션하여 로그인합니까일반적으로 우리는 WebRequest라는 종류를 이용하여 서버에 데이터의 POST를 진행하지만 많은 상황에서 상응하는 서버가 검증을 하고 있다. 우리는 그 속성을 바꾸어 사기 서비스기에 도달할 수 있다.그러나 서버가...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.