diff --git a/.github/workflows/portainer-deploy.yml b/.github/workflows/portainer-deploy.yml
index cf08c96..3fa34f5 100644
--- a/.github/workflows/portainer-deploy.yml
+++ b/.github/workflows/portainer-deploy.yml
@@ -5,6 +5,8 @@ on:
branches:
- main
- master
+ tags:
+ - '**'
pull_request:
branches:
- '**'
@@ -13,7 +15,6 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: mrmigles/pakhombot
- TAG: latest
jobs:
pr-docker-build:
@@ -21,16 +22,31 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
+ packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- - name: Build Docker image (no push)
+ - name: Log in to GitHub Container Registry
+ uses: docker/login-action@v3
+ with:
+ registry: ${{ env.REGISTRY }}
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Determine image tag
+ run: |
+ TAG="${GITHUB_HEAD_REF}"
+ TAG="${TAG//\//_}"
+ TAG="${TAG//\\/_}"
+ echo "TAG=$TAG" >> "$GITHUB_ENV"
+
+ - name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
- push: false
- tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
+ push: true
+ tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
build-and-deploy:
if: github.event_name != 'pull_request'
@@ -63,6 +79,20 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
+ - name: Determine image tag
+ run: |
+ REF="${GITHUB_REF}"
+ if [[ "$REF" == refs/tags/* ]]; then
+ TAG="${REF#refs/tags/}"
+ elif [[ "$REF" == refs/heads/main || "$REF" == refs/heads/master ]]; then
+ TAG="latest"
+ else
+ TAG="${REF#refs/heads/}"
+ TAG="${TAG//\//_}"
+ TAG="${TAG//\\/_}"
+ fi
+ echo "TAG=$TAG" >> "$GITHUB_ENV"
+
- name: Build and push image
uses: docker/build-push-action@v6
with:
diff --git a/pom.xml b/pom.xml
index 706258b..cdc27a0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,14 +14,14 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.2.RELEASE
+ 3.4.4
UTF-8
UTF-8
21
- 4.0.20
+ 4.0.24
@@ -59,6 +59,18 @@
org.springframework.boot
spring-boot-starter
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+
+
+ org.springframework.boot
+ spring-boot-starter-data-mongodb
+
org.springframework.boot
@@ -71,10 +83,18 @@
5.14.0
test
+
- org.springframework.boot
- spring-boot-starter-data-mongodb
+ org.telegram
+ telegrambots
+ 6.9.7.1
+
+ org.telegram
+ telegrambotsextensions
+ 6.9.7.1
+
+
ru.stachek66.nlp
mystem-scala
@@ -90,30 +110,11 @@
skype4j
0.1.5
-
- commons-lang
- commons-lang
- 2.3
-
-
- org.telegram
- telegrambots
- 6.5.0
-
-
- org.telegram
- telegrambotsextensions
- 6.5.0
-
-
- com.sun.jersey
- jersey-bundle
- 1.10-b01
-
+
org.json
json
- 20140107
+ 20240303
org.hsqldb
@@ -123,7 +124,6 @@
com.google.code.gson
gson
- 2.8.0
ai.api
@@ -131,47 +131,28 @@
1.4.8
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- org.springframework.security.oauth
- spring-security-oauth2
- 2.2.4.RELEASE
-
-
- org.springframework
- spring-web
- 4.3.4.RELEASE
-
-
org.apache.commons
commons-lang3
- 3.4
-
com.jayway.jsonpath
json-path
- 2.8.0
- org.apache.httpcomponents
- httpcore
- 4.4.7
+ org.apache.httpcomponents.client5
+ httpclient5
+
org.springframework.retry
spring-retry
- 1.2.2.RELEASE
com.google.code.findbugs
jsr305
- 2.0.1
+ 3.0.2
commons-collections
@@ -181,7 +162,6 @@
org.projectlombok
lombok
- 1.18.36
org.apache.groovy
@@ -191,17 +171,16 @@
net.minidev
json-smart
- 2.4.11
org.jsoup
jsoup
- 1.15.1
+ 1.18.3
us.codecraft
xsoup
- 0.3.2
+ 0.3.7
cglib
diff --git a/src/main/java/ru/holyway/botplatform/BotPlatformApplication.java b/src/main/java/ru/holyway/botplatform/BotPlatformApplication.java
index 12a5616..c5f07da 100644
--- a/src/main/java/ru/holyway/botplatform/BotPlatformApplication.java
+++ b/src/main/java/ru/holyway/botplatform/BotPlatformApplication.java
@@ -6,17 +6,14 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import ru.holyway.botplatform.core.Bot;
-import javax.annotation.PostConstruct;
+import jakarta.annotation.PostConstruct;
-@EnableWebSecurity
-@EnableGlobalMethodSecurity(prePostEnabled = true)
+@EnableMethodSecurity
@EnableCaching
-@SpringBootApplication
-@EnableAutoConfiguration(exclude = {GroovyTemplateAutoConfiguration.class})
+@SpringBootApplication(exclude = {GroovyTemplateAutoConfiguration.class})
public class BotPlatformApplication {
private final Bot bots;
diff --git a/src/main/java/ru/holyway/botplatform/config/BotConfiguration.java b/src/main/java/ru/holyway/botplatform/config/BotConfiguration.java
index 6b0577d..e002636 100644
--- a/src/main/java/ru/holyway/botplatform/config/BotConfiguration.java
+++ b/src/main/java/ru/holyway/botplatform/config/BotConfiguration.java
@@ -1,13 +1,14 @@
package ru.holyway.botplatform.config;
import org.apache.commons.lang3.StringUtils;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.conn.ssl.TrustStrategy;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
+import org.apache.hc.core5.ssl.SSLContexts;
+import org.apache.hc.core5.ssl.TrustStrategy;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@@ -19,6 +20,7 @@
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.DefaultUriBuilderFactory;
import ru.holyway.botplatform.core.Bot;
import ru.holyway.botplatform.core.CommonHandler;
import ru.holyway.botplatform.core.CommonMessageHandler;
@@ -41,9 +43,6 @@
import java.util.List;
import java.util.Map;
-/**
- * Created by Sergey on 1/17/2017.
- */
@Configuration
public class BotConfiguration {
@@ -104,12 +103,6 @@ public List orderedMessageHandlers(
final Map messageHandlers) {
final List orderedMessageHandlers = new ArrayList<>();
orderedMessageHandlers.add(messageHandlers.get("settingsHandler"));
- //orderedMessageHandlers.add(messageHandlers.get("authenticationHandler"));
- //orderedMessageHandlers.add(messageHandlers.get("skiperHandler"));
- //orderedMessageHandlers.add(messageHandlers.get("messageAnalyzerHandler"));
- //orderedMessageHandlers.add(messageHandlers.get("recordsHandler"));
- //orderedMessageHandlers.add(messageHandlers.get("wikiHandler"));
- //orderedMessageHandlers.add(messageHandlers.get("simpleQuestionHandler"));
return orderedMessageHandlers;
}
@@ -136,19 +129,20 @@ private HttpComponentsClientHttpRequestFactory buildRequestFactory()
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
- SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
+ SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
- SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
-
CloseableHttpClient httpClient = HttpClients.custom()
- .setSSLSocketFactory(csf)
+ .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()
+ .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
+ .setSslContext(sslContext)
+ .build())
+ .build())
.build();
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();
-
requestFactory.setHttpClient(httpClient);
return requestFactory;
}
@@ -157,8 +151,9 @@ private HttpComponentsClientHttpRequestFactory buildRequestFactory()
public RestTemplate instaproviderTemplate()
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
HttpComponentsClientHttpRequestFactory requestFactory = buildRequestFactory();
- return new RestTemplateBuilder().requestFactory(requestFactory).rootUri(instaproviderUrl)
- .build();
+ RestTemplate template = new RestTemplate(requestFactory);
+ template.setUriTemplateHandler(new DefaultUriBuilderFactory(instaproviderUrl));
+ return template;
}
private void setProxy(final String host, final String port, final String user,
@@ -187,28 +182,6 @@ protected PasswordAuthentication getPasswordAuthentication() {
}
}
-// @Bean
-// public DefaultBotOptions botOptions() {
-// if (!org.apache.commons.lang3.StringUtils
-// .isEmpty(proxyUser) && !org.apache.commons.lang3.StringUtils.isEmpty(proxyPass)) {
-// Authenticator.setDefault(new Authenticator() {
-// @Override
-// protected PasswordAuthentication getPasswordAuthentication() {
-// return new PasswordAuthentication(proxyUser, proxyPass.toCharArray());
-// }
-// });
-// }
-//
-// DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
-//
-// if (!StringUtils.isEmpty(proxyHost) && !StringUtils.isEmpty(proxyPort)) {
-// botOptions.setProxyHost(proxyHost);
-// botOptions.setProxyPort(Integer.valueOf(proxyPort));
-// botOptions.setProxyType(DefaultBotOptions.ProxyType.SOCKS5);
-// }
-// return botOptions;
-// }
-
@Bean
public RetryTemplate retryTemplate() {
RetryTemplate retryTemplate = new RetryTemplate();
diff --git a/src/main/java/ru/holyway/botplatform/config/GroovyConfiguration.java b/src/main/java/ru/holyway/botplatform/config/GroovyConfiguration.java
index 815cde1..d57a828 100644
--- a/src/main/java/ru/holyway/botplatform/config/GroovyConfiguration.java
+++ b/src/main/java/ru/holyway/botplatform/config/GroovyConfiguration.java
@@ -13,7 +13,7 @@
import ru.holyway.botplatform.scripting.entity.*;
import ru.holyway.botplatform.scripting.util.*;
-import javax.annotation.Nonnull;
+import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
diff --git a/src/main/java/ru/holyway/botplatform/config/RequestFactory.java b/src/main/java/ru/holyway/botplatform/config/RequestFactory.java
index e24d949..bc2d2e2 100644
--- a/src/main/java/ru/holyway/botplatform/config/RequestFactory.java
+++ b/src/main/java/ru/holyway/botplatform/config/RequestFactory.java
@@ -1,13 +1,13 @@
package ru.holyway.botplatform.config;
-import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
-import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
-import javax.annotation.PostConstruct;
+import jakarta.annotation.PostConstruct;
import java.net.URI;
@Component
@@ -22,7 +22,7 @@ public void init() {
public static final class HttpComponentsClientHttpRequestWithBodyFactory extends
HttpComponentsClientHttpRequestFactory {
@Override
- protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
+ protected ClassicHttpRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
if (httpMethod == HttpMethod.GET) {
return new HttpGetRequestWithEntity(uri);
}
@@ -30,9 +30,9 @@ protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
}
}
- private static final class HttpGetRequestWithEntity extends HttpEntityEnclosingRequestBase {
+ private static final class HttpGetRequestWithEntity extends HttpUriRequestBase {
public HttpGetRequestWithEntity(final URI uri) {
- super.setURI(uri);
+ super("GET", uri);
}
@Override
diff --git a/src/main/java/ru/holyway/botplatform/config/SecurityConfiguration.java b/src/main/java/ru/holyway/botplatform/config/SecurityConfiguration.java
index 724800b..ae392ac 100644
--- a/src/main/java/ru/holyway/botplatform/config/SecurityConfiguration.java
+++ b/src/main/java/ru/holyway/botplatform/config/SecurityConfiguration.java
@@ -1,34 +1,30 @@
package ru.holyway.botplatform.config;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.builders.WebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
+import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
-/**
- * Created by seiv0814 on 07-11-17.
- */
@Configuration
-public class SecurityConfiguration extends
- WebSecurityConfigurerAdapter {
+@EnableWebSecurity
+public class SecurityConfiguration {
@Autowired
private AnonymousAuthenticationFilter anonymousAuthenticationFilter;
- @Override
- public void configure(WebSecurity web) throws Exception {
- web
- .ignoring()
- .antMatchers("/resources/**"); // #3
+ @Bean
+ public WebSecurityCustomizer webSecurityCustomizer() {
+ return web -> web.ignoring().requestMatchers("/resources/**");
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
-
- http.csrf().disable();
-
- http.anonymous().authenticationFilter(anonymousAuthenticationFilter);
+ @Bean
+ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
+ http.csrf(csrf -> csrf.disable())
+ .anonymous(anon -> anon.authenticationFilter(anonymousAuthenticationFilter));
+ return http.build();
}
}
diff --git a/src/main/java/ru/holyway/botplatform/core/CommonMessageHandler.java b/src/main/java/ru/holyway/botplatform/core/CommonMessageHandler.java
index 5ea5b50..b82da4c 100644
--- a/src/main/java/ru/holyway/botplatform/core/CommonMessageHandler.java
+++ b/src/main/java/ru/holyway/botplatform/core/CommonMessageHandler.java
@@ -8,7 +8,7 @@
import org.springframework.beans.factory.annotation.Value;
import ru.holyway.botplatform.core.handler.MessageHandler;
-import javax.annotation.PostConstruct;
+import jakarta.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.TimeUnit;
diff --git a/src/main/java/ru/holyway/botplatform/core/data/ChatMemberRepository.java b/src/main/java/ru/holyway/botplatform/core/data/ChatMemberRepository.java
index 76a2165..14ee07b 100644
--- a/src/main/java/ru/holyway/botplatform/core/data/ChatMemberRepository.java
+++ b/src/main/java/ru/holyway/botplatform/core/data/ChatMemberRepository.java
@@ -5,5 +5,4 @@
public interface ChatMemberRepository extends MongoRepository {
- public ChatMembers findById(String id);
}
diff --git a/src/main/java/ru/holyway/botplatform/core/data/ChatRepository.java b/src/main/java/ru/holyway/botplatform/core/data/ChatRepository.java
index e15d166..7e17d19 100644
--- a/src/main/java/ru/holyway/botplatform/core/data/ChatRepository.java
+++ b/src/main/java/ru/holyway/botplatform/core/data/ChatRepository.java
@@ -3,10 +3,6 @@
import org.springframework.data.mongodb.repository.MongoRepository;
import ru.holyway.botplatform.core.entity.Chat;
-/**
- * Created by Sergey on 4/24/2017.
- */
public interface ChatRepository extends MongoRepository {
- public Chat findById(String id);
}
diff --git a/src/main/java/ru/holyway/botplatform/core/data/MongoDataHelper.java b/src/main/java/ru/holyway/botplatform/core/data/MongoDataHelper.java
index 034a8c0..23ef9e3 100644
--- a/src/main/java/ru/holyway/botplatform/core/data/MongoDataHelper.java
+++ b/src/main/java/ru/holyway/botplatform/core/data/MongoDataHelper.java
@@ -7,7 +7,7 @@
import ru.holyway.botplatform.core.entity.JSettings;
import ru.holyway.botplatform.core.entity.Record;
-import javax.annotation.PostConstruct;
+import jakarta.annotation.PostConstruct;
import java.util.*;
/**
@@ -54,12 +54,12 @@ public void updateLearn(Map> learnMap) {
for (Map.Entry> entry : learnMap.entrySet()) {
chats.add(new Chat(entry.getKey(), entry.getValue()));
}
- repository.save(chats);
+ repository.saveAll(chats);
}
public List getSimple() {
try {
- return simpleRepository.findOne("1").dictionary;
+ return simpleRepository.findById("1").map(s -> s.dictionary).orElse(new ArrayList<>());
} catch (Exception e) {
return new ArrayList<>();
}
@@ -67,7 +67,7 @@ public List getSimple() {
public JSettings getSettings() {
if (this.settings == null) {
- JSettings settings = settingsRepository.findOne("1");
+ JSettings settings = settingsRepository.findById("1").orElse(null);
if (settings == null) {
settings = new JSettings();
settings.id = "1";
@@ -88,12 +88,12 @@ public List getRecords() {
}
public void updateRecords(List records) {
- recordRepository.save(records);
+ recordRepository.saveAll(records);
}
@Override
public List getChatMembers(String chatId) {
- ChatMembers chatMembers = chatMemberRepository.findById(chatId);
+ ChatMembers chatMembers = chatMemberRepository.findById(chatId).orElse(null);
if (chatMembers != null) {
return chatMembers.members;
}
diff --git a/src/main/java/ru/holyway/botplatform/core/education/EducationCache.java b/src/main/java/ru/holyway/botplatform/core/education/EducationCache.java
index 60caa9b..5cc4317 100644
--- a/src/main/java/ru/holyway/botplatform/core/education/EducationCache.java
+++ b/src/main/java/ru/holyway/botplatform/core/education/EducationCache.java
@@ -6,7 +6,7 @@
import org.springframework.stereotype.Component;
import ru.holyway.botplatform.core.data.DataHelper;
-import javax.annotation.PostConstruct;
+import jakarta.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
diff --git a/src/main/java/ru/holyway/botplatform/core/handler/SettingsHandler.java b/src/main/java/ru/holyway/botplatform/core/handler/SettingsHandler.java
index 4b86ca0..8feac15 100644
--- a/src/main/java/ru/holyway/botplatform/core/handler/SettingsHandler.java
+++ b/src/main/java/ru/holyway/botplatform/core/handler/SettingsHandler.java
@@ -9,7 +9,7 @@
import ru.holyway.botplatform.scripting.MetricCollector;
import ru.holyway.botplatform.telegram.TelegramMessageEntity;
-import javax.annotation.PostConstruct;
+import jakarta.annotation.PostConstruct;
/**
* Created by seiv0814 on 10-10-17.
diff --git a/src/main/java/ru/holyway/botplatform/scripting/MethodsBlacklistExpressionChecker.java b/src/main/java/ru/holyway/botplatform/scripting/MethodsBlacklistExpressionChecker.java
index 134acbb..e889e49 100644
--- a/src/main/java/ru/holyway/botplatform/scripting/MethodsBlacklistExpressionChecker.java
+++ b/src/main/java/ru/holyway/botplatform/scripting/MethodsBlacklistExpressionChecker.java
@@ -5,7 +5,7 @@
import org.codehaus.groovy.ast.expr.MethodCallExpression;
import org.codehaus.groovy.control.customizers.SecureASTCustomizer;
-import javax.annotation.Nonnull;
+import jakarta.annotation.Nonnull;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
diff --git a/src/main/java/ru/holyway/botplatform/scripting/ScriptCompiler.java b/src/main/java/ru/holyway/botplatform/scripting/ScriptCompiler.java
index 6c39fdb..6fcc0a6 100644
--- a/src/main/java/ru/holyway/botplatform/scripting/ScriptCompiler.java
+++ b/src/main/java/ru/holyway/botplatform/scripting/ScriptCompiler.java
@@ -1,6 +1,6 @@
package ru.holyway.botplatform.scripting;
-import javax.annotation.Nonnull;
+import jakarta.annotation.Nonnull;
public interface ScriptCompiler {
diff --git a/src/main/java/ru/holyway/botplatform/scripting/ScriptCompilerImpl.java b/src/main/java/ru/holyway/botplatform/scripting/ScriptCompilerImpl.java
index cd2497a..d3b76da 100644
--- a/src/main/java/ru/holyway/botplatform/scripting/ScriptCompilerImpl.java
+++ b/src/main/java/ru/holyway/botplatform/scripting/ScriptCompilerImpl.java
@@ -3,7 +3,7 @@
import groovy.lang.GroovyShell;
import lombok.RequiredArgsConstructor;
-import javax.annotation.Nonnull;
+import jakarta.annotation.Nonnull;
@RequiredArgsConstructor
public class ScriptCompilerImpl implements ScriptCompiler {
diff --git a/src/main/java/ru/holyway/botplatform/scripting/entity/CallbackScriptEntity.java b/src/main/java/ru/holyway/botplatform/scripting/entity/CallbackScriptEntity.java
index 4636bce..8a38e3c 100644
--- a/src/main/java/ru/holyway/botplatform/scripting/entity/CallbackScriptEntity.java
+++ b/src/main/java/ru/holyway/botplatform/scripting/entity/CallbackScriptEntity.java
@@ -18,7 +18,7 @@ public MessageScriptEntity getMessage() {
return new MessageScriptEntity() {
@Override
public Function entity() {
- return scriptContext -> scriptContext.message.messageEntity.getCallbackQuery().getMessage();
+ return scriptContext -> (Message) scriptContext.message.messageEntity.getCallbackQuery().getMessage();
}
};
}
diff --git a/src/main/java/ru/holyway/botplatform/scripting/util/Request.java b/src/main/java/ru/holyway/botplatform/scripting/util/Request.java
index 2be7c9d..8daa1b7 100644
--- a/src/main/java/ru/holyway/botplatform/scripting/util/Request.java
+++ b/src/main/java/ru/holyway/botplatform/scripting/util/Request.java
@@ -1,19 +1,19 @@
package ru.holyway.botplatform.scripting.util;
import com.jayway.jsonpath.JsonPath;
-import org.apache.http.client.HttpClient;
-import org.apache.http.conn.ssl.NoopHostnameVerifier;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.ssl.SSLContexts;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
+import org.apache.hc.core5.ssl.SSLContexts;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -39,22 +39,41 @@
public class Request {
- private static RestTemplate restTemplate = new RestTemplateBuilder().setReadTimeout(5 * 60 * 1000).setConnectTimeout(5 * 60 * 1000).build();
+ private static RestTemplate restTemplate;
private static final Logger LOGGER = LoggerFactory.getLogger(Request.class);
static {
- SSLContext sslContext = SSLContexts.createDefault();
-
- SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}, null, new NoopHostnameVerifier());
-
- HttpClient httpClient = HttpClientBuilder.create().disableCookieManagement().useSystemProperties().setSSLSocketFactory(sslsf).build();
- HttpComponentsClientHttpRequestWithBodyFactory factory = new HttpComponentsClientHttpRequestWithBodyFactory();
- factory.setHttpClient(httpClient);
- restTemplate.setRequestFactory(factory);
-
- restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
-
+ try {
+ SSLContext sslContext = SSLContexts.createDefault();
+
+ var connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
+ .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
+ .setSslContext(sslContext)
+ .setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
+ .setTlsVersions("TLSv1.2", "TLSv1.3")
+ .build())
+ .build();
+
+ var httpClient = HttpClientBuilder.create()
+ .disableCookieManagement()
+ .useSystemProperties()
+ .setConnectionManager(connectionManager)
+ .build();
+
+ HttpComponentsClientHttpRequestWithBodyFactory factory =
+ new HttpComponentsClientHttpRequestWithBodyFactory();
+ factory.setHttpClient(httpClient);
+ factory.setConnectTimeout(5 * 60 * 1000);
+
+ restTemplate = new RestTemplate();
+ restTemplate.setRequestFactory(factory);
+ restTemplate.getMessageConverters().add(0,
+ new StringHttpMessageConverter(StandardCharsets.UTF_8));
+ } catch (Exception e) {
+ LOGGER.error("Failed to initialize Request RestTemplate", e);
+ restTemplate = new RestTemplate();
+ }
}
private Map params = new HashMap<>();
@@ -156,7 +175,7 @@ private Function performRequest() {
if (!this.params.isEmpty()) {
headers.add("Content-Type", "application/x-www-form-urlencoded");
}
- if (StringUtils.isEmpty(body)) {
+ if (!StringUtils.hasText(body)) {
if (params == null || params.isEmpty()) {
httpEntity = new HttpEntity(headers);
} else {
diff --git a/src/main/java/ru/holyway/botplatform/security/AnonymousChatTokenSecurityFilter.java b/src/main/java/ru/holyway/botplatform/security/AnonymousChatTokenSecurityFilter.java
index 401a2a0..30efe63 100644
--- a/src/main/java/ru/holyway/botplatform/security/AnonymousChatTokenSecurityFilter.java
+++ b/src/main/java/ru/holyway/botplatform/security/AnonymousChatTokenSecurityFilter.java
@@ -8,7 +8,7 @@
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
import ru.holyway.botplatform.core.data.DataHelper;
-import javax.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletRequest;
import java.util.Collections;
public class AnonymousChatTokenSecurityFilter extends AnonymousAuthenticationFilter {
diff --git a/src/main/java/ru/holyway/botplatform/telegram/TelegramBot.java b/src/main/java/ru/holyway/botplatform/telegram/TelegramBot.java
index b7df9e9..378d76c 100644
--- a/src/main/java/ru/holyway/botplatform/telegram/TelegramBot.java
+++ b/src/main/java/ru/holyway/botplatform/telegram/TelegramBot.java
@@ -19,7 +19,7 @@
import ru.holyway.botplatform.telegram.processor.MessagePostLoader;
import ru.holyway.botplatform.telegram.processor.MessageProcessor;
-import javax.annotation.PostConstruct;
+import jakarta.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
@@ -86,7 +86,7 @@ public void onUpdateReceived(Update update) {
Message message = update.hasChannelPost() ? update.getChannelPost() : update.getMessage();
if (message == null) {
if (update.hasCallbackQuery()) {
- message = update.getCallbackQuery().getMessage();
+ message = (Message) update.getCallbackQuery().getMessage();
} else if (update.hasInlineQuery()) {
try {
inlineQueryBlockingQueue.put(update.getInlineQuery());
diff --git a/src/main/java/ru/holyway/botplatform/telegram/processor/RandomMemeProcessor.java b/src/main/java/ru/holyway/botplatform/telegram/processor/RandomMemeProcessor.java
index dbee2c0..a70627b 100644
--- a/src/main/java/ru/holyway/botplatform/telegram/processor/RandomMemeProcessor.java
+++ b/src/main/java/ru/holyway/botplatform/telegram/processor/RandomMemeProcessor.java
@@ -10,7 +10,7 @@
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import ru.holyway.botplatform.telegram.TelegramMessageEntity;
-import javax.annotation.PostConstruct;
+import jakarta.annotation.PostConstruct;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
diff --git a/src/main/java/ru/holyway/botplatform/telegram/processor/ReconnaissanceMessageProcessor.java b/src/main/java/ru/holyway/botplatform/telegram/processor/ReconnaissanceMessageProcessor.java
index d9a32da..a15efe2 100644
--- a/src/main/java/ru/holyway/botplatform/telegram/processor/ReconnaissanceMessageProcessor.java
+++ b/src/main/java/ru/holyway/botplatform/telegram/processor/ReconnaissanceMessageProcessor.java
@@ -135,8 +135,8 @@ public boolean isRegardingCallback(CallbackQuery callbackQuery) {
@Override
public void processCallBack(CallbackQuery callbackQuery, AbsSender sender)
throws TelegramApiException {
-
- final String chatID = String.valueOf(callbackQuery.getMessage().getChatId());
+ final Message cbMessage = (Message) callbackQuery.getMessage();
+ final String chatID = String.valueOf(cbMessage.getChatId());
List currentChatMembers = currentReconChatMembers.get(chatID);
if (currentChatMembers == null) {
currentChatMembers = new ArrayList<>();
@@ -152,14 +152,14 @@ public void processCallBack(CallbackQuery callbackQuery, AbsSender sender)
currentChatMembers.add(userID);
currentReconChatMembers.put(chatID, currentChatMembers);
- if (callbackQuery.getMessage().getChat().isUserChat()) {
- showResult(String.valueOf(callbackQuery.getMessage().getChatId()),
- callbackQuery.getMessage().getMessageId(), sender);
+ if (cbMessage.getChat().isUserChat()) {
+ showResult(String.valueOf(cbMessage.getChatId()),
+ cbMessage.getMessageId(), sender);
} else {
Integer userCount = sender.execute(GetChatMemberCount.builder().chatId(chatID).build());
if (userCount - 1 == currentChatMembers.size()) {
- showResult(String.valueOf(callbackQuery.getMessage().getChatId()),
- callbackQuery.getMessage().getMessageId(), sender);
+ showResult(String.valueOf(cbMessage.getChatId()),
+ cbMessage.getMessageId(), sender);
}
}
}
diff --git a/src/main/java/ru/holyway/botplatform/telegram/processor/ScriptManagerProcessor.java b/src/main/java/ru/holyway/botplatform/telegram/processor/ScriptManagerProcessor.java
index 4ce03e6..bf7eb33 100644
--- a/src/main/java/ru/holyway/botplatform/telegram/processor/ScriptManagerProcessor.java
+++ b/src/main/java/ru/holyway/botplatform/telegram/processor/ScriptManagerProcessor.java
@@ -11,6 +11,7 @@
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.DeleteMessage;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
+import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.chatmember.ChatMember;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ForceReplyKeyboard;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
@@ -169,23 +170,24 @@ public boolean isRegardingCallback(CallbackQuery callbackQuery) {
@Override
public void processCallBack(CallbackQuery callbackQuery, AbsSender sender)
throws TelegramApiException {
+ final Message cbMessage = (Message) callbackQuery.getMessage();
if (callbackQuery.getData().startsWith("script:edit:")) {
sender
.execute(SendMessage.builder().replyMarkup(new ForceReplyKeyboard())
- .chatId(String.valueOf(callbackQuery.getMessage().getChatId()))
- .text(callbackQuery.getMessage().getText()).build());
+ .chatId(String.valueOf(cbMessage.getChatId()))
+ .text(cbMessage.getText()).build());
} else if (callbackQuery.getData().startsWith("script:delete:")) {
final String scriptId = StringUtils.substringAfter(callbackQuery.getData(), "script:delete:");
- final Script script = scriptMessageProcessor.getScript(String.valueOf(callbackQuery.getMessage().getChatId()), Integer.valueOf(scriptId));
+ final Script script = scriptMessageProcessor.getScript(String.valueOf(cbMessage.getChatId()), Integer.valueOf(scriptId));
if (script != null) {
- if (callbackQuery.getMessage().getChat().isUserChat() || script.getOwner() == 0 || script.getOwner() == callbackQuery.getFrom().getId() || isAdmin(sender, callbackQuery.getMessage().getChatId(), callbackQuery.getFrom().getId())) {
+ if (cbMessage.getChat().isUserChat() || script.getOwner() == 0 || script.getOwner() == callbackQuery.getFrom().getId() || isAdmin(sender, cbMessage.getChatId(), callbackQuery.getFrom().getId())) {
if (scriptMessageProcessor.removeScript(
- String.valueOf(callbackQuery.getMessage().getChatId()), Integer.valueOf(scriptId))) {
+ String.valueOf(cbMessage.getChatId()), Integer.valueOf(scriptId))) {
sender
.execute(
- SendMessage.builder().chatId(String.valueOf(callbackQuery.getMessage().getChatId()))
+ SendMessage.builder().chatId(String.valueOf(cbMessage.getChatId()))
.text("Скрипт удален")
- .replyToMessageId(callbackQuery.getMessage().getMessageId()).build());
+ .replyToMessageId(cbMessage.getMessageId()).build());
} else {
sender.execute(AnswerCallbackQuery.builder().callbackQueryId(callbackQuery.getId())
.text("Скрипт не найден").build());
@@ -200,23 +202,23 @@ public void processCallBack(CallbackQuery callbackQuery, AbsSender sender)
}
} else if (callbackQuery.getData().startsWith("script:clear:")) {
final int firstMessage = Integer.parseInt(StringUtils.substringAfterLast(callbackQuery.getData(), ":"));
- for (int i = firstMessage; i <= callbackQuery.getMessage().getMessageId(); i++) {
+ for (int i = firstMessage; i <= cbMessage.getMessageId(); i++) {
try {
- sender.execute(DeleteMessage.builder().chatId(String.valueOf(callbackQuery.getMessage().getChatId())).messageId(i).build());
+ sender.execute(DeleteMessage.builder().chatId(String.valueOf(cbMessage.getChatId())).messageId(i).build());
} catch (Exception e) {
- LOGGER.warn("Could not delete message {} in chat {}", i, callbackQuery.getMessage().getChatId(), e);
+ LOGGER.warn("Could not delete message {} in chat {}", i, cbMessage.getChatId(), e);
}
}
} else if (callbackQuery.getData().startsWith("script:more:")) {
final int firstMessage = Integer.parseInt(StringUtils.substringAfterLast(callbackQuery.getData(), ":"));
final int offset = Integer.parseInt(StringUtils.substringBetween(callbackQuery.getData(), "script:more:", ":"));
- List