From 44c814256d61615dca5626ac186d1eb6166ef2ae Mon Sep 17 00:00:00 2001 From: rubenlagus Date: Tue, 10 Sep 2019 23:44:28 +0100 Subject: [PATCH] Bug fixes and pom dependencies upgrades --- Bots.ipr | 367 +++++++++--------- pom.xml | 10 +- telegrambots-meta/pom.xml | 4 +- .../meta/api/objects/ChatPermissions.java | 32 ++ telegrambots-spring-boot-starter/pom.xml | 4 +- telegrambots/pom.xml | 8 +- .../telegrambots/bots/DefaultAbsSender.java | 15 +- .../facilities/TelegramHttpClientBuilder.java | 3 +- .../updatesreceivers/DefaultBotSession.java | 23 +- .../telegrambots/util/WebhookUtils.java | 24 +- 10 files changed, 268 insertions(+), 222 deletions(-) diff --git a/Bots.ipr b/Bots.ipr index 48a1815b..3cba11c9 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -22,10 +22,10 @@ - - - + + + @@ -920,26 +920,15 @@ - + - + - + - - - - - - - - - - - - + @@ -1008,15 +997,15 @@ - + - + - + - + @@ -1129,37 +1118,48 @@ - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + @@ -1184,17 +1184,6 @@ - - - - - - - - - - - @@ -1250,37 +1239,37 @@ - + - + - + - + - + - + - + - + - + - + - + - + @@ -1415,15 +1404,15 @@ - + - + - + - + @@ -1437,15 +1426,15 @@ - + - + - + - + @@ -1525,59 +1514,59 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1591,147 +1580,147 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1800,48 +1789,48 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1921,103 +1910,103 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/pom.xml b/pom.xml index 5498fb4d..df092cfe 100644 --- a/pom.xml +++ b/pom.xml @@ -67,12 +67,13 @@ ${java.version} ${java.version} - 5.5.1 + 5.5.2 3.0.0 3.0.0 2.9.9 - 2.9.9.1 + 2.9.9.2 1.7.28 + 1.3.5 @@ -115,6 +116,11 @@ slf4j-api ${slf4j.version} + + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation.version} + diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 78b37e06..e60b3e72 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -70,10 +70,10 @@ UTF-8 UTF-8 4.2.2 - 2.9.9 + 2.9.9.2 2.9.9 20180813 - 28.0-jre + 28.1-jre diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java index 7a42bd41..97c48de7 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatPermissions.java @@ -73,6 +73,38 @@ public class ChatPermissions implements BotApiObject { return canPinMessages; } + public void setCanSendMessages(Boolean canSendMessages) { + this.canSendMessages = canSendMessages; + } + + public void setGetCanSendMediaMessages(Boolean getCanSendMediaMessages) { + this.getCanSendMediaMessages = getCanSendMediaMessages; + } + + public void setCanSendPolls(Boolean canSendPolls) { + this.canSendPolls = canSendPolls; + } + + public void setCanSendOtherMessages(Boolean canSendOtherMessages) { + this.canSendOtherMessages = canSendOtherMessages; + } + + public void setCanAddWebPagePreviews(Boolean canAddWebPagePreviews) { + this.canAddWebPagePreviews = canAddWebPagePreviews; + } + + public void setCanChangeInfo(Boolean canChangeInfo) { + this.canChangeInfo = canChangeInfo; + } + + public void setCanInviteUsers(Boolean canInviteUsers) { + this.canInviteUsers = canInviteUsers; + } + + public void setCanPinMessages(Boolean canPinMessages) { + this.canPinMessages = canPinMessages; + } + @Override public String toString() { return "ChatPermissions{" + diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index f2a6a2b9..0ba8111f 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -70,7 +70,7 @@ UTF-8 UTF-8 - 2.1.6.RELEASE + 2.1.8.RELEASE @@ -103,7 +103,7 @@ org.assertj assertj-core test - 3.13.1 + 3.13.2 diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index cb8e45ef..113bc407 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -70,11 +70,11 @@ UTF-8 UTF-8 - 2.29 + 2.29.1 1.19.3 - 4.5.9 + 4.5.10 20180813 - 2.9.9 + 2.9.9.2 2.9.9 2.6 @@ -105,7 +105,7 @@ com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - ${jackson.version} + ${jacksonbase.version} com.fasterxml.jackson.module diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java index b94d3a09..71c6d4ed 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java @@ -6,7 +6,6 @@ import org.apache.http.HttpEntity; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -16,7 +15,15 @@ import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.telegram.telegrambots.facilities.filedownloader.TelegramFileDownloader; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatPhoto; -import org.telegram.telegrambots.meta.api.methods.send.*; +import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; +import org.telegram.telegrambots.meta.api.methods.send.SendAudio; +import org.telegram.telegrambots.meta.api.methods.send.SendDocument; +import org.telegram.telegrambots.meta.api.methods.send.SendMediaGroup; +import org.telegram.telegrambots.meta.api.methods.send.SendPhoto; +import org.telegram.telegrambots.meta.api.methods.send.SendSticker; +import org.telegram.telegrambots.meta.api.methods.send.SendVideo; +import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote; +import org.telegram.telegrambots.meta.api.methods.send.SendVoice; import org.telegram.telegrambots.meta.api.methods.stickers.AddStickerToSet; import org.telegram.telegrambots.meta.api.methods.stickers.CreateNewStickerSet; import org.telegram.telegrambots.meta.api.methods.stickers.UploadStickerFile; @@ -729,9 +736,7 @@ public abstract class DefaultAbsSender extends AbsSender { private String sendHttpPostRequest(HttpPost httppost) throws IOException { try (CloseableHttpResponse response = httpClient.execute(httppost, options.getHttpContext())) { - HttpEntity ht = response.getEntity(); - BufferedHttpEntity buf = new BufferedHttpEntity(ht); - return EntityUtils.toString(buf, StandardCharsets.UTF_8); + return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); } } diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java index 38a3a17a..3993fc79 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/TelegramHttpClientBuilder.java @@ -45,7 +45,8 @@ public class TelegramHttpClientBuilder { case SOCKS5: registry = RegistryBuilder. create() .register("http", new SocksConnectionSocketFactory()) - .register("https", new SocksSSLConnectionSocketFactory(SSLContexts.createSystemDefault())).build(); + .register("https", new SocksSSLConnectionSocketFactory(SSLContexts.createSystemDefault())) + .build(); return new PoolingHttpClientConnectionManager(registry); } return null; diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java index 78a84d8d..0f9f6334 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java @@ -2,25 +2,27 @@ package org.telegram.telegrambots.updatesreceivers; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Inject; -import org.apache.http.HttpEntity; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONException; +import org.telegram.telegrambots.bots.DefaultBotOptions; +import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.telegram.telegrambots.meta.ApiConstants; import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates; import org.telegram.telegrambots.meta.api.objects.Update; -import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; -import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; -import org.telegram.telegrambots.meta.generics.*; +import org.telegram.telegrambots.meta.generics.BotOptions; +import org.telegram.telegrambots.meta.generics.BotSession; +import org.telegram.telegrambots.meta.generics.LongPollingBot; +import org.telegram.telegrambots.meta.generics.UpdatesHandler; +import org.telegram.telegrambots.meta.generics.UpdatesReader; import java.io.IOException; import java.io.InvalidObjectException; @@ -28,7 +30,11 @@ import java.net.SocketException; import java.net.SocketTimeoutException; import java.nio.charset.StandardCharsets; import java.security.InvalidParameterException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicBoolean; @@ -132,6 +138,7 @@ public class DefaultBotSession implements BotSession { return running.get(); } + @SuppressWarnings("WeakerAccess") private class ReaderThread extends Thread implements UpdatesReader { private final UpdatesSupplier updatesSupplier; @@ -244,9 +251,7 @@ public class DefaultBotSession implements BotSession { httpPost.setEntity(new StringEntity(objectMapper.writeValueAsString(request), ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = httpclient.execute(httpPost, options.getHttpContext())) { - HttpEntity ht = response.getEntity(); - BufferedHttpEntity buf = new BufferedHttpEntity(ht); - String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8); + String responseContent = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); if (response.getStatusLine().getStatusCode() >= 500) { log.warn(responseContent); diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java b/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java index a294738d..5210cd6c 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/util/WebhookUtils.java @@ -1,9 +1,9 @@ package org.telegram.telegrambots.util; import org.apache.http.HttpEntity; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; @@ -11,19 +11,21 @@ import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.telegram.telegrambots.meta.ApiConstants; -import org.telegram.telegrambots.meta.api.methods.updates.DeleteWebhook; import org.telegram.telegrambots.bots.DefaultAbsSender; import org.telegram.telegrambots.bots.DefaultBotOptions; -import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.facilities.TelegramHttpClientBuilder; +import org.telegram.telegrambots.meta.ApiConstants; +import org.telegram.telegrambots.meta.api.methods.updates.DeleteWebhook; import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook; +import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT; + public final class WebhookUtils { private WebhookUtils() { @@ -35,8 +37,16 @@ public final class WebhookUtils { try (CloseableHttpClient httpclient = TelegramHttpClientBuilder.build(botOptions)) { String requestUrl = bot.getBaseUrl() + SetWebhook.PATH; + RequestConfig requestConfig = botOptions.getRequestConfig(); + if (requestConfig == null) { + requestConfig = RequestConfig.copy(RequestConfig.custom().build()) + .setSocketTimeout(SOCKET_TIMEOUT) + .setConnectTimeout(SOCKET_TIMEOUT) + .setConnectionRequestTimeout(SOCKET_TIMEOUT).build(); + } + HttpPost httppost = new HttpPost(requestUrl); - httppost.setConfig(botOptions.getRequestConfig()); + httppost.setConfig(requestConfig); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SetWebhook.URL_FIELD, url); if (botOptions.getMaxWebhookConnections() != null) { @@ -54,9 +64,7 @@ public final class WebhookUtils { HttpEntity multipart = builder.build(); httppost.setEntity(multipart); try (CloseableHttpResponse response = httpclient.execute(httppost, botOptions.getHttpContext())) { - HttpEntity ht = response.getEntity(); - BufferedHttpEntity buf = new BufferedHttpEntity(ht); - String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8); + String responseContent = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); JSONObject jsonObject = new JSONObject(responseContent); if (!jsonObject.getBoolean(ApiConstants.RESPONSE_FIELD_OK)) { throw new TelegramApiRequestException("Error setting webhook", jsonObject);