public RealtimeNotificationConfig getRealtimeConfigs()

in sdk/communication/azure-communication-chat/src/main/java/com/azure/android/communication/chat/implementation/notifications/signaling/RealtimeNotificationConfigClient.java [44:110]


    public RealtimeNotificationConfig getRealtimeConfigs(String token, String endpoint, String configApiVersion) {
        /// Construct the URL
        String urlString = endpoint + "/chat/config/realTimeNotifications?api-version=" + configApiVersion;

        // Build the HttpRequest
        HttpRequest request = new HttpRequest(HttpMethod.GET, urlString);
        request
            .setHeader(AUTHORIZATION_HEADER, "Bearer " + token)
            .setHeader("Accept", "application/json");

        // Initialize CountDownLatch and error holder
        CountDownLatch latch = new CountDownLatch(1);
        final Throwable[] requestError = { null };
        final RealtimeNotificationConfig[] configResult = {null};

        // Send the request asynchronously using HttpPipeline
        httpPipeline.send(request, RequestContext.NONE, CancellationToken.NONE, new HttpCallback() {
            @Override
            public void onSuccess(HttpResponse response) {
                int statusCode = response.getStatusCode();
                logger.info("Retrieve realtime notification config HTTP response code: " + statusCode);
                if (statusCode != 200) {
                    try {
                        String errorBody = response.getBodyAsString();
                        requestError[0] = new RuntimeException("Registrar register request failed with HTTP status code "
                            + statusCode
                            + ". Error message: "
                            + errorBody);
                    } catch (Exception e) {
                        requestError[0] = new RuntimeException("Failed to read error response body", e);
                    }
                } else {
                    // Convert the response content to RealtimeNotificationConfig
                    try {
                        ObjectMapper objectMapper = new ObjectMapper();
                        configResult[0] = objectMapper.readValue(response.getBodyAsString(), RealtimeNotificationConfig.class);
                        logger.info("Successfully converted response to RealtimeNotificationConfig.");
                    } catch (Exception e) {
                        logger.error("Failed to parse response body to RealtimeNotificationConfig: " + e.getMessage(), e);
                        requestError[0] = new RuntimeException("Failed to parse response body", e);
                    }
                }
                latch.countDown();
            }

            @Override
            public void onError(Throwable error) {
                logger.error("HTTP request failed: " + error.getMessage(), error);
                requestError[0] = error;
                latch.countDown();
            }
        });

        // Wait for the asynchronous operation to complete (with a timeout for safety)
        boolean completed = awaitOnLatch(latch);
        if (!completed) {
            throw logger.logThrowableAsError(new RuntimeException("HTTP request timed out."));
        }

        // Check for errors and throw an exception if necessary
        if (requestError[0] != null) {
            throw logger.logThrowableAsError(new RuntimeException("All retry attempts failed.", requestError[0]));
        }

        // Return the result
        return configResult[0];
    }