Timeout in openhabremote binding

Hello,

when I try tu connect from my second openhab 3 Server (3.2.0M4) to my main server (3.2.0M4) I always get a communication error. In the debug log I see that there is a timeout reading the items via the rest API.

Blockquote
2021-11-30 11:23:20.176 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - The remopte server redirected the request to this URL: http://192.168.1.84:8080/rest/
2021-11-30 11:23:20.177 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Request GET http://192.168.1.84:8080/rest/
2021-11-30 11:23:20.697 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - REST API version = 5
2021-11-30 11:23:20.698 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - REST API items = http://192.168.1.84:8080/rest/items
2021-11-30 11:23:20.699 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - REST API things = http://192.168.1.84:8080/rest/things
2021-11-30 11:23:20.699 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - REST API events = http://192.168.1.84:8080/rest/events
2021-11-30 11:23:20.700 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - topic namespace = openhab
2021-11-30 11:23:20.701 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Request GET http://192.168.1.84:8080/rest/items?recursive=false&fields=name,type,groupType,state,stateDescription
2021-11-30 11:23:22.224 [DEBUG] [l.handler.RemoteopenhabBridgeHandler] - Failed to get the list of remote items using the items REST API: java.util.concurrent.TimeoutException
2021-11-30 11:23:22.228 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Closing EventSource
2021-11-30 11:23:22.228 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - EventSource stopped
2021-11-30 11:23:25.703 [DEBUG] [l.handler.RemoteopenhabBridgeHandler] - Failed to get the list of remote items using the items REST API: java.util.concurrent.TimeoutException

Blockquote

When I try to send command via curl I get the result after approximately 3 seconds (its a long list of items on my main server).
So I think the timeout for this step is far to low.
Is there any workaround to set this timeout?

Thanks for suggestions!

br. Christian

As far as I can see in the source of the openhabremote binding the timeout is set to 30 seconds:

   private static final int REQUEST_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(30);
   public String executeUrl(HttpMethod httpMethod, String url, String acceptHeader, @Nullable String content,
            @Nullable String contentType, boolean provideAccessToken, boolean asyncReading, boolean retryIfEOF)
            throws RemoteopenhabException {
        final Request request = httpClient.newRequest(url).method(httpMethod)
                .timeout(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS).followRedirects(false)
                .header(HttpHeaders.ACCEPT, acceptHeader);
        if (url.startsWith("https:") || authenticateAnyway) {
            boolean useAlternativeHeader = false;
            if (!credentialToken.isEmpty()) {
                request.header(HttpHeaders.AUTHORIZATION, "Basic " + credentialToken);
                useAlternativeHeader = true;
            }
            if (provideAccessToken && !accessToken.isEmpty()) {
                if (useAlternativeHeader) {
                    request.header("X-OPENHAB-TOKEN", accessToken);
                } else {
                    request.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken);
                }
            }
        }

which is called from

    public List<RemoteopenhabItem> getRemoteItems(@Nullable String fields) throws RemoteopenhabException {
        try {
            String url = String.format("%s?recursive=false", getRestApiUrl("items"));
            if (fields != null) {
                url += "&fields=" + fields;
            }
            boolean asyncReading = fields == null || Arrays.asList(fields.split(",")).contains("state");
            String jsonResponse = executeGetUrl(url, "application/json", false, asyncReading);
            if (jsonResponse.isEmpty()) {
                throw new RemoteopenhabException("@text/exception.json-response-empty");
            }
            return Arrays.asList(jsonParser.fromJson(jsonResponse, RemoteopenhabItem[].class));
        } catch (RemoteopenhabException | JsonSyntaxException e) {
            throw new RemoteopenhabException("@text/exception.get-list-items-api-failed", e);
        }
    }

So I am wondering if this is really a timeout problem as 3 secs < 30secs ?

EDITed: corrected typo 10 secs => 30 secs

Hello Wolfgang_S,

thanks for your fast reply!!
I checked the timestamps in log

2021-11-30 15:01:09.140 [DEBUG] [nternal.rest.RemoteopenhabRestClient] - Request GET http://192.168.1.84:8080/rest/items?recursive=false&fields=name,type,groupType,state,stateDescription
2021-11-30 15:01:14.155 [DEBUG] [l.handler.RemoteopenhabBridgeHandler] - Failed to get the list of remote items using the items REST API: java.util.concurrent.TimeoutException

so it’s about 5 seconds. Still more than 3 :slight_smile:
What I saw is that the whole request in putty takes about 15 to 20 seconds to come to an end.

br. Christian

still less than 30 secs which is the constant that is being used for the timeout value.
Is the JSON that is returned valid JSON ? Asking because there are two execeptions mentioned in the code ( RemoteopenhabException | JsonSyntaxException ) - but the text says timeout.

Hi,
looks valid, but very large I have approximately 2100 Items.

br. Christian

If you haven’t done would it be possible to check if it is valid JSON using e.g. an online tool like https://jsonformatter.curiousconcept.com/ or https://jsonlint.com/

I did a check using https://jsonformatter.curiousconcept.com/

and it seems to be correct:

 
 "editable":false,
      "type":"String",
      "name":"StartStopBudHM5",
      "label":"Start/Stop",
      "category":"calendar",
      "tags":[
         
      ],
      "groupNames":[
         "HP5",
         "DB"
      ]
   },
   {
      "link":"http://192.168.1.84:8080/rest/items/StartStopBudHM3",
      "state":"NULL",
      "stateDescription":{
         "pattern":"%s",
         "readOnly":false,
         "options":[
            
         ]
      },
      "editable":false,
      "type":"String",
      "name":"StartStopBudHM3",
      "label":"Start/Stop",
      "category":"calendar",
      "tags":[
         
      ],
      "groupNames":[
         "HP3",
         "DB"
      ]
   },

That’s just the beginning but seems to be ok.

BR. Christian

then I am out of ideas for the moment.

Hey Christian,

We are in the same boat, there is an issue with the REST API on Items. I’m having issues also using the MAP binding - so I had to remove it but it stops me in my tracks in rolling out sitemaps and habpanel until this is addressed.

I have 2400 items.

Best, Jay

1 Like

Hi Wolfgang_S

Thanks for your efforts!!
br. Christian

1 Like

Hi,
@jwiseman , @Kai
think there is another topic dealing with this timeout!

[https://community.openhab.org/t/remote-openhab-binding/107846/60](Remote openHAB Binding - #92 by Selter)

br. Christian

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.