diff --git a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index 8cea4a35..4373745e 100644 --- a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -781,25 +781,29 @@ public abstract class AbsSender { // Simplified methods private void sendApiMethodAsync(BotApiMethod method, SentCallback callback) { - exe.submit(() -> { - try { - CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); - String url = getBaseUrl() + method.getPath(); - HttpPost httppost = new HttpPost(url); - httppost.addHeader("charset", StandardCharsets.UTF_8.name()); - httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); - CloseableHttpResponse response = httpclient.execute(httppost); - HttpEntity ht = response.getEntity(); - BufferedHttpEntity buf = new BufferedHttpEntity(ht); - String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8); + exe.submit(new Runnable() { + @Override + public void run() { + try { + CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); + String url = getBaseUrl() + method.getPath(); + HttpPost httppost = new HttpPost(url); + httppost.addHeader("charset", StandardCharsets.UTF_8.name()); + httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); + CloseableHttpResponse response = httpclient.execute(httppost); + HttpEntity ht = response.getEntity(); + BufferedHttpEntity buf = new BufferedHttpEntity(ht); + String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8); - JSONObject jsonObject = new JSONObject(responseContent); - if (!jsonObject.getBoolean(Constants.RESPONSEFIELDOK)) { - callback.onError(method, jsonObject); + JSONObject jsonObject = new JSONObject(responseContent); + if (!jsonObject.getBoolean(Constants.RESPONSEFIELDOK)) { + callback.onError(method, jsonObject); + } + callback.onResult(method, jsonObject); + } catch (IOException e) { + callback.onException(method, e); } - callback.onResult(method, jsonObject); - } catch (IOException e) { - callback.onException(method, e); + } }); }