diff --git a/build.gradle.kts b/build.gradle.kts index 5a73dbc5f..6cf8a6140 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -91,9 +91,9 @@ allprojects { dependency("io.swagger.core.v3:swagger-annotations-jakarta:2.2.22") dependency("io.swagger.core.v3:swagger-models:2.2.22") dependency("io.swagger.core.v3:swagger-models-jakarta:2.2.22") - dependency("org.springdoc:springdoc-openapi-starter-common:2.5.0") - dependency("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0") - dependency("org.springdoc:springdoc-openapi-starter-webflux-ui:2.5.0") + dependency("org.springdoc:springdoc-openapi-starter-common:2.6.0") + dependency("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0") + dependency("org.springdoc:springdoc-openapi-starter-webflux-ui:2.6.0") // database & nosql dependency("org.mybatis:mybatis:3.5.16") dependency("org.mybatis:mybatis-spring:3.0.3") @@ -101,9 +101,9 @@ allprojects { dependency("org.mybatis.generator:mybatis-generator-core:1.4.2") dependency("org.apache.shardingsphere:shardingsphere-jdbc:5.5.0") dependency("com.github.jsqlparser:jsqlparser:4.9") - dependency("org.redisson:redisson:3.31.0") - dependency("org.redisson:redisson-spring-data-33:3.31.0") - dependency("org.redisson:redisson-spring-boot-starter:3.31.0") + dependency("org.redisson:redisson:3.32.0") + dependency("org.redisson:redisson-spring-data-33:3.32.0") + dependency("org.redisson:redisson-spring-boot-starter:3.32.0") // others dependency("com.nimbusds:nimbus-jose-jwt:9.40") dependency("com.nimbusds:oauth2-oidc-sdk:11.12") @@ -132,6 +132,9 @@ allprojects { dependency("org.jodd:jodd-bean:5.1.6") dependency("org.jodd:jodd-core:5.3.0") dependency("org.jodd:jodd-util:6.2.2") + dependency("org.jodd:jodd-http:6.3.0") + dependency("us.codecraft:webmagic-core:0.7.3") + dependency("us.codecraft:webmagic-extension:0.7.3") // xml & pdf & office & image dependency("xalan:xalan:2.7.3") dependency("org.jsoup:jsoup:1.17.2") @@ -156,33 +159,30 @@ allprojects { dependency("org.dom4j:dom4j:2.1.4") dependency("com.thoughtworks.xstream:xstream:1.4.20") dependency("org.apache.pdfbox:pdfbox:3.0.2") - dependency("org.dromara.x-easypdf:x-easypdf:3.0.0") - dependency("org.dromara.x-easypdf:x-easypdf-pdfbox:3.0.0") - dependency("org.dromara.x-easypdf:x-easypdf-fop:3.0.0") // sdks - dependency("io.minio:minio:8.5.10") + dependency("io.minio:minio:8.5.11") dependency("com.github.binarywang:weixin-java-channel:4.6.0") dependency("com.github.binarywang:weixin-java-cp:4.6.0") dependency("com.github.binarywang:weixin-java-miniapp:4.6.0") dependency("com.github.binarywang:weixin-java-mp:4.6.0") dependency("com.github.binarywang:weixin-java-open:4.6.0") dependency("com.github.binarywang:weixin-java-pay:4.6.0") - dependency("com.alibaba:dashscope-sdk-java:2.14.8") + dependency("com.alibaba:dashscope-sdk-java:2.15.1") dependency("com.aliyun:aliyun-java-sdk-core:4.6.4") - dependency("com.aliyun:tea-openapi:0.3.3") + dependency("com.aliyun:tea-openapi:0.3.4") dependency("com.aliyun:tea-rpc:0.1.3") dependency("com.aliyun:tea-rpc-util:0.1.3") - dependency("com.aliyun:dingtalk:2.1.27") + dependency("com.aliyun:dingtalk:2.1.29") dependency("com.aliyun:imm20170906:1.23.8") dependency("com.aliyun:facebody20191230:5.1.2") - dependency("com.aliyun:dysmsapi20170525:2.0.24") + dependency("com.aliyun:dysmsapi20170525:3.0.0") dependency("com.aliyun:alimt20181012:1.3.1") - dependency("com.aliyun.oss:aliyun-sdk-oss:3.17.4") - dependency("com.alipay.sdk:alipay-sdk-java:4.39.110.ALL") - dependency("com.qcloud:cos_api:5.6.218") - dependency("com.tencentcloudapi:tencentcloud-sdk-java-common:3.1.1042") + dependency("com.aliyun.oss:aliyun-sdk-oss:3.18.0") + dependency("com.alipay.sdk:alipay-sdk-java:4.39.123.ALL") + dependency("com.qcloud:cos_api:5.6.219.1") + dependency("com.tencentcloudapi:tencentcloud-sdk-java-common:3.1.1052") dependency("com.tencentcloudapi:tencentcloud-sdk-java-kms:3.1.977") - dependency("com.tencentcloudapi:tencentcloud-sdk-java-sms:3.1.1024") + dependency("com.tencentcloudapi:tencentcloud-sdk-java-sms:3.1.1043") dependency("com.tencentcloudapi:tencentcloud-sdk-java-tmt:3.1.1040") dependency("com.tencentcloudapi:tencentcloud-sdk-java-iai:3.1.978") dependency("com.tencentcloudapi:tencentcloud-sdk-java-hunyuan:3.1.1041") @@ -221,6 +221,7 @@ allprojects { exclude(module = "junit") exclude(module = "junit-vintage-engine") exclude(module = "log4j") + exclude(module = "slf4j-log4j12") exclude(module = "ehcache") exclude(module = "poi-ooxml-schemas") exclude(module = "javax.servlet-api") diff --git a/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/commons/web/HomeController.java b/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/commons/web/HomeController.java index d2573e5e7..70964d6ec 100644 --- a/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/commons/web/HomeController.java +++ b/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/commons/web/HomeController.java @@ -1,6 +1,8 @@ package cc.elvea.platform.system.commons.web; import cc.elvea.platform.commons.annotations.OperationLog; +import cc.elvea.platform.commons.constants.DateTimeConstants; +import cc.elvea.platform.commons.utils.DateTimeUtils; import cc.elvea.platform.commons.utils.StringUtils; import cc.elvea.platform.commons.utils.platform.Platform; import cc.elvea.platform.commons.utils.platform.PlatformHelper; @@ -8,9 +10,15 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.io.IOException; +import java.time.LocalDateTime; /** * @author elvea @@ -25,20 +33,33 @@ public class HomeController extends AbstractController { @ApiResponse(description = "首页") @GetMapping("/") @OperationLog("首页") - public String index() { - String page = ""; - if (this.context.isProductionMode()) { - Platform platform = PlatformHelper.fromServletRequest(); - if (platform.isMobile()) { - page = StringUtils.isNotEmpty(this.context.getHome().getMobile()) ? this.context.getHome().getMobile() : ""; - } else { - page = StringUtils.isNotEmpty(this.context.getHome().getWebapp()) ? this.context.getHome().getWebapp() : ""; + public void index(@RequestParam("i") String i, HttpServletResponse response) throws IOException { + String page = "/home"; + if ("1".equalsIgnoreCase(i)) { + response.addCookie(new Cookie("a", DateTimeUtils.format(LocalDateTime.now(), DateTimeConstants.Pattern.FULL_TIME))); + page = "/about"; + } else { + if (this.context.isProductionMode()) { + Platform platform = PlatformHelper.fromServletRequest(); + if (platform.isMobile()) { + page = StringUtils.isNotEmpty(this.context.getHome().getMobile()) ? this.context.getHome().getMobile() : ""; + } else { + page = StringUtils.isNotEmpty(this.context.getHome().getWebapp()) ? this.context.getHome().getWebapp() : ""; + } + } + if (StringUtils.isEmpty(page)) { + page = StringUtils.isNotEmpty(this.context.getHome().getMain()) ? this.context.getHome().getMain() : "about"; } } - if (StringUtils.isEmpty(page)) { - page = StringUtils.isNotEmpty(this.context.getHome().getMain()) ? this.context.getHome().getMain() : "about"; - } - return redirect(page); + response.sendRedirect(page); + } + + @Operation(summary = "主页") + @ApiResponse(description = "主页") + @GetMapping("/home") + @OperationLog("主页") + public String home() { + return "index"; } @Operation(summary = "关于页") diff --git a/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/message/api/impl/MessageApiImpl.java b/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/message/api/impl/MessageApiImpl.java index 620297253..534d54707 100644 --- a/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/message/api/impl/MessageApiImpl.java +++ b/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/message/api/impl/MessageApiImpl.java @@ -2,7 +2,7 @@ import cc.elvea.platform.commons.constants.GlobalConstants; import cc.elvea.platform.commons.enums.BaseEnum; -import cc.elvea.platform.commons.extensions.template.HtmlTemplateService; +import cc.elvea.platform.commons.template.HtmlTemplateService; import cc.elvea.platform.commons.utils.*; import cc.elvea.platform.system.core.model.entity.UserEntity; import cc.elvea.platform.system.core.service.UserService; diff --git a/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/message/sender/MessageMailSender.java b/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/message/sender/MessageMailSender.java index 17adfed9a..47df60ab5 100644 --- a/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/message/sender/MessageMailSender.java +++ b/platform-boot-modules/system/system-impl/src/main/java/cc/elvea/platform/system/message/sender/MessageMailSender.java @@ -1,7 +1,7 @@ package cc.elvea.platform.system.message.sender; -import cc.elvea.platform.commons.extensions.mail.MailBody; -import cc.elvea.platform.commons.extensions.mail.MailSender; +import cc.elvea.platform.commons.mail.MailBody; +import cc.elvea.platform.commons.mail.MailSender; import cc.elvea.platform.commons.utils.ExceptionUtils; import cc.elvea.platform.system.message.model.dto.SendMessageDto; import cc.elvea.platform.system.message.service.MessageContentService; diff --git a/platform-boot-server/app-server/src/main/resources/application-development.yml b/platform-boot-server/app-server/src/main/resources/application-development.yml index 36b899747..4c6c1a1fd 100644 --- a/platform-boot-server/app-server/src/main/resources/application-development.yml +++ b/platform-boot-server/app-server/src/main/resources/application-development.yml @@ -145,6 +145,13 @@ platform: enabled: true quartz: enabled: true + http: + enabled: true + type: okhttp + proxy: + enabled: true + host: 127.0.0.1 + port: 7890 oapis: dingtalk: enabled: false diff --git a/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/http/HttpTests.java b/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/http/HttpTests.java new file mode 100644 index 000000000..e7c134f66 --- /dev/null +++ b/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/http/HttpTests.java @@ -0,0 +1,48 @@ +package cc.elvea.platform.commons.extensions.http; + +import cc.elvea.platform.BaseTests; +import cc.elvea.platform.commons.http.HttpConfig; +import cc.elvea.platform.commons.http.HttpManger; +import cc.elvea.platform.commons.http.HttpType; +import cc.elvea.platform.commons.http.executor.HttpExecutor; +import cc.elvea.platform.commons.http.executor.HttpGetRequestExecutor; +import com.google.common.collect.Maps; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +/** + * @author elvea + * @since 24.1.0 + */ +@Slf4j +public class HttpTests extends BaseTests { + + @Test + public void baseTest() throws Exception { + HttpExecutor> executor = HttpGetRequestExecutor.create(HttpManger.getHttp().getConfig()); + executor.execute("https://google.com", Maps.newHashMap(), response -> { + log.info("google response: {}", response); + }); + } + + @Test + public void baseOkHttpTest() throws Exception { + HttpConfig config = HttpConfig.builder().type(HttpType.OKHTTP).build(); + HttpExecutor> executor = HttpGetRequestExecutor.create(config); + executor.execute("https://baidu.com", Maps.newHashMap(), response -> { + log.info("okhttp response: {}", response); + }); + } + + @Test + public void baseApacheHttpTest() throws Exception { + HttpConfig config = HttpConfig.builder().type(HttpType.APACHE).build(); + HttpExecutor> executor = HttpGetRequestExecutor.create(config); + executor.execute("https://baidu.com", Maps.newHashMap(), response -> { + log.info("apache response: {}", response); + }); + } + +} diff --git a/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/mail/MailSenderTests.java b/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/mail/MailSenderTests.java index 12efbd219..67641bafc 100644 --- a/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/mail/MailSenderTests.java +++ b/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/mail/MailSenderTests.java @@ -1,6 +1,8 @@ package cc.elvea.platform.commons.extensions.mail; import cc.elvea.platform.BaseTests; +import cc.elvea.platform.commons.mail.MailBody; +import cc.elvea.platform.commons.mail.MailSender; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/template/HtmlTemplateServiceTests.java b/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/template/HtmlTemplateServiceTests.java index 7de8fa7ed..79be914a6 100644 --- a/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/template/HtmlTemplateServiceTests.java +++ b/platform-boot-server/app-server/src/test/java/cc/elvea/platform/commons/extensions/template/HtmlTemplateServiceTests.java @@ -1,6 +1,7 @@ package cc.elvea.platform.commons.extensions.template; import cc.elvea.platform.BaseTests; +import cc.elvea.platform.commons.template.HtmlTemplateService; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Assertions; diff --git a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/http/HttpAutoConfiguration.java b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/http/HttpAutoConfiguration.java new file mode 100644 index 000000000..9aa17148e --- /dev/null +++ b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/http/HttpAutoConfiguration.java @@ -0,0 +1,38 @@ +package cc.elvea.platform.commons.autoconfigure.http; + +import cc.elvea.platform.commons.autoconfigure.http.properties.HttpProperties; +import cc.elvea.platform.commons.http.Http; +import cc.elvea.platform.commons.http.HttpManger; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author elvea + * @since 24.1.0 + */ +@Slf4j +@Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(prefix = HttpProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) +@EnableConfigurationProperties({HttpProperties.class}) +public class HttpAutoConfiguration { + + public HttpAutoConfiguration() { + log.info("HttpAutoConfiguration is enabled."); + } + + /** + * @return {@link HttpManger} + */ + @Bean + @ConditionalOnMissingBean + public Http httpManger(HttpProperties properties) { + Http http = new Http(); + HttpManger.setHttp(http); + return http; + } + +} diff --git a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/http/properties/HttpProperties.java b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/http/properties/HttpProperties.java new file mode 100644 index 000000000..1ffbedfb8 --- /dev/null +++ b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/http/properties/HttpProperties.java @@ -0,0 +1,28 @@ +package cc.elvea.platform.commons.autoconfigure.http.properties; + +import cc.elvea.platform.commons.http.HttpProxy; +import cc.elvea.platform.commons.http.HttpType; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; + +/** + * @author elvea + * @since 24.1.0 + */ +@Data +@NoArgsConstructor +@ConfigurationProperties(HttpProperties.PREFIX) +public class HttpProperties { + + public static final String PREFIX = "platform.http"; + + private boolean enabled = true; + + private HttpType type = HttpType.OKHTTP; + + @NestedConfigurationProperty + private HttpProxy proxy = HttpProxy.builder().build(); + +} diff --git a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/mail/MailAutoConfiguration.java b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/mail/MailAutoConfiguration.java similarity index 76% rename from platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/mail/MailAutoConfiguration.java rename to platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/mail/MailAutoConfiguration.java index ab7389064..e1477190f 100644 --- a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/mail/MailAutoConfiguration.java +++ b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/mail/MailAutoConfiguration.java @@ -1,8 +1,8 @@ -package cc.elvea.platform.commons.autoconfigure.extensions.mail; +package cc.elvea.platform.commons.autoconfigure.mail; -import cc.elvea.platform.commons.autoconfigure.extensions.mail.properties.MailProperties; -import cc.elvea.platform.commons.extensions.mail.MailSender; -import cc.elvea.platform.commons.extensions.mail.spring.SpringMailSender; +import cc.elvea.platform.commons.autoconfigure.mail.properties.MailProperties; +import cc.elvea.platform.commons.mail.MailSender; +import cc.elvea.platform.commons.mail.spring.SpringMailSender; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; diff --git a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/mail/properties/MailProperties.java b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/mail/properties/MailProperties.java similarity index 79% rename from platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/mail/properties/MailProperties.java rename to platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/mail/properties/MailProperties.java index a60038c03..ac57d81ed 100644 --- a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/mail/properties/MailProperties.java +++ b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/mail/properties/MailProperties.java @@ -1,6 +1,6 @@ -package cc.elvea.platform.commons.autoconfigure.extensions.mail.properties; +package cc.elvea.platform.commons.autoconfigure.mail.properties; -import cc.elvea.platform.commons.extensions.mail.MailServer; +import cc.elvea.platform.commons.mail.MailServer; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/swagger/SwaggerAutoConfiguration.java b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/swagger/SwaggerAutoConfiguration.java similarity index 90% rename from platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/swagger/SwaggerAutoConfiguration.java rename to platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/swagger/SwaggerAutoConfiguration.java index e73a809b6..ebc9c64d3 100644 --- a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/swagger/SwaggerAutoConfiguration.java +++ b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/swagger/SwaggerAutoConfiguration.java @@ -1,6 +1,6 @@ -package cc.elvea.platform.commons.autoconfigure.extensions.swagger; +package cc.elvea.platform.commons.autoconfigure.swagger; -import cc.elvea.platform.commons.autoconfigure.extensions.swagger.properties.SwaggerProperties; +import cc.elvea.platform.commons.autoconfigure.swagger.properties.SwaggerProperties; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; diff --git a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/swagger/properties/SwaggerProperties.java b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/swagger/properties/SwaggerProperties.java similarity index 88% rename from platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/swagger/properties/SwaggerProperties.java rename to platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/swagger/properties/SwaggerProperties.java index 0414543cf..18dae3cc9 100644 --- a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/swagger/properties/SwaggerProperties.java +++ b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/swagger/properties/SwaggerProperties.java @@ -1,4 +1,4 @@ -package cc.elvea.platform.commons.autoconfigure.extensions.swagger.properties; +package cc.elvea.platform.commons.autoconfigure.swagger.properties; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/template/TemplateAutoConfiguration.java b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/template/TemplateAutoConfiguration.java similarity index 76% rename from platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/template/TemplateAutoConfiguration.java rename to platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/template/TemplateAutoConfiguration.java index d5a8cbb01..538673492 100644 --- a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/template/TemplateAutoConfiguration.java +++ b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/template/TemplateAutoConfiguration.java @@ -1,8 +1,8 @@ -package cc.elvea.platform.commons.autoconfigure.extensions.template; +package cc.elvea.platform.commons.autoconfigure.template; -import cc.elvea.platform.commons.autoconfigure.extensions.template.properties.TemplateProperties; -import cc.elvea.platform.commons.extensions.template.DefaultHtmlTemplateService; -import cc.elvea.platform.commons.extensions.template.HtmlTemplateService; +import cc.elvea.platform.commons.autoconfigure.template.properties.TemplateProperties; +import cc.elvea.platform.commons.template.DefaultHtmlTemplateService; +import cc.elvea.platform.commons.template.HtmlTemplateService; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; diff --git a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/template/properties/TemplateProperties.java b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/template/properties/TemplateProperties.java similarity index 82% rename from platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/template/properties/TemplateProperties.java rename to platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/template/properties/TemplateProperties.java index 0994dab6b..9c2e6673a 100644 --- a/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/extensions/template/properties/TemplateProperties.java +++ b/platform-commons/commons-core-starter/src/main/java/cc/elvea/platform/commons/autoconfigure/template/properties/TemplateProperties.java @@ -1,4 +1,4 @@ -package cc.elvea.platform.commons.autoconfigure.extensions.template.properties; +package cc.elvea.platform.commons.autoconfigure.template.properties; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/platform-commons/commons-core-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/platform-commons/commons-core-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 237f92c68..ddde65c2a 100644 --- a/platform-commons/commons-core-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/platform-commons/commons-core-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,11 +1,15 @@ cc.elvea.platform.commons.autoconfigure.core.CoreAutoConfiguration cc.elvea.platform.commons.autoconfigure.core.JwtAutoConfiguration cc.elvea.platform.commons.autoconfigure.core.RateLimitAutoConfiguration +cc.elvea.platform.commons.autoconfigure.cache.CustomCacheAutoConfiguration +cc.elvea.platform.commons.autoconfigure.http.HttpAutoConfiguration cc.elvea.platform.commons.autoconfigure.logging.LogAutoConfiguration cc.elvea.platform.commons.autoconfigure.job.CustomQuartzAutoConfiguration -cc.elvea.platform.commons.autoconfigure.cache.CustomCacheAutoConfiguration +cc.elvea.platform.commons.autoconfigure.mail.MailAutoConfiguration cc.elvea.platform.commons.autoconfigure.sequence.SequenceAutoConfiguration +cc.elvea.platform.commons.autoconfigure.template.TemplateAutoConfiguration cc.elvea.platform.commons.autoconfigure.storage.StorageAutoConfiguration +cc.elvea.platform.commons.autoconfigure.swagger.SwaggerAutoConfiguration cc.elvea.platform.commons.autoconfigure.web.WebAutoConfiguration cc.elvea.platform.commons.autoconfigure.data.core.CustomDataAutoConfiguration cc.elvea.platform.commons.autoconfigure.data.datasource.CustomDataSourceAutoConfiguration @@ -16,16 +20,13 @@ cc.elvea.platform.commons.autoconfigure.data.mongodb.CustomMongoAutoConfiguratio cc.elvea.platform.commons.autoconfigure.oapis.weixin.WeiXinCpAutoConfiguration cc.elvea.platform.commons.autoconfigure.oapis.weixin.WeiXinMaAutoConfiguration cc.elvea.platform.commons.autoconfigure.oapis.weixin.WeiXinMpAutoConfiguration -cc.elvea.platform.commons.autoconfigure.oapis.lark.LarkAutoConfiguration cc.elvea.platform.commons.autoconfigure.oapis.dingtalk.DingTalkAutoConfiguration cc.elvea.platform.commons.autoconfigure.oapis.facebody.FaceBodyAutoConfiguration +cc.elvea.platform.commons.autoconfigure.oapis.lark.LarkAutoConfiguration cc.elvea.platform.commons.autoconfigure.oapis.sms.SmsAutoConfiguration cc.elvea.platform.commons.autoconfigure.oapis.translator.TranslatorAutoConfiguration cc.elvea.platform.commons.autoconfigure.extensions.captcha.CaptchaAutoConfiguration cc.elvea.platform.commons.autoconfigure.extensions.keyword.KeywordAutoConfiguration -cc.elvea.platform.commons.autoconfigure.extensions.mail.MailAutoConfiguration cc.elvea.platform.commons.autoconfigure.extensions.sensitive.SensitiveAutoConfiguration -cc.elvea.platform.commons.autoconfigure.extensions.swagger.SwaggerAutoConfiguration -cc.elvea.platform.commons.autoconfigure.extensions.template.TemplateAutoConfiguration cc.elvea.platform.commons.autoconfigure.message.socket.WebSocketCommonAutoConfiguration cc.elvea.platform.commons.autoconfigure.message.socket.WebSocketMessageBrokerAutoConfiguration diff --git a/platform-commons/commons-core/build.gradle.kts b/platform-commons/commons-core/build.gradle.kts index b088cdae4..4b5bb769c 100644 --- a/platform-commons/commons-core/build.gradle.kts +++ b/platform-commons/commons-core/build.gradle.kts @@ -69,6 +69,10 @@ dependencies { compileOnly("com.tencentcloudapi:tencentcloud-sdk-java-iai") compileOnly("com.larksuite.oapi:oapi-sdk") compileOnly("com.github.goodforgod:java-etherscan-api") + // http + api("org.jodd:jodd-http") + api("com.squareup.okhttp3:okhttp") + api("org.apache.httpcomponents.client5:httpclient5") // 3rd party api("com.github.spotbugs:spotbugs-annotations") api("io.swagger.core.v3:swagger-annotations") @@ -77,9 +81,7 @@ dependencies { api("com.google.code.gson:gson") api("com.mysql:mysql-connector-j") api("com.google.guava:guava") - api("com.squareup.okhttp3:okhttp") api("com.nimbusds:nimbus-jose-jwt") - api("org.apache.httpcomponents.client5:httpclient5") api("cn.hutool:hutool-captcha") api("cn.hutool:hutool-dfa") api("cn.hutool:hutool-http") diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/Http.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/Http.java new file mode 100644 index 000000000..5c77f054c --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/Http.java @@ -0,0 +1,48 @@ +package cc.elvea.platform.commons.http; + +import cc.elvea.platform.commons.utils.http.ApacheHttpUtils; +import cc.elvea.platform.commons.utils.http.OkHttpUtils; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import okhttp3.OkHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; + +/** + * @author elvea + * @since 24.1.0 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Http { + + @Builder.Default + private HttpType type = HttpType.OKHTTP; + + @Builder.Default + private HttpProxy proxy = HttpProxy.builder().build(); + + public HttpConfig getConfig() { + return HttpConfig.builder().type(this.type).build(); + } + + public OkHttpClient getOkHttpClient() { + return Http.getOkHttpClient(this.getConfig()); + } + + public CloseableHttpClient getApacheHttpClient() { + return Http.getApacheHttpClient(this.getConfig()); + } + + public static OkHttpClient getOkHttpClient(HttpConfig config) { + return OkHttpUtils.getClient(); + } + + public static CloseableHttpClient getApacheHttpClient(HttpConfig config) { + return ApacheHttpUtils.getClient(); + } + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpConfig.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpConfig.java new file mode 100644 index 000000000..ab84eb805 --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpConfig.java @@ -0,0 +1,24 @@ +package cc.elvea.platform.commons.http; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author elvea + * @since 24.1.0 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class HttpConfig implements Serializable { + + HttpProxy proxy; + + HttpType type; + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpManger.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpManger.java new file mode 100644 index 000000000..7903624f0 --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpManger.java @@ -0,0 +1,18 @@ +package cc.elvea.platform.commons.http; + +import lombok.Getter; + +/** + * @author elvea + * @since 24.1.0 + */ +public class HttpManger { + + @Getter + private static volatile Http http = Http.builder().type(HttpType.OKHTTP).build(); + + public static void setHttp(Http http) { + HttpManger.http = http; + } + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpProxy.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpProxy.java new file mode 100644 index 000000000..4922beace --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpProxy.java @@ -0,0 +1,31 @@ +package cc.elvea.platform.commons.http; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author elvea + * @since 24.1.0 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class HttpProxy implements Serializable { + + @Builder.Default + private boolean enabled = false; + + private String host; + + private Integer port; + + private String username; + + private String password; + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpType.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpType.java new file mode 100644 index 000000000..324b32069 --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpType.java @@ -0,0 +1,10 @@ +package cc.elvea.platform.commons.http; + +/** + * @author elvea + * @since 24.1.0 + */ +public enum HttpType { + APACHE, + OKHTTP +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpUtils.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpUtils.java new file mode 100644 index 000000000..9d368e880 --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/HttpUtils.java @@ -0,0 +1,29 @@ +package cc.elvea.platform.commons.http; + +import cc.elvea.platform.commons.utils.http.ApacheHttpUtils; +import okhttp3.OkHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; + +import java.net.InetSocketAddress; +import java.net.Proxy; + +/** + * @author elvea + * @since 24.1.0 + */ +public final class HttpUtils { + + public static OkHttpClient getOkHttpClient(HttpConfig config) { + OkHttpClient.Builder builder = new OkHttpClient().newBuilder(); + if (config.getProxy() != null && config.getProxy().isEnabled()) { + Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(config.getProxy().getHost(), config.getProxy().getPort())); + builder.proxy(proxy); + } + return builder.build(); + } + + public static CloseableHttpClient getApacheHttpClient(HttpConfig config) { + return ApacheHttpUtils.getClient(); + } + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/ResponseHandler.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/ResponseHandler.java new file mode 100644 index 000000000..095d9cdd4 --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/ResponseHandler.java @@ -0,0 +1,9 @@ +package cc.elvea.platform.commons.http; + +/** + * @author elvea + * @since 24.1.0 + */ +public interface ResponseHandler { + void handle(T t); +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/apache/ApacheGetRequestExecutor.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/apache/ApacheGetRequestExecutor.java new file mode 100644 index 000000000..bca54691a --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/apache/ApacheGetRequestExecutor.java @@ -0,0 +1,48 @@ +package cc.elvea.platform.commons.http.apache; + +import cc.elvea.platform.commons.constants.GlobalConstants; +import cc.elvea.platform.commons.http.HttpConfig; +import cc.elvea.platform.commons.http.HttpUtils; +import cc.elvea.platform.commons.http.executor.HttpGetRequestExecutor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.core5.http.io.entity.EntityUtils; + +import java.io.IOException; +import java.util.Map; + +/** + * @author elvea + * @since 24.1.0 + */ +@Slf4j +public class ApacheGetRequestExecutor extends HttpGetRequestExecutor { + + public ApacheGetRequestExecutor(HttpConfig config) { + super(config); + } + + @Override + public String execute(String uri, Map paramMap) throws IOException { + final String url = this.handleQueryParam(uri, paramMap); + + log.info("ApacheGetRequestExecutor.execute() - [{}] - start.", url); + HttpGet httpGet = new HttpGet(uri); + return getHttpClient().execute(httpGet, response -> { + String content = ""; + if (!ObjectUtils.isEmpty(response) && !ObjectUtils.isEmpty(response.getEntity())) { + content = EntityUtils.toString(response.getEntity(), GlobalConstants.UTF8); + log.info("ApacheGetRequestExecutor.execute() - [{}] - response - [{}].", uri, content); + } + log.info("ApacheGetRequestExecutor.execute() - [{}] - start.", url); + return content; + }); + } + + protected CloseableHttpClient getHttpClient() { + return HttpUtils.getApacheHttpClient(this.config); + } + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/executor/HttpExecutor.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/executor/HttpExecutor.java new file mode 100644 index 000000000..70e47644a --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/executor/HttpExecutor.java @@ -0,0 +1,19 @@ +package cc.elvea.platform.commons.http.executor; + +import cc.elvea.platform.commons.http.ResponseHandler; + +import java.io.IOException; + +/** + * 请求执行器 + * + * @param + * @param + */ +public interface HttpExecutor { + + T execute(String uri, E data) throws IOException; + + void execute(String uri, E data, ResponseHandler handler) throws IOException; + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/executor/HttpGetRequestExecutor.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/executor/HttpGetRequestExecutor.java new file mode 100644 index 000000000..3300bdbbb --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/executor/HttpGetRequestExecutor.java @@ -0,0 +1,58 @@ +package cc.elvea.platform.commons.http.executor; + +import cc.elvea.platform.commons.http.HttpConfig; +import cc.elvea.platform.commons.http.ResponseHandler; +import cc.elvea.platform.commons.http.apache.ApacheGetRequestExecutor; +import cc.elvea.platform.commons.http.okhttp.OkHttpGetRequestExecutor; +import cc.elvea.platform.commons.utils.ObjectUtils; +import cc.elvea.platform.commons.utils.StringUtils; +import org.apache.commons.collections4.MapUtils; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.util.Map; + +/** + * @author elvea + * @since 24.1.0 + */ +public abstract class HttpGetRequestExecutor implements HttpExecutor> { + + protected HttpConfig config; + + public HttpGetRequestExecutor(HttpConfig config) { + this.config = config; + } + + @Override + public void execute(String uri, Map data, ResponseHandler handler) throws IOException { + handler.handle(this.execute(uri, data)); + } + + public static HttpExecutor> create(HttpConfig config) { + return switch (config.getType()) { + case APACHE -> new ApacheGetRequestExecutor(config); + case OKHTTP -> new OkHttpGetRequestExecutor(config); + }; + } + + public String handleQueryParam(String uri, Map paramMap) { + if (MapUtils.isNotEmpty(paramMap) && StringUtils.isNotEmpty(uri)) { + if (uri.indexOf('?') == -1) { + uri += '?'; + } + StringBuilder sb = new StringBuilder(uri); + for (String key : paramMap.keySet()) { + sb.append(sb.toString().endsWith("?") ? key : '&' + ObjectUtils.nvl(paramMap.get(key), "")); + } + uri = sb.toString(); + } + return uri; + } + + @NotNull + public String handleResponse(String response) { + return response; + } + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/okhttp/OkHttpGetRequestExecutor.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/okhttp/OkHttpGetRequestExecutor.java new file mode 100644 index 000000000..47231a8ac --- /dev/null +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/http/okhttp/OkHttpGetRequestExecutor.java @@ -0,0 +1,45 @@ +package cc.elvea.platform.commons.http.okhttp; + +import cc.elvea.platform.commons.http.HttpConfig; +import cc.elvea.platform.commons.http.HttpUtils; +import cc.elvea.platform.commons.http.executor.HttpGetRequestExecutor; +import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +import java.io.IOException; +import java.util.Map; + +/** + * @author elvea + * @since 24.1.0 + */ +@Slf4j +public class OkHttpGetRequestExecutor extends HttpGetRequestExecutor { + + public OkHttpGetRequestExecutor(HttpConfig config) { + super(config); + } + + @Override + public String execute(String uri, Map paramMap) throws IOException { + uri = this.handleQueryParam(uri, paramMap); + + log.info("OkHttpGetRequestExecutor.execute() - [{}] - start.", uri); + OkHttpClient client = getHttpClient(); + Request request = new Request.Builder().url(uri).build(); + try (Response response = client.newCall(request).execute()) { + String content = response.body().string(); + log.info("OkHttpGetRequestExecutor.execute() - [{}] - response - [{}].", uri, content); + return this.handleResponse(content); + } finally { + log.info("OkHttpGetRequestExecutor.execute() - [{}] - finish.", uri); + } + } + + protected OkHttpClient getHttpClient() { + return HttpUtils.getOkHttpClient(this.config); + } + +} diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailBody.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailBody.java similarity index 84% rename from platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailBody.java rename to platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailBody.java index 95b308f24..479a6fc73 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailBody.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailBody.java @@ -1,4 +1,4 @@ -package cc.elvea.platform.commons.extensions.mail; +package cc.elvea.platform.commons.mail; import lombok.Builder; import lombok.Data; diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailSender.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailSender.java similarity index 78% rename from platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailSender.java rename to platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailSender.java index 21e920a60..afb615f2e 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailSender.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailSender.java @@ -1,4 +1,4 @@ -package cc.elvea.platform.commons.extensions.mail; +package cc.elvea.platform.commons.mail; /** * @author elvea diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailServer.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailServer.java similarity index 93% rename from platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailServer.java rename to platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailServer.java index 1e0d9f5c8..a276d301b 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/MailServer.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/MailServer.java @@ -1,4 +1,4 @@ -package cc.elvea.platform.commons.extensions.mail; +package cc.elvea.platform.commons.mail; import cc.elvea.platform.commons.enums.SslProtocolTypeEnum; import lombok.AllArgsConstructor; diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/spring/SpringMailSender.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/spring/SpringMailSender.java similarity index 93% rename from platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/spring/SpringMailSender.java rename to platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/spring/SpringMailSender.java index 01fc9713b..305dd10e1 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/mail/spring/SpringMailSender.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/mail/spring/SpringMailSender.java @@ -1,10 +1,10 @@ -package cc.elvea.platform.commons.extensions.mail.spring; +package cc.elvea.platform.commons.mail.spring; import cc.elvea.platform.commons.constants.GlobalConstants; import cc.elvea.platform.commons.enums.SslProtocolTypeEnum; -import cc.elvea.platform.commons.extensions.mail.MailBody; -import cc.elvea.platform.commons.extensions.mail.MailSender; -import cc.elvea.platform.commons.extensions.mail.MailServer; +import cc.elvea.platform.commons.mail.MailBody; +import cc.elvea.platform.commons.mail.MailSender; +import cc.elvea.platform.commons.mail.MailServer; import jakarta.mail.internet.MimeMessage; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/oapis/translator/baidu/BaiduTranslator.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/oapis/translator/baidu/BaiduTranslator.java index 0e1117ad6..2eaaf7c13 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/oapis/translator/baidu/BaiduTranslator.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/oapis/translator/baidu/BaiduTranslator.java @@ -2,7 +2,11 @@ import cc.elvea.platform.commons.oapis.translator.Translator; import cc.elvea.platform.commons.oapis.translator.TranslatorConverter; -import cc.elvea.platform.commons.utils.*; +import cc.elvea.platform.commons.utils.CollectionUtils; +import cc.elvea.platform.commons.utils.GsonUtils; +import cc.elvea.platform.commons.utils.JacksonUtils; +import cc.elvea.platform.commons.utils.StringUtils; +import cc.elvea.platform.commons.utils.http.ApacheHttpUtils; import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -52,7 +56,7 @@ public String translate(String sourceLang, String targetLang, String text) { log.info("BaiduTranslator translate from {} to {} start. text - [{}].", sourceLang, targetLang, text); try { - String responseText = HttpComponentsUtils.get(this.config.getEndpoint(), params); + String responseText = ApacheHttpUtils.get(this.config.getEndpoint(), params); Response response = JacksonUtils.toObject(responseText, Response.class); log.info("BaiduTranslator translate from {} to {}. response - [{}].", sourceLang, targetLang, GsonUtils.toJson(response)); diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/template/DefaultHtmlTemplateService.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/template/DefaultHtmlTemplateService.java similarity index 91% rename from platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/template/DefaultHtmlTemplateService.java rename to platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/template/DefaultHtmlTemplateService.java index 4628e92c0..c18f9afca 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/template/DefaultHtmlTemplateService.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/template/DefaultHtmlTemplateService.java @@ -1,4 +1,4 @@ -package cc.elvea.platform.commons.extensions.template; +package cc.elvea.platform.commons.template; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.Context; diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/template/HtmlTemplateService.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/template/HtmlTemplateService.java similarity index 75% rename from platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/template/HtmlTemplateService.java rename to platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/template/HtmlTemplateService.java index 657357b7a..515ab1adf 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/extensions/template/HtmlTemplateService.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/template/HtmlTemplateService.java @@ -1,4 +1,4 @@ -package cc.elvea.platform.commons.extensions.template; +package cc.elvea.platform.commons.template; import java.util.Map; diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/HttpComponentsUtils.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/http/ApacheHttpUtils.java similarity index 94% rename from platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/HttpComponentsUtils.java rename to platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/http/ApacheHttpUtils.java index d212f5490..c4dbdb4ae 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/HttpComponentsUtils.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/http/ApacheHttpUtils.java @@ -1,6 +1,7 @@ -package cc.elvea.platform.commons.utils; +package cc.elvea.platform.commons.utils.http; import cc.elvea.platform.commons.constants.GlobalConstants; +import cc.elvea.platform.commons.utils.JacksonUtils; import com.google.common.collect.Maps; import org.apache.commons.lang3.ObjectUtils; import org.apache.hc.client5.http.classic.HttpClient; @@ -30,7 +31,7 @@ * @author elvea * @since 24.1.0 */ -public abstract class HttpComponentsUtils { +public abstract class ApacheHttpUtils { // ----------------------------------------------------------------------------------------------------------------- // Get @@ -188,4 +189,12 @@ public static String createBearerAuthorization(String token) { return "Bearer " + token; } + // ----------------------------------------------------------------------------------------------------------------- + // Commons + // ----------------------------------------------------------------------------------------------------------------- + + public static CloseableHttpClient getClient() { + return HttpClients.createDefault(); + } + } diff --git a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/OkHttpUtils.java b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/http/OkHttpUtils.java similarity index 89% rename from platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/OkHttpUtils.java rename to platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/http/OkHttpUtils.java index 166f86fed..70ccda1a6 100644 --- a/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/OkHttpUtils.java +++ b/platform-commons/commons-core/src/main/java/cc/elvea/platform/commons/utils/http/OkHttpUtils.java @@ -1,5 +1,6 @@ -package cc.elvea.platform.commons.utils; +package cc.elvea.platform.commons.utils.http; +import cc.elvea.platform.commons.utils.GsonUtils; import com.google.common.collect.Maps; import okhttp3.*; import org.apache.commons.collections4.MapUtils; @@ -24,12 +25,6 @@ public abstract class OkHttpUtils { private static final int READ_TIMEOUT = 3 * 60 * 1000; private static final int WRITE_TIMEOUT = 3 * 60 * 1000; - private static final OkHttpClient client = new OkHttpClient().newBuilder() - .connectTimeout(CONNECT_TIMEOUT, TimeUnit.MILLISECONDS) - .readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS) - .writeTimeout(WRITE_TIMEOUT, TimeUnit.MILLISECONDS) - .build(); - // ----------------------------------------------------------------------------------------------------------------- // Get // ----------------------------------------------------------------------------------------------------------------- @@ -107,8 +102,16 @@ public static Response postJson(String url, String json) throws Exception { // Commons // ----------------------------------------------------------------------------------------------------------------- + public static OkHttpClient getClient() { + return new OkHttpClient().newBuilder() + .connectTimeout(CONNECT_TIMEOUT, TimeUnit.MILLISECONDS) + .readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS) + .writeTimeout(WRITE_TIMEOUT, TimeUnit.MILLISECONDS) + .build(); + } + public static Response execute(Request request) throws Exception { - return client.newCall(request).execute(); + return getClient().newCall(request).execute(); } }