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: Handling Http Push in client side with httpcore nio extensions
Date Thu, 13 Nov 2008 22:55:14 GMT
On Fri, 2008-11-14 at 02:19 +0530, hemant wrote:
> Hi,
> 
> As I mentioned in my previous mails, I am trying to write a server
> side program which handles http push for several concurrent clients
> for an external service.
> 
> Content thats pushed is binary stream and I see some data
> inconsistencies in pushed contents. Here are the steps I have taken:
> 
> // set params
> val params = new BasicHttpParams()
> params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE,64)
> params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,false)
> params.setParameter(CoreProtocolPNames.USER_AGENT,"Httpcomponents/1.1")
> 
> 
>   // request processor
>   val httpproc = new BasicHttpProcessor()
>   httpproc.addInterceptor(new RequestContent())
>   httpproc.addInterceptor(new RequestTargetHost())
>   httpproc.addInterceptor(new RequestConnControl())
>   httpproc.addInterceptor(new RequestUserAgent())
>   httpproc.addInterceptor(new RequestExpectContinue())
> 
>  val ioReactor = new DefaultConnectingIOReactor(2,params)
> 
>   val handler = new AsyncNHttpClientHandler(httpproc,new
> CustomRequestHandler(),new DefaultConnectionReuseStrategy(),params)
>   handler.setEventListener(new EventLogger())
> 
>   val sslcontext = SSLContext.getInstance("SSL");
>   sslcontext.init(null, null, null);
> 
>   val ioEventDispatch = new SSLClientIOEventDispatch(handler,
> sslcontext, params)
> 
> // on request open new connection for client
>   val httpSession = ioReactor.connect(
>       new InetSocketAddress(authInfo.streamerInfo.url,443),
>       null,
>       new RequestAttachment(authInfo,request,hostInfo),
>       new CustomRequestCallback()
>     )
> 
> 
> And in CustomRequestHandler class which extends
> NHttpRequestExecutionHandler, use
> responseEntity for handling pushed content:
> 
>   def responseEntity(response: HttpResponse,context: HttpContext):
> ConsumingNHttpEntity = {
>     val requestAttachment =
> context.getAttribute("request_attachment").asInstanceOf[RequestAttachment[GenericAmtdRequest]]
>     val entity = response.getEntity()
>     Log.log("Status is : " + response.getStatusLine())
>     val length = entity.getContentLength()
>     Log.log("Length of entity is : " + length)
>     new CustomEntity(requestAttachment)
>   }
> 
> 
> In CustomEntity class which extends ConsumingNHttpEntity class,
> instantiate a nonblocking parser and
> handle content in consumeContent class,
> 
> 
> def consumeContent(decoder: ContentDecoder,ioctrl: IOControl): Unit = {
>     Log.log("Calling Consuming content")
>     var allRead = false
>     val t = ByteBuffer.allocate(256)
> 
>     while(!allRead) {
>       val count = decoder.read(t)
>       if(count <= 0) {
>         allRead = true
>         Log.spc("Buffer reading is : " + decoder.isCompleted())
>       } else {
>         Log.spc("****** Number of Bytes read is : " + count)
>          t.flip()
>         parser.add(t)
>         t.clear()
>       }
>     }
>   }
> 
> Q1: decoder.isCompleted() never returns true. Is that because of
> persistent http push? 

I think so.

> I can't see entry point of consumeConent method
> in code base, can anyone point me in right direction?
> 

I assume this may be what you are looking for

http://hc.apache.org/httpcomponents-core/httpcore-nio/xref/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.html#298


> Q2: Is there anything wrong with above code? I can see some bytes not
> coming in the callbacks.

I took a cursory look at the code and found nothing that looked
obviously wrong.

I would strongly suggest to reduce the complexity at first and start
with a simple case. Do not use SSL encryption until you get the basic
functionality working as intended.

>  How can I debug this?

There is a number of classes in the contrib package one can use to add
debug logging to a number of standard classes such IOSession 

http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/

Could you please try to reproduce the problem with a self-contained test
case, which I could run locally to help you troubleshoot the problem?

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