diff --git a/src/main/java/org/jitsi/jigasi/TranscriptionGateway.java b/src/main/java/org/jitsi/jigasi/TranscriptionGateway.java index 905aa5083..66eef3eab 100644 --- a/src/main/java/org/jitsi/jigasi/TranscriptionGateway.java +++ b/src/main/java/org/jitsi/jigasi/TranscriptionGateway.java @@ -100,57 +100,66 @@ public void stop() */ private String getCustomTranscriptionServiceClass(String tenant) { + String transcriberClass = null; String remoteTranscriptionConfigUrl = JigasiBundleActivator.getConfigurationService() .getString( REMOTE_TRANSCRIPTION_CONFIG_URL, null); - if (remoteTranscriptionConfigUrl != null) + if (remoteTranscriptionConfigUrl != null && tenant != null) { - String transcriberClass = null; - try + String tsConfigUrl = remoteTranscriptionConfigUrl + "/" + tenant; + transcriberClass = getTranscriberFromRemote(tsConfigUrl); + } + + if (transcriberClass == null) + { + transcriberClass + = JigasiBundleActivator.getConfigurationService() + .getString( + CUSTOM_TRANSCRIPTION_SERVICE_PROP, + null); + } + return transcriberClass; + } + + private String getTranscriberFromRemote(String remoteTsConfigUrl) + { + String transcriberClass = null; + if (logger.isDebugEnabled()) + { + logger.debug("Calling " + remoteTsConfigUrl + " to retrieve transcriber."); + } + try + { + URL url = new URL(remoteTsConfigUrl); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.setRequestProperty("Content-Type", "application/json"); + conn.setConnectTimeout(3000); + int responseCode = conn.getResponseCode(); + if (responseCode == 200) { - URL url = new URL(remoteTranscriptionConfigUrl + "/" + tenant); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("GET"); - conn.setRequestProperty("Content-Type", "application/json"); - int responseCode = conn.getResponseCode(); - if (responseCode == 200) + BufferedReader inputStream = new BufferedReader( + new InputStreamReader(conn.getInputStream())); + String inputLine; + StringBuilder responseBody = new StringBuilder(); + while ((inputLine = inputStream.readLine()) != null) { - BufferedReader inputStream = new BufferedReader( - new InputStreamReader(conn.getInputStream())); - String inputLine; - StringBuilder responseBody = new StringBuilder(); - while ((inputLine = inputStream.readLine()) != null) - { - responseBody.append(inputLine); - } - inputStream.close(); - if (logger.isDebugEnabled()) - { - logger.debug("Received body " + responseBody); - } - JSONObject obj = new JSONObject(responseBody.toString()); - transcriberClass = obj.getString("transcriber"); - if (logger.isDebugEnabled()) - { - logger.debug("Using " + transcriberClass + " as the transcriber class."); - } + responseBody.append(inputLine); } - conn.disconnect(); - return transcriberClass; - } - catch (Exception ex) - { - logger.error("Could not retrieve transcriber from remote URL." + ex); + inputStream.close(); + JSONObject obj = new JSONObject(responseBody.toString()); + transcriberClass = obj.getString("transcriber"); } + conn.disconnect(); } - - return JigasiBundleActivator.getConfigurationService() - .getString( - CUSTOM_TRANSCRIPTION_SERVICE_PROP, - null); + catch (Exception ex) + { + logger.error("Could not retrieve transcriber from remote URL." + ex); + } + return transcriberClass; } @Override