Project

General

Profile

Using HttpClient from inside a WApplication

Added by Stefan Lanz over 10 years ago

Hello,

I have a class using a wt http client object to request data from a server. This class implements a method handling the done()-event of the http client. As a standalone request class it uses a given wt ioservice and everything works fine. But inside a WApplication where the app's ioservice is used the done()-event handler is never called nor the emit()-Signal of the client itself. The request is triggered by a button click and the client's post() returns successfully.

Please let me know if someone knows what I'm missing.

Thank you,

Stefan


Replies (6)

RE: Using HttpClient from inside a WApplication - Added by Koen Deforche over 10 years ago

Are you sure the done() event handler isn't called or simply the UI is not updated? Since this is a server side event you need to enableUpdates() and triggerUpdate() from the done() event handler to reflect UI updates.

RE: Using HttpClient from inside a WApplication - Added by Stefan Lanz over 10 years ago

Hello,

yes I'm sure that the done() event handler isn't called. The emitDone() event of the client itself isn't called either. Stepping through the functions of the wt http client code shows that Client::Impl::handleReadStatusLine() and Client::Impl::handleReadHeaders() processes the response. In the latter is the whole body content also processed. In the following Client::Impl::handleReadContent() is no more work to do, so it calls complete(). There it posts the emitDone() event handler to the existing server's thread pool. This emitDone() handler is never called.

I already enabled updates at application's construction.

Thank you for any advice, because I'm rather helpless with this issue.

Stefan

RE: Using HttpClient from inside a WApplication - Added by Koen Deforche over 10 years ago

Stefan,

We cannot reproduce this problem. Can you submit a big report with a test case?

Koen

RE: Using HttpClient from inside a WApplication - Added by Stefan Lanz over 10 years ago

Hello Koen,

do you mean that I should submit a new issue with my problem?

Anyway, here is some test code that roughly describes my problem. I am using your latest RC.

Thank you

Stefan

main.cpp (3.28 KB) main.cpp

RE: Using HttpClient from inside a WApplication - Added by Koen Deforche over 10 years ago

Hey Stefan,

That's a nice catch. The problem is that you are not releasing the application lock while you are using the client.

The Http::Client integrates itself within your application instance, by evoking requestDone() within the context of the application (i.e. while holding the application lock by posting to the session). Thus you can't busy-wait for the client to finish.

It would be straight-forward to remove this default behavior by making it optional. But in the end I think that busy-waiting for a response is really not nice as it blocks the UI and interactivity of your application.

Regards,

koen

RE: Using HttpClient from inside a WApplication - Added by Stefan Lanz over 10 years ago

Thank you Koen,

I am not exactly sure what you mean. The UpdateLock is never reached.

Nevertheless I got it work by moving the request and the gui update in the function "doRequestWork" that is called in its own thread.

For anyone who is interested I attach the code.

Regards,

Stefan

main.cpp (3.55 KB) main.cpp
    (1-6/6)