hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hemant <gethem...@gmail.com>
Subject Handling Http Push in client side with httpcore nio extensions
Date Thu, 13 Nov 2008 20:49:46 GMT
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 can't see entry point of consumeConent method
in code base, can anyone point me in right direction?

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



-- 
Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org

---------------------------------------------------------------------
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