This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git


The following commit(s) were added to refs/heads/dev by this push:
     new 65d968f68 [ISSUE-2992][Improve] Using code style & quality rules to 
improve org.apache.streampark.console.base.config package of streampark-console 
module. (#3012)
65d968f68 is described below

commit 65d968f68d0c25dcedc072a49660bca0481f5911
Author: eaglelihh <[email protected]>
AuthorDate: Sun Sep 10 11:09:21 2023 +0800

    [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 <[email protected]>
    Co-authored-by: benjobs <[email protected]>
---
 .../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 aa5ec0185..fd783986b 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 @@ import java.util.Collections;
 @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 = 
"[email protected]";
+
   @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("[email protected]"))
-                .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 class OpenapiConfig implements WebMvcConfigurer {
   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 2188b831c..4d34bc645 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 
com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 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<HttpMessageConverter<?>> 
converters) {
     converters.add(new ByteArrayHttpMessageConverter());
@@ -54,7 +63,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
     registry
         .addMapping("/**")
         .allowedOriginPatterns("*")
-        .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
+        .allowedMethods(CORS_MAPPINGS_ALLOWED_METHODS)
         .allowedHeaders("*")
         .allowCredentials(true)
         .maxAge(3600);
@@ -72,4 +81,5 @@ public class WebMvcConfig implements WebMvcConfigurer {
   public void addInterceptors(InterceptorRegistry registry) {
     
registry.addInterceptor(uploadFileTypeInterceptor).addPathPatterns("/flink/app/upload");
   }
+
 }

Reply via email to