Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
ios_developer
Posts: 21
Registered: ‎05-28-2013
My Device: Z10
My Carrier: Telus

Interminitent web response when making HTTPS REST call

Hi,

 

I am trying to make a HTTPS REST call and get XML response, then parse it and update screen, pretty basic stuff. However I am getting intermittent result, when I test the web call on the REST client on my desktop, it works every time.

 

Here's my cde

	QNetworkAccessManager *pNetworkAccessManager = new QNetworkAccessManager(this);

	// If any Q_ASSERT statement(s) indicate that the slot failed to connect to
	// the signal, make sure you know exactly why this has happened. This is not
	// normal, and will cause your app to stop working!!
	bool result;

	// Since the variable is not used in the app, this is added to avoid a
	// compiler warning.
	Q_UNUSED(result);

	result = connect(pNetworkAccessManager, SIGNAL(finished(QNetworkReply*)),
	        this, SLOT(onRequestFinished(QNetworkReply*)));
.....

void ApplicationUI::onRequestFinished ( QNetworkReply* reply )
{
	QString eventDateTime, trackingDescription;
    QNetworkReply::NetworkError netError = reply->error();
    qDebug() << "Web service call with response : " << reply->readAll();
    this->loadingIndicator->stop();

    if(netError == QNetworkReply::NoError)
    {
        // Emit updateListView signal to set the
        // new data model on the list.

    	QByteArray response = reply->readAll();
    	bb::data&colon;:XmlDataAccess xda;
    	QVariant list = xda.loadFromBuffer(response);

    	qDebug() << "XML Payload : " << list.toString();
    }
    else
    {
        switch(netError)
.....

 When I try the web call multiple times, I am not getting the same response, the correct response composed of 2 lines, sometimes, I just get the 1st line, sometimes 2 lines.

 

Web service call with response :  "<?xml version="1.0" encoding="UTF-8"?> <----- BAD RESPONSE

XML Payload :  "" 

Calling  "https://XXXXXXXXXX

Sending credential :  YYYYYYYYYYY

Web service call with response :  "<?xml version="1.0" encoding="UTF-8"?> <------ BAD RESPONSE

XML Payload :  "" 

Calling  "https://XXXXXXXXXX

Sending credential :  YYYYYYYYYYY

Web service call with response :  "<?xml version="1.0" encoding="UTF-8"?> <------- GOOD RESPONSE

<tra............is en ...

XML Payload :  "" 

 

Any help would be appreciated.

 

Thanks.

Please use plain text.
Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Interminitent web response when making HTTPS REST call

I remember that in QT 4.7 version was a little bug (but this is a later version). Sometimes i was not able to get the full output (in XML format). If XML output was very "big" then i get empty output, but this is not your case, i hope.

Try to read only a few bytes from output.

 

BTW: After you first call reply->readAll()is deleted. Second function call you get still empty output. So 

qDebug() << "XML Payload :

is still empty



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Please use plain text.
Contributor
ios_developer
Posts: 21
Registered: ‎05-28-2013
My Device: Z10
My Carrier: Telus

Re: Interminitent web response when making HTTPS REST call

Tried that, no go, same.

 

void ApplicationUI::onRequestFinished ( QNetworkReply* reply )
{
	QString eventDateTime, trackingDescription;
    QNetworkReply::NetworkError netError = reply->error();
    QByteArray response = reply->readAll();
    qDebug() << "XML Response : " << response;
    this->loadingIndicator->stop();

    if(netError == QNetworkReply::NoError)
    {
        // Emit updateListView signal to set the
        // new data model on the list.

    	//QByteArray response = reply->readAll();
    	bb::data&colon;:XmlDataAccess xda;
    	QVariant list = xda.loadFromBuffer(response);

    	qDebug() << "XML Payload : " << list.toString();
    }
    else
    {
        switch(netError)
        {

 

Output:

XML Response :  "<?xml version="1.0" encoding="UTF-8"?>

XML Payload :  "" 

Calling  "https://..... 

Sending credential :  "..... 

XML Response :  "<?xml version="1.0" encoding="UTF-8"?>

<trac...... xmlns=".........</e...

XML Payload :  "" 

 

Still receiving intermittent response, can anyone please help me?

Please use plain text.
Developer
superdirt
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Interminitent web response when making HTTPS REST call

AFAIK, once you call readAll(), that data is "removed" from the QNetworkReply object. If you need to both display the reply both through qDebug() and parsing, assign the value of readAll() to a QByteArray first (call it only once), then display it and then parse it. 

 

Please use plain text.
Developer
superdirt
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Interminitent web response when making HTTPS REST call

Sorry, I just realized I duplicated benecore's reply.

Please use plain text.
BlackBerry Development Advisor
RSperanza
Posts: 141
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: Interminitent web response when making HTTPS REST call

Hi.

 

What OS are you testing with?  This problem seems to be a similar to an issue reported by another developer recently.

Please use plain text.
Contributor
ios_developer
Posts: 21
Registered: ‎05-28-2013
My Device: Z10
My Carrier: Telus

Re: Interminitent web response when making HTTPS REST call

10.2
Please use plain text.
BlackBerry Development Advisor
RSperanza
Posts: 141
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: Interminitent web response when making HTTPS REST call

Hi.

 

I retested some sample code I have that uses a similar operation to download an image and ran it several times and the image loaded properly each time.

 

The last developer I helped with this issue seemed to be working with a project created with a much older version of the IDE.  When he tested the code in a newly created test project, it worked fine.  I am wonder if your situation is similar.  When you first created your project, what NDK were you working with at the time?

Please use plain text.
Contributor
ios_developer
Posts: 21
Registered: ‎05-28-2013
My Device: Z10
My Carrier: Telus

Re: Interminitent web response when making HTTPS REST call

10.2

 

I just retest my code again, it seems to be working now. However, the only problem I am having now is the serialization of the XML payload.

 

My code

 

void ApplicationUI::onRequestFinished ( QNetworkReply* reply )
{
	QString eventDateTime, trackingDescription;
    QNetworkReply::NetworkError netError = reply->error();
    QByteArray response = reply->readAll();
    qDebug() << "XML Response : " << response;
    this->loadingIndicator->stop();

    if(netError == QNetworkReply::NoError)
    {
        // Emit updateListView signal to set the
        // new data model on the list.

    	//QByteArray response = reply->readAll();
    	bb::data&colon;:XmlDataAccess xda;
    	QVariant list = xda.loadFromBuffer(response);

    	qDebug() << "XML Payload : " << list.toString();
    }
    else

 But on the log, it always initialize to null on the QVariant list

 

XML Response :  "<?xml version="1.0" encoding="UTF-8"?>

<tracking-summary xmlns="http://www.canadapost.ca/ws/track"><pin-summary><pin>CP274103524CN</pin><origin-postal-id/><destinat... item has left originating country and is en route to Canada</e...

XML Payload :  "" 

Calling  "https://soa......" 

Sending credential :  "........" 

XML Response :  "<?xml version="1.0" encoding="UTF-8"?>

<trac...

XML Payload :  "" 

 

I checked online to verify the XML payload is well formed, which I am sure it is, since I am using a public SDK which is shared by many platforms, the webpage shows the XML payload is well formed.

 

Any idea?

 

Thanks

Please use plain text.
Contributor
ios_developer
Posts: 21
Registered: ‎05-28-2013
My Device: Z10
My Carrier: Telus

Re: Interminitent web response when making HTTPS REST call

I am starting to think it's the metadata and the xmlns, I suppose XmlDataAccess doesn't like the metadata

 

<?xml version="1.0" encoding="UTF-8"?>

 

and the xmlns

 

<tra.... xmlns="http://......"><pin-.....

 

So, if that's the case, how can i kick them out before I call the loadFromBuffer?

 

Should I write code to go byte by byte to delete them?

Please use plain text.