From 3f2c0c9a0a231addbbb89d94e97cbf0c98b0c114 Mon Sep 17 00:00:00 2001 From: hengboy Date: Wed, 22 Jul 2020 21:25:55 +0800 Subject: [PATCH 1/7] [#44] Adapt "minbox-oss" component --- .../api-boot-autoconfigure/pom.xml | 5 + .../oss/ApiBootOssAutoConfiguration.java | 17 +- .../oss/ApiBootOssProperties.java | 2 +- .../api-boot-dependencies/pom.xml | 194 +------------ .../api-boot-starter-alibaba-oss/pom.xml | 6 +- api-boot-project/api-boot/pom.xml | 5 - .../api/boot/oss/ApiBootOssService.java | 267 ------------------ .../framework/api/boot/oss/OssRegion.java | 101 ------- .../framework/api/boot/oss/PartSize.java | 42 --- .../ApiBootObjectStorageProgress.java | 55 ---- .../oss/progress/OssProgressListener.java | 95 ------- .../storage/ApiBootObjectStorageService.java | 61 ---- .../ApiBootObjectStorageException.java | 16 -- .../ApiBootObjectStorageResponse.java | 22 -- .../sample/ApiBootOssOverrideService.java | 4 +- .../api/boot/sample/ApiBootOssTest.java | 12 +- 16 files changed, 29 insertions(+), 875 deletions(-) delete mode 100644 api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/ApiBootOssService.java delete mode 100644 api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/OssRegion.java delete mode 100644 api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/PartSize.java delete mode 100644 api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/progress/ApiBootObjectStorageProgress.java delete mode 100644 api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/progress/OssProgressListener.java delete mode 100644 api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/ApiBootObjectStorageService.java delete mode 100644 api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/exception/ApiBootObjectStorageException.java delete mode 100644 api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/response/ApiBootObjectStorageResponse.java diff --git a/api-boot-project/api-boot-autoconfigure/pom.xml b/api-boot-project/api-boot-autoconfigure/pom.xml index 411b7c74..7f52bcb2 100644 --- a/api-boot-project/api-boot-autoconfigure/pom.xml +++ b/api-boot-project/api-boot-autoconfigure/pom.xml @@ -156,6 +156,11 @@ minbox-security true + + org.minbox.framework + minbox-oss + true + diff --git a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/oss/ApiBootOssAutoConfiguration.java b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/oss/ApiBootOssAutoConfiguration.java index f95c4c68..a3439587 100644 --- a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/oss/ApiBootOssAutoConfiguration.java +++ b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/oss/ApiBootOssAutoConfiguration.java @@ -1,8 +1,9 @@ package org.minbox.framework.api.boot.autoconfigure.oss; import com.aliyun.oss.OSSClient; -import org.minbox.framework.api.boot.oss.ApiBootOssService; -import org.minbox.framework.api.boot.oss.progress.ApiBootObjectStorageProgress; +import org.minbox.framework.oss.ObjectStorageProgress; +import org.minbox.framework.oss.ObjectStorageService; +import org.minbox.framework.oss.support.aliyun.AliyunObjectStorageService; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -36,9 +37,9 @@ public class ApiBootOssAutoConfiguration { /** * ApiBoot Progress Provider */ - private ApiBootObjectStorageProgress apiBootObjectStorageProgress; + private ObjectStorageProgress apiBootObjectStorageProgress; - public ApiBootOssAutoConfiguration(ApiBootOssProperties apiBootOssProperties, ObjectProvider apiBootProgressProvider) { + public ApiBootOssAutoConfiguration(ApiBootOssProperties apiBootOssProperties, ObjectProvider apiBootProgressProvider) { this.apiBootOssProperties = apiBootOssProperties; this.apiBootObjectStorageProgress = apiBootProgressProvider.getIfAvailable(); } @@ -50,9 +51,9 @@ public ApiBootOssAutoConfiguration(ApiBootOssProperties apiBootOssProperties, Ob */ @Bean @ConditionalOnMissingBean - ApiBootOssService apiBootOssService() { - ApiBootOssService apiBootOssService = new ApiBootOssService(apiBootOssProperties.getRegion().getEndpoint(), apiBootOssProperties.getBucketName(), apiBootOssProperties.getAccessKeyId(), apiBootOssProperties.getAccessKeySecret(), apiBootOssProperties.getDomain()); - apiBootOssService.setApiBootObjectStorageProgress(apiBootObjectStorageProgress); - return apiBootOssService; + ObjectStorageService apiBootOssService() { + AliyunObjectStorageService objectStorageService = new AliyunObjectStorageService(apiBootOssProperties.getRegion().getEndpoint(), apiBootOssProperties.getBucketName(), apiBootOssProperties.getAccessKeyId(), apiBootOssProperties.getAccessKeySecret(), apiBootOssProperties.getDomain()); + objectStorageService.setObjectStorageProgress(apiBootObjectStorageProgress); + return objectStorageService; } } diff --git a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/oss/ApiBootOssProperties.java b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/oss/ApiBootOssProperties.java index b99d1ba1..240a0f75 100644 --- a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/oss/ApiBootOssProperties.java +++ b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/oss/ApiBootOssProperties.java @@ -1,7 +1,7 @@ package org.minbox.framework.api.boot.autoconfigure.oss; import lombok.Data; -import org.minbox.framework.api.boot.oss.OssRegion; +import org.minbox.framework.oss.OssRegion; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; diff --git a/api-boot-project/api-boot-dependencies/pom.xml b/api-boot-project/api-boot-dependencies/pom.xml index 15a6105f..c6c246b4 100644 --- a/api-boot-project/api-boot-dependencies/pom.xml +++ b/api-boot-project/api-boot-dependencies/pom.xml @@ -18,41 +18,18 @@ 5.2.7.RELEASE 2.3.1.RELEASE - 2.3.8.RELEASE - 1.1.0.RELEASE - 3.0.1.RELEASE - 1.0.5.RELEASE - 1.0.5.RELEASE - 1.0.0.RELEASE - 1.0.0.RELEASE - 1.0.0.RELEASE - 1.0.0.RELEASE - 1.0.0.RELEASE - 1.0.0.RELEASE - 1.0.0.RELEASE + 1.0.1-SNAPSHOT 1.0.5.RELEASE - 1.1.3.RELEASE - 1.0.7.RELEASE - 1.1.21 1.1.21 - 1.2.60 0.9.11 - 29.0-jre - 2.9.2 - 2.8.3 - 4.2.0 - 1.1.0 - 2.3.2 3.3.11 0.6.8 1.3.2 0.2.7 - 3.3.1 - 4.0.4 3.6.1 @@ -74,12 +51,11 @@ org.minbox.framework - minbox-dependencies - ${minbox.version} + minbox-bom + ${minbox-bom.version} import pom - com.alibaba @@ -92,114 +68,12 @@ ${nacos.config.version} - - - org.springframework - spring-tx - ${spring.version} - - - org.springframework.security.oauth - spring-security-oauth2 - ${security.oauth2.version} - - - org.springframework.security - spring-security-jwt - ${spring.security.jwt.version} - - - org.springframework.data - spring-data-mongodb - ${spring-data-mongodb.version} - - - - - org.minbox.framework - minbox-web - ${minbox.version} - - - org.minbox.framework - minbox-core - ${minbox.version} - - - org.minbox.framework - minbox-logging-admin - ${minbox-logging.version} - - - org.minbox.framework - minbox-logging-admin-ui - ${minbox-logging.version} - - - org.minbox.framework - minbox-logging-client - ${minbox-logging.version} - - - org.minbox.framework - minbox-logging-spring-context - ${minbox-logging.version} - - - org.minbox.framework - minbox-mongo-client-settings - ${minbox-mongo-client-settings.version} - + com.gitee.hengboy code-builder-core ${code.builder.core.version} - - com.gitee.hengboy - mybatis-pageable-core - ${mybatis.pageable.core.version} - - - com.gitee.hengboy - mybatis-enhance-core - ${mybatis-enhance.version} - - - com.gitee.hengboy - mybatis-enhance-dsl - ${mybatis-enhance.version} - - - org.minbox.framework - minbox-ratelimiter - ${minbox-ratelimiter.version} - - - org.minbox.framework - minbox-resource-load - ${minbox-resource-load.version} - - - org.minbox.framework - minbox-datasource-switch - ${minbox-datasource-switch.version} - - - org.minbox.framework - minbox-sequence - ${minbox-sequence.version} - - - org.minbox.framework - minbox-oauth - ${minbox-oauth.version} - - - org.minbox.framework - minbox-security - ${minbox-security.version} - @@ -319,26 +193,11 @@ - - com.alibaba - fastjson - ${fastjson.version} - - - com.alibaba - druid - ${druid.version} - org.reflections reflections ${reflections.version} - - com.google.guava - guava - ${guava.version} - org.apache.maven maven-plugin-api @@ -349,41 +208,6 @@ maven-plugin-annotations ${maven-plugin-annotations.version} - - io.springfox - springfox-swagger-ui - ${swagger.version} - - - io.springfox - springfox-swagger2 - ${swagger.version} - - - io.springfox - springfox-bean-validators - ${swagger.version} - - - com.aliyun.oss - aliyun-sdk-oss - ${alibaba.oss.version} - - - com.aliyun - aliyun-java-sdk-core - ${aliyun.sdk.core.version} - - - com.aliyun - aliyun-java-sdk-dysmsapi - ${aliyun.sdk.dysmsapi.version} - - - org.quartz-scheduler - quartz - ${quartz.version} - cn.jpush.api jpush-client @@ -394,21 +218,11 @@ codegen ${mysema.codegen.version} - - com.aliyun - aliyun-java-sdk-dm - ${aliyun-java-sdk-dm.version} - javax.annotation javax.annotation-api ${javax-annotation-api.version} - - org.mongodb - mongodb-driver-sync - ${mongo-driver-sync.version} - diff --git a/api-boot-project/api-boot-starters/api-boot-starter-alibaba-oss/pom.xml b/api-boot-project/api-boot-starters/api-boot-starter-alibaba-oss/pom.xml index 8ff58d47..fd758077 100644 --- a/api-boot-project/api-boot-starters/api-boot-starter-alibaba-oss/pom.xml +++ b/api-boot-project/api-boot-starters/api-boot-starter-alibaba-oss/pom.xml @@ -28,15 +28,13 @@ HEAD - org.minbox.framework api-boot-starter - - com.aliyun.oss - aliyun-sdk-oss + org.minbox.framework + minbox-oss diff --git a/api-boot-project/api-boot/pom.xml b/api-boot-project/api-boot/pom.xml index 3aadd22b..9c62b6b6 100644 --- a/api-boot-project/api-boot/pom.xml +++ b/api-boot-project/api-boot/pom.xml @@ -89,11 +89,6 @@ compile true - - com.aliyun.oss - aliyun-sdk-oss - true - com.aliyun aliyun-java-sdk-core diff --git a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/ApiBootOssService.java b/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/ApiBootOssService.java deleted file mode 100644 index 9385d9e6..00000000 --- a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/ApiBootOssService.java +++ /dev/null @@ -1,267 +0,0 @@ -package org.minbox.framework.api.boot.oss; - -import com.aliyun.oss.OSSClient; -import com.aliyun.oss.model.*; -import lombok.Setter; -import org.minbox.framework.api.boot.oss.progress.ApiBootObjectStorageProgress; -import org.minbox.framework.api.boot.oss.progress.OssProgressListener; -import org.minbox.framework.api.boot.storage.ApiBootObjectStorageService; -import org.minbox.framework.api.boot.storage.exception.ApiBootObjectStorageException; -import org.minbox.framework.api.boot.storage.response.ApiBootObjectStorageResponse; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * Ospi file operation class provided by ApiBoot - * - * @author 恒宇少年 - */ -public class ApiBootOssService implements ApiBootObjectStorageService { - /** - * region endpoint - */ - protected String endpoint; - /** - * Storage name - */ - protected String bucketName; - /** - * Alibaba Cloud account authorization id - */ - protected String accessKeyId; - /** - * Alibaba Cloud account authorization secret - */ - protected String accessKeySecret; - /** - * customer domain name - */ - protected String domain; - /** - * ApiBoot Oss Progress - */ - @Setter - private ApiBootObjectStorageProgress apiBootObjectStorageProgress; - - /** - * Initialize global variables using constructor - * - * @param endpoint {@link #endpoint} - * @param bucketName {@link #bucketName} - * @param accessKeyId {@link #accessKeyId} - * @param accessKeySecret {@link #accessKeySecret} - * @param domain {@link #domain} - */ - public ApiBootOssService(String endpoint, String bucketName, String accessKeyId, String accessKeySecret, String domain) { - this.endpoint = endpoint; - this.bucketName = bucketName; - this.accessKeyId = accessKeyId; - this.accessKeySecret = accessKeySecret; - this.domain = domain; - } - - @Override - public ApiBootObjectStorageResponse upload(String objectName, byte[] bytes) throws ApiBootObjectStorageException { - try { - OSSClient ossClient = getOssClient(); - // put byte inputStream - ossClient.putObject(new PutObjectRequest(bucketName, objectName, new ByteArrayInputStream(bytes)).withProgressListener(new OssProgressListener(objectName, apiBootObjectStorageProgress))); - closeOssClient(ossClient); - } catch (Exception e) { - throw new ApiBootObjectStorageException(e.getMessage(), e); - } - return ApiBootObjectStorageResponse.builder().objectName(objectName).objectUrl(getObjectUrl(objectName)).build(); - } - - @Override - public ApiBootObjectStorageResponse upload(String objectName, InputStream inputStream) throws ApiBootObjectStorageException { - try { - OSSClient ossClient = getOssClient(); - // put byte inputStream - ossClient.putObject(new PutObjectRequest(bucketName, objectName, inputStream).withProgressListener(new OssProgressListener(objectName, apiBootObjectStorageProgress))); - closeOssClient(ossClient); - } catch (Exception e) { - throw new ApiBootObjectStorageException(e.getMessage(), e); - } - return ApiBootObjectStorageResponse.builder().objectName(objectName).objectUrl(getObjectUrl(objectName)).build(); - } - - @Override - public ApiBootObjectStorageResponse upload(String objectName, String localFile) throws ApiBootObjectStorageException { - try { - OSSClient ossClient = getOssClient(); - // put byte inputStream - ossClient.putObject(new PutObjectRequest(bucketName, objectName, new File(localFile)).withProgressListener(new OssProgressListener(objectName, apiBootObjectStorageProgress))); - closeOssClient(ossClient); - } catch (Exception e) { - throw new ApiBootObjectStorageException(e.getMessage(), e); - } - return ApiBootObjectStorageResponse.builder().objectName(objectName).objectUrl(getObjectUrl(objectName)).build(); - } - - @Override - public void download(String objectName, String localFile) throws ApiBootObjectStorageException { - try { - OSSClient ossClient = getOssClient(); - ossClient.getObject(new GetObjectRequest(bucketName, objectName).withProgressListener(new OssProgressListener(objectName, apiBootObjectStorageProgress)), new File(localFile)); - closeOssClient(ossClient); - } catch (Exception e) { - throw new ApiBootObjectStorageException(e.getMessage(), e); - } - } - - @Override - public void delete(String objectName) throws ApiBootObjectStorageException { - try { - OSSClient ossClient = getOssClient(); - ossClient.deleteObject(bucketName, objectName); - closeOssClient(ossClient); - } catch (Exception e) { - throw new ApiBootObjectStorageException(e.getMessage(), e); - } - } - - /** - * multi part upload file - * with local file - * - * @param objectName object name - * @param uploadFile upload file - * @param partSize every part size - * @return ApiBootObjectStorageResponse - * @throws ApiBootObjectStorageException ApiBoot Oss Exception - */ - public ApiBootObjectStorageResponse multipartUpload(String objectName, File uploadFile, long partSize) throws ApiBootObjectStorageException { - try { - OSSClient ossClient = getOssClient(); - - // init multi part upload request - InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, objectName); - - // get upload id - InitiateMultipartUploadResult result = ossClient.initiateMultipartUpload(request); - String uploadId = result.getUploadId(); - List partETags = new ArrayList(); - // local file length - long fileLength = uploadFile.length(); - // part count - int partCount = (int) (fileLength / partSize); - - if (fileLength % partSize != 0) { - partCount++; - } - - for (int i = 0; i < partCount; i++) { - // start position - long startPos = i * partSize; - // current part size - long curPartSize = (i + 1 == partCount) ? (fileLength - startPos) : partSize; - - InputStream is = new FileInputStream(uploadFile); - is.skip(startPos); - - UploadPartRequest uploadPartRequest = new UploadPartRequest(); - uploadPartRequest.setBucketName(bucketName); - uploadPartRequest.setKey(objectName); - uploadPartRequest.setUploadId(uploadId); - uploadPartRequest.setInputStream(is); - // set part size - uploadPartRequest.setPartSize(curPartSize); - // set part number - uploadPartRequest.setPartNumber(i + 1); - - // execute upload part - UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest); - partETags.add(uploadPartResult.getPartETag()); - } - - // sort by part number - Collections.sort(partETags, Comparator.comparingInt(PartETag::getPartNumber)); - - // merge upload part file - CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, objectName, uploadId, partETags); - ossClient.completeMultipartUpload(completeMultipartUploadRequest); - closeOssClient(ossClient); - } catch (Exception e) { - throw new ApiBootObjectStorageException(e.getMessage(), e); - } - return ApiBootObjectStorageResponse.builder().objectName(objectName).objectUrl(getObjectUrl(objectName)).build(); - } - - /** - * multi part upload file - * with local file string path - * - * @param objectName object name - * @param localFile local file - * @param partSize every part size - * @return ApiBootObjectStorageResponse - * @throws ApiBootObjectStorageException ApiBoot Oss Exception - * @see PartSize - */ - public ApiBootObjectStorageResponse multipartUpload(String objectName, String localFile, long partSize) throws ApiBootObjectStorageException { - // load local file - File uploadFile = new File(localFile); - // execute multi part upload file - return multipartUpload(objectName, uploadFile, partSize); - } - - /** - * get oss client instance - * - * @return {@link OSSClient} - * @throws ApiBootObjectStorageException ApiBoot Oss Exception - */ - protected OSSClient getOssClient() throws ApiBootObjectStorageException { - try { - OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); - return ossClient; - } catch (Exception e) { - throw new ApiBootObjectStorageException("获取OssClient对象异常.", e); - } - } - - /** - * close given oss client instance - * - * @param ossClient {@link OSSClient} - * @throws ApiBootObjectStorageException 对象存储异常对象 - */ - protected void closeOssClient(OSSClient ossClient) throws ApiBootObjectStorageException { - ossClient.shutdown(); - } - - /** - * get the default file address - * Use Alibaba Cloud endpoint external network address for combination - * - * @param objectName file name - * @return the default object url - */ - protected String getDefaultObjectUrl(String objectName) { - return String.format("https://%s.%s/%s", bucketName, endpoint.replace("http://", ""), objectName); - } - - /** - * get upload file path - * If the address is configured, use the custom configuration address, otherwise use the default address - * - * @param objectName file name - * @return file access address - */ - protected String getObjectUrl(String objectName) { - if (domain != null && domain.length() > 0) { - return String.format(domain + "/%s", objectName); - } - return getDefaultObjectUrl(objectName); - } - - -} diff --git a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/OssRegion.java b/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/OssRegion.java deleted file mode 100644 index ad489fb1..00000000 --- a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/OssRegion.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.minbox.framework.api.boot.oss; - -import lombok.Getter; - -/** - * Alibaba Cloud Oss Region - * - * @author 恒宇少年 - */ -@Getter -public enum OssRegion { - /** - * 华东1(杭州) - */ - hangzhou("http://oss-cn-hangzhou.aliyuncs.com"), - /** - * 华东2(上海) - */ - shanghai("http://oss-cn-shanghai.aliyuncs.com"), - /** - * 华北1(青岛) - */ - qingdao("http://oss-cn-qingdao.aliyuncs.com"), - /** - * 华北2(北京) - */ - beijing("http://oss-cn-beijing.aliyuncs.com"), - /** - * 华北3(张家口) - */ - zhangjiakou("http://oss-cn-zhangjiakou.aliyuncs.com"), - /** - * 华北5(呼和浩特) - */ - huhehaote("http://oss-cn-huhehaote.aliyuncs.com"), - /** - * 华南1(深圳) - */ - shenzhen("http://oss-cn-shenzhen.aliyuncs.com"), - /** - * 西南(成都) - */ - chengdu("http://oss-cn-chengdu.aliyuncs.com"), - /** - * 香港 - */ - hongkong("http://oss-cn-hongkong.aliyuncs.com"), - /** - * 美国西部1(硅谷) - */ - uswest("http://oss-us-west-1.aliyuncs.com"), - /** - * 美国东部1(弗吉尼亚) - */ - useast("http://oss-us-east-1.aliyuncs.com"), - /** - * 亚太东南1(新加坡) - */ - apsoutheast1("http://oss-ap-southeast-1.aliyuncs.com"), - /** - * 亚太东南2(悉尼) - */ - apsoutheast2("http://oss-ap-southeast-2.aliyuncs.com"), - /** - * 亚太东南3(吉隆坡) - */ - apsoutheast3("http://oss-ap-southeast-3.aliyuncs.com"), - /** - * 亚太东南5 (雅加达) - */ - apsoutheast5("http://oss-ap-southeast-5.aliyuncs.com"), - /** - * 亚太东北1(日本) - */ - apnortheast1("http://oss-ap-northeast-1.aliyuncs.com"), - /** - * 亚太南部1(孟买) - */ - apsouth1("http://oss-ap-south-1.aliyuncs.com"), - /** - * 欧洲中部1(法兰克福) - */ - eucentral1("http://oss-eu-central-1.aliyuncs.com"), - /** - * 英国(伦敦) - */ - euwest1("http://oss-eu-west-1.aliyuncs.com"), - /** - * 中东东部1(迪拜) - */ - meeast1("http://oss-me-east-1.aliyuncs.com"); - - OssRegion(String endpoint) { - this.endpoint = endpoint; - } - - /** - * 外网endpoint - */ - private String endpoint; -} diff --git a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/PartSize.java b/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/PartSize.java deleted file mode 100644 index ab0a3a3d..00000000 --- a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/PartSize.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright [2019] [恒宇少年 - 于起宇] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.minbox.framework.api.boot.oss; - -/** - * File size unit - * - * @author 恒宇少年 - */ -public interface PartSize { - /** - * kb - */ - long KB = 1024; - /** - * mb - */ - long MB = KB * 1024L; - /** - * gb - */ - long GB = MB * 1024L; - /** - * tb - */ - long TB = GB * 1024L; -} diff --git a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/progress/ApiBootObjectStorageProgress.java b/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/progress/ApiBootObjectStorageProgress.java deleted file mode 100644 index 6c022ae8..00000000 --- a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/progress/ApiBootObjectStorageProgress.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright [2019] [恒宇少年 - 于起宇] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.minbox.framework.api.boot.oss.progress; - - -import org.minbox.framework.api.boot.storage.exception.ApiBootObjectStorageException; - -/** - * ApiBoot Oss Upload and Download Progress - * - * @author 恒宇少年 - */ -public interface ApiBootObjectStorageProgress { - /** - * progress - * - * @param objectName object name - * @param percent upload or download progress percent - * @param totalBytes total bytes - * @param currentWrittenBytes already written bytes - * @throws ApiBootObjectStorageException ApiBoot Oss Exception - */ - void progress(String objectName, double percent, long totalBytes, long currentWrittenBytes) throws ApiBootObjectStorageException; - - /** - * upload or download success - * - * @param objectName object name - * @throws ApiBootObjectStorageException ApiBoot Oss Exception - */ - void success(String objectName) throws ApiBootObjectStorageException; - - /** - * upload or download failed - * - * @param objectName object name - * @throws ApiBootObjectStorageException ApiBoot Oss Exception - */ - void failed(String objectName) throws ApiBootObjectStorageException; -} diff --git a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/progress/OssProgressListener.java b/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/progress/OssProgressListener.java deleted file mode 100644 index f8a64d1f..00000000 --- a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/oss/progress/OssProgressListener.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright [2019] [恒宇少年 - 于起宇] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.minbox.framework.api.boot.oss.progress; - - -import com.aliyun.oss.event.ProgressEvent; -import com.aliyun.oss.event.ProgressEventType; -import com.aliyun.oss.event.ProgressListener; - -import java.math.BigDecimal; - -/** - * ApiBoot Oss Progress Listener - * - * @author 恒宇少年 - */ -public class OssProgressListener implements ProgressListener { - /** - * already write bytes - */ - private long bytesWritten = 0; - /** - * file total bytes - */ - private long totalBytes = -1; - /** - * percent scale - */ - private int percentScale = 2; - /** - * oss object name - */ - private String objectName; - /** - * ApiBoot Progress - */ - private ApiBootObjectStorageProgress apiBootObjectStorageProgress; - - public OssProgressListener(String objectName, ApiBootObjectStorageProgress apiBootObjectStorageProgress) { - this.objectName = objectName; - this.apiBootObjectStorageProgress = apiBootObjectStorageProgress; - } - - @Override - public void progressChanged(ProgressEvent progressEvent) { - if (apiBootObjectStorageProgress != null) { - // current progress bytes - long bytes = progressEvent.getBytes(); - // progress event type - ProgressEventType eventType = progressEvent.getEventType(); - - switch (eventType) { - // sent file total bytes - case REQUEST_CONTENT_LENGTH_EVENT: - this.totalBytes = bytes; - break; - // request byte transfer - case REQUEST_BYTE_TRANSFER_EVENT: - this.bytesWritten += bytes; - if (this.totalBytes != -1) { - // Calculation percent - double percent = (this.bytesWritten * 100.00 / this.totalBytes); - BigDecimal decimal = BigDecimal.valueOf(percent).setScale(percentScale, BigDecimal.ROUND_DOWN); - apiBootObjectStorageProgress.progress(objectName, decimal.doubleValue(), this.totalBytes, this.bytesWritten); - } - break; - // complete - case TRANSFER_COMPLETED_EVENT: - apiBootObjectStorageProgress.success(objectName); - break; - // failed - case TRANSFER_FAILED_EVENT: - apiBootObjectStorageProgress.failed(objectName); - break; - default: - break; - } - } - } -} diff --git a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/ApiBootObjectStorageService.java b/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/ApiBootObjectStorageService.java deleted file mode 100644 index 5fc871b6..00000000 --- a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/ApiBootObjectStorageService.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.minbox.framework.api.boot.storage; - - -import org.minbox.framework.api.boot.storage.exception.ApiBootObjectStorageException; -import org.minbox.framework.api.boot.storage.response.ApiBootObjectStorageResponse; - -import java.io.InputStream; - -/** - * ApiBoot Object Storage Interface Definition - * - * @author 恒宇少年 - */ -public interface ApiBootObjectStorageService { - /** - * byte array upload file - * - * @param objectName file name - * @param bytes file byte array - * @return {@link ApiBootObjectStorageResponse} - * @throws ApiBootObjectStorageException object storage exception - */ - ApiBootObjectStorageResponse upload(String objectName, byte[] bytes) throws ApiBootObjectStorageException; - - /** - * input stream upload file - * - * @param objectName file name - * @param inputStream file input stream - * @return {@link ApiBootObjectStorageResponse} - * @throws ApiBootObjectStorageException object storage exception - */ - ApiBootObjectStorageResponse upload(String objectName, InputStream inputStream) throws ApiBootObjectStorageException; - - /** - * local path upload file - * - * @param objectName file name - * @param localFile file local path - * @return {@link ApiBootObjectStorageResponse} - * @throws ApiBootObjectStorageException object storage exception - */ - ApiBootObjectStorageResponse upload(String objectName, String localFile) throws ApiBootObjectStorageException; - - /** - * download file - * - * @param objectName file name in the object store - * @param localFile file local path - * @throws ApiBootObjectStorageException object storage exception - */ - void download(String objectName, String localFile) throws ApiBootObjectStorageException; - - /** - * delete file - * - * @param objectName file name in the object store - * @throws ApiBootObjectStorageException object storage exception - */ - void delete(String objectName) throws ApiBootObjectStorageException; -} diff --git a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/exception/ApiBootObjectStorageException.java b/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/exception/ApiBootObjectStorageException.java deleted file mode 100644 index da455c5e..00000000 --- a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/exception/ApiBootObjectStorageException.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.minbox.framework.api.boot.storage.exception; - -import lombok.NoArgsConstructor; - -/** - * Object storage exception - * extend from {@link RuntimeException} - * - * @author 恒宇少年 - */ -@NoArgsConstructor -public class ApiBootObjectStorageException extends RuntimeException { - public ApiBootObjectStorageException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/response/ApiBootObjectStorageResponse.java b/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/response/ApiBootObjectStorageResponse.java deleted file mode 100644 index 911c32d3..00000000 --- a/api-boot-project/api-boot/src/main/java/org/minbox/framework/api/boot/storage/response/ApiBootObjectStorageResponse.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.minbox.framework.api.boot.storage.response; - -import lombok.Builder; -import lombok.Data; - -/** - * ApiBoot object storage response entity - * - * @author 恒宇少年 - */ -@Data -@Builder -public class ApiBootObjectStorageResponse { - /** - * file name - */ - private String objectName; - /** - * file request url - */ - private String objectUrl; -} diff --git a/api-boot-samples/api-boot-sample-alibaba-oss/src/main/java/org/minbox/framework/api/boot/sample/ApiBootOssOverrideService.java b/api-boot-samples/api-boot-sample-alibaba-oss/src/main/java/org/minbox/framework/api/boot/sample/ApiBootOssOverrideService.java index 3df93bda..aba96a7d 100644 --- a/api-boot-samples/api-boot-sample-alibaba-oss/src/main/java/org/minbox/framework/api/boot/sample/ApiBootOssOverrideService.java +++ b/api-boot-samples/api-boot-sample-alibaba-oss/src/main/java/org/minbox/framework/api/boot/sample/ApiBootOssOverrideService.java @@ -2,7 +2,7 @@ import com.aliyun.oss.OSSClient; import com.aliyun.oss.model.Bucket; -import org.minbox.framework.api.boot.oss.ApiBootOssService; +import org.minbox.framework.oss.support.aliyun.AliyunObjectStorageService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,7 +16,7 @@ * Gitee:https://gitee.com/hengboy * GitHub:https://github.com/hengboy */ -public class ApiBootOssOverrideService extends ApiBootOssService { +public class ApiBootOssOverrideService extends AliyunObjectStorageService { /** * logger instance */ diff --git a/api-boot-samples/api-boot-sample-alibaba-oss/src/test/java/org/minbox/framework/api/boot/sample/ApiBootOssTest.java b/api-boot-samples/api-boot-sample-alibaba-oss/src/test/java/org/minbox/framework/api/boot/sample/ApiBootOssTest.java index 33279caf..76d1f3b7 100644 --- a/api-boot-samples/api-boot-sample-alibaba-oss/src/test/java/org/minbox/framework/api/boot/sample/ApiBootOssTest.java +++ b/api-boot-samples/api-boot-sample-alibaba-oss/src/test/java/org/minbox/framework/api/boot/sample/ApiBootOssTest.java @@ -2,8 +2,8 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.minbox.framework.api.boot.oss.ApiBootOssService; -import org.minbox.framework.api.boot.storage.response.ApiBootObjectStorageResponse; +import org.minbox.framework.oss.ObjectStorageResponse; +import org.minbox.framework.oss.ObjectStorageService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +36,7 @@ public class ApiBootOssTest { * 注入ApiBoot内置Oss Service */ @Autowired - private ApiBootOssService apiBootOssService; + private ObjectStorageService apiBootOssService; /** * 注入自定义Oss Service */ @@ -48,7 +48,7 @@ public class ApiBootOssTest { */ @Test public void uploadBytes() { - ApiBootObjectStorageResponse response = apiBootOssService.upload("admin.txt", "admin".getBytes()); + ObjectStorageResponse response = apiBootOssService.upload("admin.txt", "admin".getBytes()); logger.info("文件名称:{}", response.getObjectName()); logger.info("文件访问路径:{}", response.getObjectUrl()); } @@ -58,7 +58,7 @@ public void uploadBytes() { */ @Test public void uploadFile() { - ApiBootObjectStorageResponse response = apiBootOssService.upload("ApiBoot Security Oauth内存方式集成.mp4", "/Users/yuqiyu/Movies/ApiBoot/ApiBoot Security Oauth内存方式集成.mp4"); + ObjectStorageResponse response = apiBootOssService.upload("ApiBoot Security Oauth内存方式集成.mp4", "/Users/yuqiyu/Movies/ApiBoot/ApiBoot Security Oauth内存方式集成.mp4"); logger.info("文件名称:{}", response.getObjectName()); logger.info("文件访问路径:{}", response.getObjectUrl()); } @@ -71,7 +71,7 @@ public void uploadFile() { @Test public void uploadInputStream() throws Exception { FileInputStream inputStream = new FileInputStream(new File("/Users/yuqiyu/Downloads/update-release-v10102.apk")); - ApiBootObjectStorageResponse response = apiBootOssService.upload("update-release-v10102.apk", inputStream); + ObjectStorageResponse response = apiBootOssService.upload("update-release-v10102.apk", inputStream); logger.info("文件名称:{}", response.getObjectName()); logger.info("文件访问路径:{}", response.getObjectUrl()); } From 72afd0a12c97c1b5ec74c9955643534a8aa652c3 Mon Sep 17 00:00:00 2001 From: hengboy Date: Wed, 22 Jul 2020 21:28:52 +0800 Subject: [PATCH 2/7] Create v2.3.1 SNAPSHOT version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 37832cf1..a86cd096 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ ${revision} ApiBoot Build - 2.3.0.RELEASE + 2.3.1-SNAPSHOT 3.5.1 1.8 UTF-8 From 7593163d090205ba85156e9f948ea4e167eb95ff Mon Sep 17 00:00:00 2001 From: hengboy Date: Wed, 22 Jul 2020 21:31:09 +0800 Subject: [PATCH 3/7] Adapt "minbox-parent" --- pom.xml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index a86cd096..9368541f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,9 +4,9 @@ 4.0.0 org.minbox.framework - oss-parent - 0.2.0.RELEASE - ../oss-parent + minbox-parent + 1.0.0.RELEASE + pom @@ -19,7 +19,6 @@ ApiBoot Build 2.3.1-SNAPSHOT - 3.5.1 1.8 UTF-8 UTF-8 @@ -51,7 +50,6 @@ org.apache.maven.plugins maven-compiler-plugin - ${maven-compiler-plugin.version} ${jdk.version} ${jdk.version} From 954542f4521714f32192249915a09d6841c91328 Mon Sep 17 00:00:00 2001 From: hengboy Date: Wed, 29 Jul 2020 08:57:42 +0800 Subject: [PATCH 4/7] [#46] fix bug --- .../security/ApiBootWebSecurityAutoConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/security/ApiBootWebSecurityAutoConfiguration.java b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/security/ApiBootWebSecurityAutoConfiguration.java index 7cf8907f..7aa265dc 100644 --- a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/security/ApiBootWebSecurityAutoConfiguration.java +++ b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/security/ApiBootWebSecurityAutoConfiguration.java @@ -23,6 +23,7 @@ import org.springframework.security.web.access.AccessDeniedHandler; import org.springframework.util.ObjectUtils; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -54,7 +55,7 @@ public ApiBootWebSecurityAutoConfiguration(ApiBootSecurityProperties apiBootSecu */ @Override protected List configureIgnoreUrls() { - List ignoringUrls = Arrays.asList(ApiBootSecurityProperties.DEFAULT_IGNORE_URLS); + List ignoringUrls = new ArrayList(Arrays.asList(ApiBootSecurityProperties.DEFAULT_IGNORE_URLS)); if (!ObjectUtils.isEmpty(apiBootSecurityProperties.getIgnoringUrls())) { ignoringUrls.addAll(Arrays.asList(apiBootSecurityProperties.getIgnoringUrls())); } From 40dce0dcba1565dfd5b1310da9b3a10fb1458b49 Mon Sep 17 00:00:00 2001 From: hengboy Date: Wed, 29 Jul 2020 09:15:58 +0800 Subject: [PATCH 5/7] Update the notification email built by ci --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f0db3fc5..438f6d50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,4 +26,7 @@ after_success: - bash <(curl -s https://codecov.io/bash) notifications: email: - - jnyuqy@gmail.com + recipients: + - apiboot@minbox.org + on_success: change + on_failure: always From 3a7eee4fdd1a605af412d3985a76c78e07707acd Mon Sep 17 00:00:00 2001 From: hengboy Date: Wed, 29 Jul 2020 09:19:53 +0800 Subject: [PATCH 6/7] Update git clone address --- README.md | 2 +- README.zh-CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 816c6f3f..e4718cbc 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ The official version of ApiBoot will be released to Maven Center. If you want to ```sh # Download master branch source code to local -➜ git clone https://gitee.com/minbox-projects/api-boot.git +➜ git clone https://github.com/minbox-projects/api-boot.git ➜ cd api-boot # install ➜ mvn clean install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dgpg.skip diff --git a/README.zh-CN.md b/README.zh-CN.md index 0f595f25..4750cdd0 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -97,7 +97,7 @@ ApiBoot正式版本都会发布到Maven Center,如果你想使用源码最新 ```sh # 下载master分支源码到本地 -➜ git clone https://gitee.com/minbox-projects/api-boot.git +➜ git clone https://github.com/minbox-projects/api-boot.git # 进入api-boot源码根目录 ➜ cd api-boot # 执行安装 From f75ff81b32000a76359019fe8241ff6f97d0d947 Mon Sep 17 00:00:00 2001 From: hengboy Date: Mon, 3 Aug 2020 09:58:02 +0800 Subject: [PATCH 7/7] Add "LoggingFactoryBeanCustomizers" --- .../ApiBootLoggingAutoConfiguration.java | 19 ++++++---- .../LoggingFactoryBeanCustomizers.java | 37 +++++++++++++++++++ .../logging/AppendIgnorePathCustomizer.java | 21 +++++++++++ 3 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/LoggingFactoryBeanCustomizers.java create mode 100644 api-boot-samples/api-boot-sample-logging/src/main/java/org/minbox/framework/api/boot/sample/logging/AppendIgnorePathCustomizer.java diff --git a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/ApiBootLoggingAutoConfiguration.java b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/ApiBootLoggingAutoConfiguration.java index 4b82ad70..3e866abf 100644 --- a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/ApiBootLoggingAutoConfiguration.java +++ b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/ApiBootLoggingAutoConfiguration.java @@ -25,6 +25,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer; +import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -38,6 +40,7 @@ import org.springframework.util.ObjectUtils; import java.util.List; +import java.util.stream.Collectors; import static org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingProperties.API_BOOT_LOGGING_PREFIX; @@ -74,18 +77,24 @@ public ApiBootLoggingAutoConfiguration(ApiBootLoggingProperties apiBootLoggingPr this.apiBootLoggingProperties = apiBootLoggingProperties; } + @Bean + @ConditionalOnMissingBean + public LoggingFactoryBeanCustomizers loggingFactoryBeanCustomizers(ObjectProvider customizers) { + return new LoggingFactoryBeanCustomizers(customizers.orderedStream().collect(Collectors.toList())); + } + /** * logging factory bean * {@link LoggingFactoryBean} * * @param loggingAdminDiscoveryObjectProvider Logging Admin Discovery Instance Provider - * @param customizerObjectProvider LoggingFactory Bean Customizer + * @param customizers LoggingFactory Bean Customizers * @return LoggingFactoryBean */ @Bean @ConditionalOnMissingBean public LoggingFactoryBean loggingFactoryBean(ObjectProvider loggingAdminDiscoveryObjectProvider, - ObjectProvider> customizerObjectProvider) { + LoggingFactoryBeanCustomizers customizers) { LoggingFactoryBean factoryBean = new LoggingFactoryBean(); factoryBean.setIgnorePaths(apiBootLoggingProperties.getIgnorePaths()); factoryBean.setIgnoreHttpStatus(apiBootLoggingProperties.getIgnoreHttpStatus()); @@ -97,12 +106,8 @@ public LoggingFactoryBean loggingFactoryBean(ObjectProvider customizers = customizerObjectProvider.getIfAvailable(); - if (!ObjectUtils.isEmpty(customizers)) { - customizers.stream().forEach(customizer -> customizer.customize(factoryBean)); - } logger.info("【LoggingFactoryBean】init successfully."); - return factoryBean; + return customizers.customize(factoryBean); } /** diff --git a/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/LoggingFactoryBeanCustomizers.java b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/LoggingFactoryBeanCustomizers.java new file mode 100644 index 00000000..f810ffa1 --- /dev/null +++ b/api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/LoggingFactoryBeanCustomizers.java @@ -0,0 +1,37 @@ +package org.minbox.framework.api.boot.autoconfigure.logging; + +import org.minbox.framework.logging.client.LoggingFactoryBean; +import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer; +import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers; +import org.springframework.boot.util.LambdaSafe; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * The {@link LoggingFactoryBeanCustomizer} collection processing class + * + * @author 恒宇少年 + */ +public class LoggingFactoryBeanCustomizers { + private List customizers; + + public LoggingFactoryBeanCustomizers(List customizers) { + this.customizers = (customizers != null) ? new ArrayList<>(customizers) : Collections.emptyList(); + } + + /** + * Customize the specified {@link LoggingFactoryBean}. Locates all + * {@link LoggingFactoryBeanCustomizer} beans able to handle the specified instance and + * invoke {@link LoggingFactoryBeanCustomizer#customize(LoggingFactoryBean)} on them. + * + * @param factoryBean the logging factory bean to customize + * @return the factory bean + */ + public LoggingFactoryBean customize(LoggingFactoryBean factoryBean) { + LambdaSafe.callbacks(LoggingFactoryBeanCustomizer.class, this.customizers, factoryBean) + .withLogger(LoggingFactoryBeanCustomizer.class).invoke((customizer) -> customizer.customize(factoryBean)); + return factoryBean; + } +} diff --git a/api-boot-samples/api-boot-sample-logging/src/main/java/org/minbox/framework/api/boot/sample/logging/AppendIgnorePathCustomizer.java b/api-boot-samples/api-boot-sample-logging/src/main/java/org/minbox/framework/api/boot/sample/logging/AppendIgnorePathCustomizer.java new file mode 100644 index 00000000..545655af --- /dev/null +++ b/api-boot-samples/api-boot-sample-logging/src/main/java/org/minbox/framework/api/boot/sample/logging/AppendIgnorePathCustomizer.java @@ -0,0 +1,21 @@ +package org.minbox.framework.api.boot.sample.logging; + +import org.minbox.framework.api.boot.autoconfigure.logging.LoggingFactoryBeanCustomizer; +import org.minbox.framework.logging.client.LoggingFactoryBean; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * {@link LoggingFactoryBeanCustomizer}实现类 + * 新增排除日志拦截输出的路径 + * + * @author 恒宇少年 + */ +@Component +@Order(2) +public class AppendIgnorePathCustomizer implements LoggingFactoryBeanCustomizer { + @Override + public void customize(LoggingFactoryBean factoryBean) { + factoryBean.getIgnorePaths().add("/test"); + } +}