hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Submit HTTP requests and asynchronously receive HTTP responses
Date Wed, 07 Jan 2009 11:29:25 GMT
On Wed, 2009-01-07 at 02:40 -0800, slytherine wrote:
> 
> olegk wrote:
> > 
> > On Wed, 2009-01-07 at 01:57 -0800, sveno wrote:
> >> Hi,
> >> 
> >> I am looking for a basic example using NHttpClientConnection where It can
> >> be
> >> used to submit HTTP requests and asynchronously receive HTTP responses. 
> >> 
> >> In my app, I am extablishing a connection and freeze the connection for
> >> few
> >> minutes in the server-side( long polling). The response will be sent to
> >> the
> >> client,  if some event occurs or when the freezing time out expires.
> >> Here, I
> >> don't want to block the connections rather I just want to use the
> >> asynchronous (non-blocking) approach just like the above class. (submit
> >> HTTP
> >> requests and asynchronously receive HTTP responses)
> >> 
> >> It would be great if you could be provide some working example using
> >> NHttpClientConnection.
> >> 
> >> Thanks
> > 
> > http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java
> > 
> > Thanks for the reply.
> > 
> > But this example doesn't seems to be working for me.
> > Reactor starts and then it shutdown,nothing happens in the middle.
> > Is that something I'm missing here.
> > 

Works for me. Please note this example will NOT be able to connect to
remote hosts if you are behind a firewall of some kind.

Feel free to add more output to the console to see why connect requests
fail. 

---
    static class MySessionRequestCallback implements
SessionRequestCallback {

        private final CountDownLatch requestCount;        
        
        public MySessionRequestCallback(final CountDownLatch
requestCount) {
            super();
            this.requestCount = requestCount;
        }
        
        public void cancelled(final SessionRequest request) {
            System.out.println("Connect request cancelled: " +
request.getRemoteAddress());
            this.requestCount.countDown();
        }

        public void completed(final SessionRequest request) {
        }

        public void failed(final SessionRequest request) {
            System.out.println("Connect request failed: " +
request.getRemoteAddress());
            this.requestCount.countDown();
        }

        public void timeout(final SessionRequest request) {
            System.out.println("Connect request timed out: " +
request.getRemoteAddress());
            this.requestCount.countDown();
        }
        
    }
--- 

Oleg

> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message