(Object method, Object endpointMethod, Object returnAsJson2, Object... optionalArgs)
| 7577 | } |
| 7578 | |
| 7579 | public java.util.concurrent.CompletableFuture<Object> fetchWebEndpoint(Object method, Object endpointMethod, Object returnAsJson2, Object... optionalArgs) |
| 7580 | { |
| 7581 | final Object returnAsJson3 = returnAsJson2; |
| 7582 | return java.util.concurrent.CompletableFuture.supplyAsync(() -> { |
| 7583 | Object returnAsJson = returnAsJson3; |
| 7584 | Object startRegex = Helpers.getArg(optionalArgs, 0, null); |
| 7585 | Object endRegex = Helpers.getArg(optionalArgs, 1, null); |
| 7586 | Object errorMessage = ""; |
| 7587 | Object options = this.safeValue(this.options, method, new java.util.HashMap<String, Object>() {{}}); |
| 7588 | Object muteOnFailure = this.safeBool(options, "webApiMuteFailure", true); |
| 7589 | try |
| 7590 | { |
| 7591 | // if it was not explicitly disabled, then don't fetch |
| 7592 | if (Helpers.isTrue(!Helpers.isEqual(this.safeBool(options, "webApiEnable", true), true))) |
| 7593 | { |
| 7594 | return null; |
| 7595 | } |
| 7596 | Object maxRetries = this.safeValue(options, "webApiRetries", 10); |
| 7597 | Object response = null; |
| 7598 | Object retry = 0; |
| 7599 | Object shouldBreak = false; |
| 7600 | while (Helpers.isLessThan(retry, maxRetries)) |
| 7601 | { |
| 7602 | try |
| 7603 | { |
| 7604 | response = ((java.util.concurrent.CompletableFuture<Object>)Helpers.callDynamically(this, endpointMethod, new Object[] { new java.util.HashMap<String, Object>() {{}} })).join(); |
| 7605 | shouldBreak = true; |
| 7606 | break; |
| 7607 | } catch(Exception e) |
| 7608 | { |
| 7609 | retry = Helpers.add(retry, 1); |
| 7610 | if (Helpers.isTrue(Helpers.isEqual(retry, maxRetries))) |
| 7611 | { |
| 7612 | throw e; |
| 7613 | } |
| 7614 | } |
| 7615 | if (Helpers.isTrue(shouldBreak)) |
| 7616 | { |
| 7617 | break; // this is needed because of GO |
| 7618 | } |
| 7619 | } |
| 7620 | Object content = response; |
| 7621 | if (Helpers.isTrue(!Helpers.isEqual(startRegex, null))) |
| 7622 | { |
| 7623 | Object splitted_by_start = Helpers.split(content, startRegex); |
| 7624 | content = Helpers.GetValue(splitted_by_start, 1); // we need second part after start |
| 7625 | } |
| 7626 | if (Helpers.isTrue(!Helpers.isEqual(endRegex, null))) |
| 7627 | { |
| 7628 | Object splitted_by_end = Helpers.split(content, endRegex); |
| 7629 | content = Helpers.GetValue(splitted_by_end, 0); // we need first part after start |
| 7630 | } |
| 7631 | if (Helpers.isTrue(Helpers.isTrue(returnAsJson) && Helpers.isTrue(((content instanceof String))))) |
| 7632 | { |
| 7633 | Object jsoned = this.parseJson(((String)content).trim()); // content should be trimmed before json parsing |
| 7634 | if (Helpers.isTrue(jsoned)) |
| 7635 | { |
| 7636 | return jsoned; // if parsing was not successfull, exception should be thrown |
no test coverage detected