Is there any way to re-initialise a binding from withing the binding code to simulate a restart of the binding?
I’m debugging a situation where I’m struggling to find out why the communication with an API fails after some time, probably related to token expiration. Restart of the binding resolves the situation.
Restart the whole binding or a thing? For a thing you can call dispose();initialize(); .
I have a bridge that handles the API communication and a thing that models my device. The bridge implements the API communication, I’ve tried to call dispose();initialize(); on the bridge handler but for some unknown reason the re-login fails. If I do a manual restart of the binding from the karaf console the bridge manages to login again.
For the whole binding it is probably easier to use the bundle:restart command on the karaf console.
That’s what I’ve been doing but I want to be able to to that from within the binding code, not manually from the karaf console.
What I really wanna do is to understand why dispose();initialize(); does not work but until that happens a w.o. would be nice to have
As a part of the binding refresh I query the API for get-fully-loaded-cars that should return a JSON and an errorCode set to 0, but after a day or so it suddenly returns errorCode 2 and an empty JSON, unfortunately I do not now what errorCode 2 means in that case, but I will not resolve itself by just continuing with the refresh, and the next refresh will experience the same error code.
But if I then do a restart of the binding from the Karaf console, the login/refresh will start to work again.
What I have discovered is when I try to login again from within the binding, I will get another behaviour in the login sequence compared to when I do a manual binding restart.
Login sequence after binding restart:
Request english landing page
Get a 302 to local landing page (in my case swedish site)
Request local landing page
Get a 200 OK and parse csrf
Request login URL using csrf
Get a 200 OK and parse login URL
Request login
Login sequence when binding tries to re.login after getting errorCode 2:
Request english landing page
Get a 302 to local landing page (in my case swedish site)
Request local landing page
Get a 302 to /portal/delegate/dashboard/WVGYYZ6JZLL8767882which is the start page that gives the impression that the session is still logged in
Since the API is reverse enginered it is not so easy to figure out what goes wrong.
I’m trying to debug a failure in my binding poll aswell and I wonder if it’s related as I get no errors at all from my binding.
Do you happen to get any openhabcloud disconnects when your binding fails?
So far with the help of a couple of beta testers it’s not the binding itself closing the connection as it kills anything that is currently in the middle of a poll.
There is some form of bug with the core or httputil that doesn’t recover but I haven’t had time to fully investigate yet.
I didn’t check the code but from description, logs and how service behaves it seems to be expiry of access token. From what you wrote about different sequences during second login this might be due to SSO cookie set by VW ID which is retained by your browser.
But this is my rough guess. Are you using OAuth 2?
From what you wrote about different sequences during second login this might be due to SSO cookie set by VW ID which is retained by your browser.
Thanks for the tip! That gives me an idea that will test, one thing that differs compared a manual restart of the binding is that the httpClient is recreated. I will add a stop/start of the HttpClient instance in my binding recovery sequence and see if that helps.
I tried stop/start on the HttpClient but that did not do it, now I changed to actually re-creating a new instance of HttpClient and that looks promising so far.