Rohith Murali
Rohith Murali

Reputation: 5669

Httpresponse exceeds the buffer size in Tizen

I am trying to parse an XML data contained in a ByteBuffer object which is obtained using a code similar to the following ReadBodyN(). If the Httprequest is given to a small XML page, the ReadBodyN() and parsing works fine. But for a large XML page which contains more than 50k characters after executing ReadBodyN() only 15559 characters are available in the ByteBuffer object. How can I get whole XML into the bytebuffer ?

 HttpResponse* pResponse = httpTransaction.GetResponse();
 if (pResponse->GetHttpStatusCode() == HTTP_STATUS_OK)
 {
     ByteBuffer* pBody = null;
     pBody = pResponse->ReadBodyN();
 }

Upvotes: 2

Views: 197

Answers (1)

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10083

Use the following code for reference, In tizen we are getting the response as chunks of data, As you said 15559 bytes is an reference data. So you should collect the bytebuffer data until you get the whole data.

Code description: keep the bytebuffer as class variable (here _pBuff)

_hasData is a flag which is set once the buffer has data (Then you need to append data)

Once you get the whole data clear the _pbuff

void YourClass::OnTransactionReadyToRead(HttpSession& httpSession,
      HttpTransaction& httpTransaction, int availableBodyLen) {

 AppLog("Transaction Ready to Read : availableBodyLen %d", availableBodyLen);

 try {
      HttpResponse* pHttpResponse = null;
      HttpHeader* pHttpHeader = null;

      pHttpResponse = httpTransaction.GetResponse();

      if (pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK) {

           bool _hasData = false;

           if (!_pBuff) {
                _pBuff = new ByteBuffer;
                _pBuff->Construct(availableBodyLen);
           }
           else
           {
                _pBuff->ExpandCapacity(_pBuff->GetCapacity() + availableBodyLen);
                _hasData = true;
           }

           pHttpHeader = pHttpResponse->GetHeader();

           if(_hasData)
           {
                ByteBuffer* pBody = pHttpResponse->ReadBodyN();

                // add to local store
                byte* pByte = new byte[availableBodyLen];
                pBody->GetArray(pByte,0,availableBodyLen);
                _pBuff->SetPosition(_pBuff->GetCapacity() - availableBodyLen);
                _pBuff->SetArray(pByte,0,availableBodyLen);
                delete []pByte;
                delete pBody;
           }
           else
                _pBuff = pHttpResponse->ReadBodyN();

    // Your Call || code
 }
 }

Upvotes: 2

Related Questions