From 65d968f68d0c25dcedc072a49660bca0481f5911 Mon Sep 17 00:00:00 2001 From: eaglelihh <62682219+eaglelihh@users.noreply.github.com> Date: Sun, 10 Sep 2023 11:09:21 +0800 Subject: [PATCH] [ISSUE-2992][Improve] Using code style & quality rules to improve org.apache.streampark.console.base.config package of streampark-console module. (#3012) * extract string as constant * code style format * define it directly instead of using constants * code correction * Update OpenapiConfig.java * Update WebMvcConfig.java --------- Co-authored-by: lihui Co-authored-by: benjobs --- .../console/base/config/OpenapiConfig.java | 22 +++++++++++++------ .../console/base/config/WebMvcConfig.java | 12 +++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/OpenapiConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/OpenapiConfig.java index aa5ec0185e..fd783986bd 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/OpenapiConfig.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/OpenapiConfig.java @@ -40,20 +40,27 @@ @ConditionalOnWebApplication public class OpenapiConfig implements WebMvcConfigurer { + private static final String OPEN_API_INFO_OVERVIEW = "Apache StreamPark Api Docs"; + private static final String OPEN_API_INFO_VERSION = "2.2.0-SNAPSHOT"; + private static final String OPEN_API_INFO_LICENSE_NAME = "Apache-2.0 license"; + private static final String OPEN_API_INFO_CONTACT_NAME = "Apache StreamPark"; + private static final String OPEN_API_INFO_CONTACT_URL = "https://streampark.apache.org"; + private static final String OPEN_API_INFO_CONTACT_EMAIL = "dev@streampark.apache.org"; + @Bean public OpenAPI apiV1Info() { return new OpenAPI() .info( new Info() - .title("Apache StreamPark Api Docs") - .description("Apache StreamPark Api Docs") + .title(OPEN_API_INFO_OVERVIEW) + .description(OPEN_API_INFO_OVERVIEW) .contact( new Contact() - .name("Apache StreamPark") - .url("https://streampark.apache.org/") - .email("dev@streampark.apache.org")) - .version("2.2.0-SNAPSHOT") - .license(new License().name("Apache-2.0 license"))) + .name(OPEN_API_INFO_CONTACT_NAME) + .url(OPEN_API_INFO_CONTACT_URL) + .email(OPEN_API_INFO_CONTACT_EMAIL)) + .version(OPEN_API_INFO_VERSION) + .license(new License().name(OPEN_API_INFO_LICENSE_NAME))) .components( new Components() .addSecuritySchemes( @@ -76,4 +83,5 @@ public GroupedOpenApi publicApiV1() { public GroupedOpenApi publicApiV2() { return GroupedOpenApi.builder().group("v2").pathsToMatch("/v2/**").build(); } + } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebMvcConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebMvcConfig.java index 2188b831c2..4d34bc645e 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebMvcConfig.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebMvcConfig.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.ResourceHttpMessageConverter; @@ -41,6 +42,14 @@ public class WebMvcConfig implements WebMvcConfigurer { @Autowired private UploadFileTypeInterceptor uploadFileTypeInterceptor; + private static final String[] CORS_MAPPINGS_ALLOWED_METHODS = { + HttpMethod.POST.name(), + HttpMethod.GET.name(), + HttpMethod.PUT.name(), + HttpMethod.OPTIONS.name(), + HttpMethod.DELETE.name() + }; + @Override public void extendMessageConverters(List> converters) { converters.add(new ByteArrayHttpMessageConverter()); @@ -54,7 +63,7 @@ public void addCorsMappings(CorsRegistry registry) { registry .addMapping("/**") .allowedOriginPatterns("*") - .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") + .allowedMethods(CORS_MAPPINGS_ALLOWED_METHODS) .allowedHeaders("*") .allowCredentials(true) .maxAge(3600); @@ -72,4 +81,5 @@ public Module jacksonModule() { public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(uploadFileTypeInterceptor).addPathPatterns("/flink/app/upload"); } + }