From 1c66511bff9519439b73a0df519119707d4855d8 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Sun, 17 Apr 2016 17:10:09 +0200 Subject: [PATCH] Add compatibility with java7 Merge #21 --- .../telegram/telegrambots/bots/AbsSender.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) 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); + } }); }