• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #5876

17 Dec 2025 04:15PM UTC coverage: 12.895% (-0.008%) from 12.903%
#5876

Pull #1641

github

web-flow
Merge 9a2ba2654 into e14e97bb7
Pull Request #1641: fix(boxsdkgen): replace internal links with absolute links (box/box-openapi#570)

8368 of 64891 relevant lines covered (12.9%)

0.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/src/main/java/com/box/sdk/RealtimeServerConnection.java
1
package com.box.sdk;
2

3
import com.eclipsesource.json.Json;
4
import com.eclipsesource.json.JsonArray;
5
import com.eclipsesource.json.JsonObject;
6
import java.net.MalformedURLException;
7
import java.net.URL;
8

9
class RealtimeServerConnection {
10
  public static final URLTemplate EVENT_URL = new URLTemplate("events");
1✔
11
  public static final URLTemplate EVENT_POSITION_URL = new URLTemplate("events?stream_position=%s");
1✔
12

13
  private final BoxAPIConnection api;
14
  private final int timeout;
15
  private final String serverURLString;
16

17
  private int retries;
18

19
  RealtimeServerConnection(BoxAPIConnection api) {
1✔
20
    BoxJSONRequest request = new BoxJSONRequest(api, EVENT_URL.build(api.getBaseURL()), "OPTIONS");
1✔
21
    try (BoxJSONResponse response = request.send()) {
1✔
22
      JsonObject jsonObject = Json.parse(response.getJSON()).asObject();
1✔
23
      JsonArray entries = jsonObject.get("entries").asArray();
1✔
24
      JsonObject firstEntry = entries.get(0).asObject();
1✔
25
      this.serverURLString = firstEntry.get("url").asString();
1✔
26
      this.retries = Integer.parseInt(firstEntry.get("max_retries").asString());
1✔
27
      this.timeout = firstEntry.get("retry_timeout").asInt();
1✔
28
      this.api = api;
1✔
29
    }
30
  }
1✔
31

32
  int getRemainingRetries() {
33
    return this.retries;
1✔
34
  }
35

36
  boolean waitForChange(long position) {
37
    if (this.retries < 1) {
1✔
38
      throw new IllegalStateException("No more retries are allowed.");
×
39
    }
40

41
    URL url;
42
    try {
43
      String u = this.serverURLString + "&stream_position=" + position;
1✔
44
      url = new URL(u);
1✔
45
    } catch (MalformedURLException e) {
×
46
      throw new BoxAPIException("The long poll URL was malformed.", e);
×
47
    }
1✔
48

49
    while (this.retries > 0) {
1✔
50
      this.retries--;
1✔
51
      BoxJSONRequest request = new BoxJSONRequest(this.api, url, "GET");
1✔
52
      request.setConnectTimeout(this.timeout * 1000);
1✔
53
      request.setReadTimeout(this.timeout * 1000);
1✔
54
      try (BoxJSONResponse response = request.send()) {
1✔
55
        JsonObject jsonObject = Json.parse(response.getJSON()).asObject();
1✔
56
        String message = jsonObject.get("message").asString();
1✔
57
        if (message.equals("new_change")) {
1✔
58
          return true;
1✔
59
        }
60
      } catch (BoxAPIException e) {
×
61
        break;
×
62
      }
×
63
    }
×
64

65
    return false;
×
66
  }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc