diff --git a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/AuthCenterApplication.java b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/AuthCenterApplication.java index 9d7d96f2..98721033 100644 --- a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/AuthCenterApplication.java +++ b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/AuthCenterApplication.java @@ -1,7 +1,7 @@ package com.jmsoftware.maf.authcenter; import com.jmsoftware.maf.authcenter.universal.configuration.ProjectProperty; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.helper.IpHelper; +import com.jmsoftware.maf.springbootstarter.helper.IpHelper; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.springframework.boot.SpringApplication; diff --git a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/universal/controller/ErrorController.java b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/universal/controller/ErrorController.java deleted file mode 100644 index 9be83f4b..00000000 --- a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/universal/controller/ErrorController.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.jmsoftware.maf.authcenter.universal.controller; - -import io.swagger.annotations.Api; -import lombok.extern.slf4j.Slf4j; -import lombok.val; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; -import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; -import org.springframework.boot.web.servlet.error.ErrorAttributes; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - *

ErrorController

- *

- * Error controller. - * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 2019-03-02 16:56 - **/ -@Slf4j -@RestController -@Api(tags = {"Error Controller"}) -public class ErrorController extends BasicErrorController { - public ErrorController(ErrorAttributes errorAttributes, - ServerProperties serverProperties, - List errorViewResolvers) { - super(errorAttributes, serverProperties.getError(), errorViewResolvers); - } - - @Override - public ResponseEntity> error(HttpServletRequest request) { - val httpStatus = getStatus(request); - val body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL)); - body.put("message", httpStatus.getReasonPhrase()); - val optionalTrace = Optional.ofNullable(body.get("trace")); - optionalTrace.ifPresent(trace -> { - val message = body.get("message"); - val firstLineOfTrace = trace.toString().split("\\n")[0]; - val joinedMessage = String.format("%s %s", message, firstLineOfTrace); - body.put("message", joinedMessage); - body.put("trace", "Trace has been simplified. Refer to 'message'"); - }); - log.error("Captured HTTP request error. Response body = {}", body); - return new ResponseEntity<>(body, httpStatus); - } -} diff --git a/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/ExerciseMisApplication.java b/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/ExerciseMisApplication.java index 596fca20..612f512f 100644 --- a/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/ExerciseMisApplication.java +++ b/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/ExerciseMisApplication.java @@ -1,7 +1,7 @@ package com.jmsoftware.maf.exercisemis; import com.jmsoftware.maf.exercisemis.universal.configuration.ProjectProperty; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.helper.IpHelper; +import com.jmsoftware.maf.springbootstarter.helper.IpHelper; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.springframework.boot.SpringApplication; diff --git a/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/universal/controller/ErrorController.java b/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/universal/controller/ErrorController.java deleted file mode 100644 index 9845a751..00000000 --- a/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/universal/controller/ErrorController.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.jmsoftware.maf.exercisemis.universal.controller; - -import io.swagger.annotations.Api; -import lombok.extern.slf4j.Slf4j; -import lombok.val; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; -import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; -import org.springframework.boot.web.servlet.error.ErrorAttributes; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - *

ErrorController

- *

- * Error controller. - * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 2019-03-02 16:56 - **/ -@Slf4j -@RestController -@Api(tags = {"Error Controller"}) -public class ErrorController extends BasicErrorController { - public ErrorController(ErrorAttributes errorAttributes, - ServerProperties serverProperties, - List errorViewResolvers) { - super(errorAttributes, serverProperties.getError(), errorViewResolvers); - } - - @Override - public ResponseEntity> error(HttpServletRequest request) { - val httpStatus = getStatus(request); - val body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL)); - body.put("message", httpStatus.getReasonPhrase()); - val optionalTrace = Optional.ofNullable(body.get("trace")); - optionalTrace.ifPresent(trace -> { - val message = body.get("message"); - val firstLineOfTrace = trace.toString().split("\\n")[0]; - val joinedMessage = String.format("%s %s", message, firstLineOfTrace); - body.put("message", joinedMessage); - body.put("trace", "Trace has been simplified. Refer to 'message'"); - }); - log.error("Captured HTTP request error. Response body = {}", body); - return new ResponseEntity<>(body, httpStatus); - } -} diff --git a/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/universal/controller/RedirectController.java b/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/universal/controller/RedirectController.java deleted file mode 100644 index 4f497597..00000000 --- a/exercise-mis/src/main/java/com/jmsoftware/maf/exercisemis/universal/controller/RedirectController.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.jmsoftware.maf.exercisemis.universal.controller; - -import com.jmsoftware.maf.exercisemis.universal.configuration.ProjectProperty; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.PostConstruct; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - *

RedirectController

- *

- * HTTP Redirect Controller - * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 1/21/20 1:18 PM - **/ -@Slf4j -@RestController -@RequiredArgsConstructor -@Api(tags = {"Redirect Controller"}) -public class RedirectController { - private final ProjectProperty projectProperty; - - @PostConstruct - private void postConstruct() { - log.info("URL redirect service initialized."); - } - - @GetMapping("/home") - @ApiOperation(value = "/home", notes = "Home page") - public void handleHomeRequest(HttpServletResponse response) throws IOException { - // Redirect to home page - response.sendRedirect(projectProperty.getContextPath() + "static/home.html"); - } - - @GetMapping("/doc") - @ApiOperation(value = "/doc", notes = "Swagger API Documentation") - public void handleDocRequest(HttpServletResponse response) throws IOException { - // Redirect to Bootstrap Swagger API documentation - response.sendRedirect(projectProperty.getContextPath() + "/doc.html?cache=1&lang=en"); - } - - @GetMapping("/webjars/bycdao-ui/images/api.ico") - @ApiOperation(value = "/webjars/bycdao-ui/images/api.ico", notes = "Favicon redirection") - public void handleFaviconRequest(HttpServletResponse response) throws IOException { - // Redirect to a customized favicon - response.sendRedirect(projectProperty.getContextPath() + "/static/icon/favicon.ico"); - } -} diff --git a/muscle-mis/src/main/java/com/jmsoftware/maf/musclemis/MuscleMisApplication.java b/muscle-mis/src/main/java/com/jmsoftware/maf/musclemis/MuscleMisApplication.java index a27fb970..3832c133 100644 --- a/muscle-mis/src/main/java/com/jmsoftware/maf/musclemis/MuscleMisApplication.java +++ b/muscle-mis/src/main/java/com/jmsoftware/maf/musclemis/MuscleMisApplication.java @@ -1,7 +1,7 @@ package com.jmsoftware.maf.musclemis; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.helper.IpHelper; import com.jmsoftware.maf.musclemis.universal.configuration.ProjectProperty; +import com.jmsoftware.maf.springbootstarter.helper.IpHelper; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.springframework.boot.SpringApplication; diff --git a/muscle-mis/src/main/java/com/jmsoftware/maf/musclemis/universal/controller/ErrorController.java b/muscle-mis/src/main/java/com/jmsoftware/maf/musclemis/universal/controller/ErrorController.java deleted file mode 100644 index 88f7fd03..00000000 --- a/muscle-mis/src/main/java/com/jmsoftware/maf/musclemis/universal/controller/ErrorController.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.jmsoftware.maf.musclemis.universal.controller; - -import io.swagger.annotations.Api; -import lombok.extern.slf4j.Slf4j; -import lombok.val; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; -import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; -import org.springframework.boot.web.servlet.error.ErrorAttributes; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - *

ErrorController

- *

- * Error controller. - * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 2019-03-02 16:56 - **/ -@Slf4j -@RestController -@Api(tags = {"Error Controller"}) -public class ErrorController extends BasicErrorController { - public ErrorController(ErrorAttributes errorAttributes, - ServerProperties serverProperties, - List errorViewResolvers) { - super(errorAttributes, serverProperties.getError(), errorViewResolvers); - } - - @Override - public ResponseEntity> error(HttpServletRequest request) { - val httpStatus = getStatus(request); - val body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL)); - body.put("message", httpStatus.getReasonPhrase()); - val optionalTrace = Optional.ofNullable(body.get("trace")); - optionalTrace.ifPresent(trace -> { - val message = body.get("message"); - val firstLineOfTrace = trace.toString().split("\\n")[0]; - val joinedMessage = String.format("%s %s", message, firstLineOfTrace); - body.put("message", joinedMessage); - body.put("trace", "Trace has been simplified. Refer to 'message'"); - }); - log.error("Captured HTTP request error. Response body = {}", body); - return new ResponseEntity<>(body, httpStatus); - } -} diff --git a/service-registry/src/main/java/com/jmsoftware/maf/serviceregistry/ServiceRegistryApplication.java b/service-registry/src/main/java/com/jmsoftware/maf/serviceregistry/ServiceRegistryApplication.java index 2ae0c1ae..105224ec 100644 --- a/service-registry/src/main/java/com/jmsoftware/maf/serviceregistry/ServiceRegistryApplication.java +++ b/service-registry/src/main/java/com/jmsoftware/maf/serviceregistry/ServiceRegistryApplication.java @@ -1,7 +1,7 @@ package com.jmsoftware.maf.serviceregistry; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.helper.IpHelper; import com.jmsoftware.maf.serviceregistry.universal.configuration.ProjectProperty; +import com.jmsoftware.maf.springbootstarter.helper.IpHelper; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.springframework.boot.SpringApplication; diff --git a/service-registry/src/main/java/com/jmsoftware/maf/serviceregistry/universal/controller/ErrorController.java b/service-registry/src/main/java/com/jmsoftware/maf/serviceregistry/universal/controller/ErrorController.java deleted file mode 100644 index 6989e1a2..00000000 --- a/service-registry/src/main/java/com/jmsoftware/maf/serviceregistry/universal/controller/ErrorController.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.jmsoftware.maf.serviceregistry.universal.controller; - -import io.swagger.annotations.Api; -import lombok.extern.slf4j.Slf4j; -import lombok.val; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; -import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; -import org.springframework.boot.web.servlet.error.ErrorAttributes; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - *

ErrorController

- *

- * Error controller. - * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 2019-03-02 16:56 - **/ -@Slf4j -@RestController -@Api(tags = {"Error Controller"}) -public class ErrorController extends BasicErrorController { - public ErrorController(ErrorAttributes errorAttributes, - ServerProperties serverProperties, - List errorViewResolvers) { - super(errorAttributes, serverProperties.getError(), errorViewResolvers); - } - - @Override - public ResponseEntity> error(HttpServletRequest request) { - val httpStatus = getStatus(request); - val body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL)); - body.put("message", httpStatus.getReasonPhrase()); - val optionalTrace = Optional.ofNullable(body.get("trace")); - optionalTrace.ifPresent(trace -> { - val message = body.get("message"); - val firstLineOfTrace = trace.toString().split("\\n")[0]; - val joinedMessage = String.format("%s %s", message, firstLineOfTrace); - body.put("message", joinedMessage); - body.put("trace", "Trace has been simplified. Refer to 'message'"); - }); - log.error("Captured HTTP request error. Response body = {}", body); - return new ResponseEntity<>(body, httpStatus); - } -} diff --git a/spring-boot-admin/src/main/java/com/jmsoftware/maf/springbootadmin/SpringBootAdminApplication.java b/spring-boot-admin/src/main/java/com/jmsoftware/maf/springbootadmin/SpringBootAdminApplication.java index dac7616f..df21d2a0 100644 --- a/spring-boot-admin/src/main/java/com/jmsoftware/maf/springbootadmin/SpringBootAdminApplication.java +++ b/spring-boot-admin/src/main/java/com/jmsoftware/maf/springbootadmin/SpringBootAdminApplication.java @@ -1,7 +1,7 @@ package com.jmsoftware.maf.springbootadmin; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.helper.IpHelper; import com.jmsoftware.maf.springbootadmin.universal.configuration.ProjectProperty; +import com.jmsoftware.maf.springbootstarter.helper.IpHelper; import de.codecentric.boot.admin.server.config.EnableAdminServer; import lombok.extern.slf4j.Slf4j; import lombok.val; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/MuscleAndFitnessServerAutoConfiguration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/MuscleAndFitnessServerAutoConfiguration.java deleted file mode 100644 index a17fa70c..00000000 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/MuscleAndFitnessServerAutoConfiguration.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.configuration; - -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.aspect.ExceptionControllerAdvice; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.aspect.WebRequestLogAspect; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.controller.RedirectController; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.filter.AccessLogFilter; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.helper.IpHelper; -import lombok.RequiredArgsConstructor; -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; -import org.springframework.core.env.Environment; - -import javax.annotation.PostConstruct; - -/** - * Description: MediaStreamingAutoConfiguration, change description here. - * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 10/19/2020 2:51 PM - **/ -@Slf4j -@Configuration -@RequiredArgsConstructor -@EnableConfigurationProperties(MuscleAndFitnessServerAutoConfiguration.class) -public class MuscleAndFitnessServerAutoConfiguration { - @PostConstruct - public void afterInitialization() { - log.debug("{} initialization is done. About to inject beans.", getClass().getSimpleName()); - } - - @Bean - @ConditionalOnMissingBean - public MafConfiguration mafConfiguration() { - log.debug("Initial bean: {}", MafConfiguration.class.getName()); - return new MafConfiguration(); - } - - @Bean - @ConditionalOnMissingBean - public ExceptionControllerAdvice exceptionControllerAdvice() { - log.debug("Initial bean: {}", ExceptionControllerAdvice.class.getName()); - return new ExceptionControllerAdvice(); - } - - @Bean - @ConditionalOnMissingBean - @ConditionalOnProperty(value = "maf.configuration.webRequestLogDisabled", havingValue = "false") - public WebRequestLogAspect webRequestLogAspect() { - log.debug("Initial bean: {}", WebRequestLogAspect.class.getName()); - return new WebRequestLogAspect(); - } - - @Bean - @ConditionalOnMissingBean - public RedirectController redirectController() { - log.debug("Initial bean: {}", RedirectController.class.getName()); - return new RedirectController(); - } - - @Bean - @ConditionalOnMissingBean - public AccessLogFilter requestFilter(MafConfiguration mafConfiguration) { - log.debug("Initial bean: {}", AccessLogFilter.class.getName()); - return new AccessLogFilter(mafConfiguration); - } - - @Bean - @ConditionalOnMissingBean - public IpHelper ipHelper(Environment environment) { - log.debug("Initial bean: {}", IpHelper.class.getName()); - return new IpHelper(environment); - } - - @Bean - @ConditionalOnMissingBean - public WebMvcConfiguration webMvcConfiguration() { - log.debug("Initial bean: {}", WebMvcConfiguration.class.getName()); - return new WebMvcConfiguration(); - } -} diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/package-info.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/package-info.java deleted file mode 100644 index 7aa39447..00000000 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/aspect/ExceptionControllerAdvice.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/aspect/ExceptionControllerAdvice.java similarity index 98% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/aspect/ExceptionControllerAdvice.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/aspect/ExceptionControllerAdvice.java index 86404125..2ea92aad 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/aspect/ExceptionControllerAdvice.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/aspect/ExceptionControllerAdvice.java @@ -1,9 +1,9 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.aspect; +package com.jmsoftware.maf.springbootstarter.aspect; import cn.hutool.core.collection.CollUtil; import com.jmsoftware.maf.common.bean.ResponseBodyBean; import com.jmsoftware.maf.common.exception.BaseException; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.util.RequestUtil; +import com.jmsoftware.maf.springbootstarter.util.RequestUtil; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.springframework.context.support.DefaultMessageSourceResolvable; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/aspect/WebRequestLogAspect.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/aspect/WebRequestLogAspect.java similarity index 97% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/aspect/WebRequestLogAspect.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/aspect/WebRequestLogAspect.java index e83fd680..096d5acf 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/aspect/WebRequestLogAspect.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/aspect/WebRequestLogAspect.java @@ -1,9 +1,9 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.aspect; +package com.jmsoftware.maf.springbootstarter.aspect; import cn.hutool.json.JSONUtil; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.util.RequestUtil; +import com.jmsoftware.maf.springbootstarter.util.RequestUtil; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.aspectj.lang.JoinPoint; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/IgnoredUrl.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/IgnoredUrl.java similarity index 95% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/IgnoredUrl.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/IgnoredUrl.java index ef50c7ee..3b649836 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/IgnoredUrl.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/IgnoredUrl.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.configuration; +package com.jmsoftware.maf.springbootstarter.configuration; import com.google.common.collect.Lists; import lombok.Data; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafAutoConfiguration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafAutoConfiguration.java new file mode 100644 index 00000000..d306ea8b --- /dev/null +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafAutoConfiguration.java @@ -0,0 +1,102 @@ +package com.jmsoftware.maf.springbootstarter.configuration; + +import com.jmsoftware.maf.springbootstarter.aspect.ExceptionControllerAdvice; +import com.jmsoftware.maf.springbootstarter.aspect.WebRequestLogAspect; +import com.jmsoftware.maf.springbootstarter.controller.GlobalErrorController; +import com.jmsoftware.maf.springbootstarter.controller.RedirectController; +import com.jmsoftware.maf.springbootstarter.filter.AccessLogFilter; +import com.jmsoftware.maf.springbootstarter.helper.IpHelper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.AutoConfigureOrder; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.SearchStrategy; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.servlet.error.ErrorAttributes; +import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; + +import javax.annotation.PostConstruct; +import java.util.List; + +/** + * Description: MediaStreamingAutoConfiguration, change description here. + * + * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 10/19/2020 2:51 PM + **/ +@Slf4j +@Configuration +@ConditionalOnWebApplication +@AutoConfigureOrder(Integer.MIN_VALUE) +@EnableConfigurationProperties(MafConfiguration.class) +public class MafAutoConfiguration { + @PostConstruct + public void postConstruct() { + log.warn("Post construction of [{}] is done. About to inject beans. Auto configure order: {}", + getClass().getSimpleName(), Integer.MIN_VALUE); + } + + @Bean + @ConditionalOnMissingBean + public MafConfiguration mafConfiguration() { + log.warn("Initial bean: {}", MafConfiguration.class.getName()); + return new MafConfiguration(); + } + + @Bean + @ConditionalOnMissingBean + public ExceptionControllerAdvice exceptionControllerAdvice() { + log.warn("Initial bean: {}", ExceptionControllerAdvice.class.getName()); + return new ExceptionControllerAdvice(); + } + + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(value = "maf.configuration.webRequestLogDisabled", havingValue = "false") + public WebRequestLogAspect webRequestLogAspect() { + log.warn("Initial bean: {}", WebRequestLogAspect.class.getName()); + return new WebRequestLogAspect(); + } + + @Bean + @ConditionalOnMissingBean + public RedirectController redirectController() { + log.warn("Initial bean: {}", RedirectController.class.getName()); + return new RedirectController(); + } + + @Bean + @ConditionalOnMissingBean + public AccessLogFilter requestFilter(MafConfiguration mafConfiguration) { + log.warn("Initial bean: {}", AccessLogFilter.class.getName()); + return new AccessLogFilter(mafConfiguration); + } + + @Bean + @ConditionalOnMissingBean + public IpHelper ipHelper(Environment environment) { + log.warn("Initial bean: {}", IpHelper.class.getName()); + return new IpHelper(environment); + } + + @Bean + @ConditionalOnMissingBean + public WebMvcConfiguration webMvcConfiguration() { + log.warn("Initial bean: {}", WebMvcConfiguration.class.getName()); + return new WebMvcConfiguration(); + } + + @Bean + @ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT) + public GlobalErrorController globalErrorController(ErrorAttributes errorAttributes, + ServerProperties serverProperties, + List errorViewResolvers) { + log.warn("Initial bean: {}", GlobalErrorController.class.getName()); + return new GlobalErrorController(errorAttributes, serverProperties, errorViewResolvers); + } +} diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/MafConfiguration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafConfiguration.java similarity index 96% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/MafConfiguration.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafConfiguration.java index af633d8b..c725e883 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/MafConfiguration.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafConfiguration.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.configuration; +package com.jmsoftware.maf.springbootstarter.configuration; import cn.hutool.core.util.ObjectUtil; import lombok.Data; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/WebMvcConfiguration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/WebMvcConfiguration.java similarity index 94% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/WebMvcConfiguration.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/WebMvcConfiguration.java index 49c8c8bf..383101be 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/configuration/WebMvcConfiguration.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/WebMvcConfiguration.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.configuration; +package com.jmsoftware.maf.springbootstarter.configuration; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-admin/src/main/java/com/jmsoftware/maf/springbootadmin/universal/controller/ErrorController.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/controller/GlobalErrorController.java similarity index 71% rename from spring-boot-admin/src/main/java/com/jmsoftware/maf/springbootadmin/universal/controller/ErrorController.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/controller/GlobalErrorController.java index e8e29ea5..4fdf9625 100644 --- a/spring-boot-admin/src/main/java/com/jmsoftware/maf/springbootadmin/universal/controller/ErrorController.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/controller/GlobalErrorController.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.springbootadmin.universal.controller; +package com.jmsoftware.maf.springbootstarter.controller; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; @@ -6,8 +6,8 @@ import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; +import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.servlet.error.ErrorAttributes; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -26,18 +26,17 @@ **/ @Slf4j @RestController -@Api(tags = {"Error Controller"}) -public class ErrorController extends BasicErrorController { - public ErrorController(ErrorAttributes errorAttributes, - ServerProperties serverProperties, - List errorViewResolvers) { +@Api(tags = {"Global Error Controller"}) +public class GlobalErrorController extends BasicErrorController { + public GlobalErrorController(ErrorAttributes errorAttributes, ServerProperties serverProperties, + List errorViewResolvers) { super(errorAttributes, serverProperties.getError(), errorViewResolvers); } @Override public ResponseEntity> error(HttpServletRequest request) { val httpStatus = getStatus(request); - val body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL)); + val body = getErrorAttributes(request, ErrorAttributeOptions.defaults()); body.put("message", httpStatus.getReasonPhrase()); val optionalTrace = Optional.ofNullable(body.get("trace")); optionalTrace.ifPresent(trace -> { @@ -45,7 +44,8 @@ public ResponseEntity> error(HttpServletRequest request) { val firstLineOfTrace = trace.toString().split("\\n")[0]; val joinedMessage = String.format("%s %s", message, firstLineOfTrace); body.put("message", joinedMessage); - body.put("trace", "Trace has been simplified. Refer to 'message'"); + body.put("trace", + String.format("Trace has been simplified by %s. Refer to 'message'", getClass().getName())); }); log.error("Captured HTTP request error. Response body = {}", body); return new ResponseEntity<>(body, httpStatus); diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/controller/RedirectController.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/controller/RedirectController.java similarity index 95% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/controller/RedirectController.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/controller/RedirectController.java index e4d8181c..ca21b9b2 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/controller/RedirectController.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/controller/RedirectController.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.controller; +package com.jmsoftware.maf.springbootstarter.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/filter/AccessLogFilter.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/filter/AccessLogFilter.java similarity index 86% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/filter/AccessLogFilter.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/filter/AccessLogFilter.java index 958374ab..2bbed06d 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/filter/AccessLogFilter.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/filter/AccessLogFilter.java @@ -1,7 +1,7 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.filter; +package com.jmsoftware.maf.springbootstarter.filter; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.configuration.MafConfiguration; -import com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.util.RequestUtil; +import com.jmsoftware.maf.springbootstarter.configuration.MafConfiguration; +import com.jmsoftware.maf.springbootstarter.util.RequestUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/helper/IpHelper.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/helper/IpHelper.java similarity index 97% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/helper/IpHelper.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/helper/IpHelper.java index 36d574bb..6221b4b1 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/helper/IpHelper.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/helper/IpHelper.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.helper; +package com.jmsoftware.maf.springbootstarter.helper; import cn.hutool.core.util.StrUtil; import lombok.AccessLevel; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/package-info.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/package-info.java new file mode 100644 index 00000000..cd627290 --- /dev/null +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/package-info.java @@ -0,0 +1 @@ +package com.jmsoftware.maf.springbootstarter; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/CaseConversionUtil.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/CaseConversionUtil.java similarity index 99% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/CaseConversionUtil.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/CaseConversionUtil.java index 232c1673..12fa7eda 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/CaseConversionUtil.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/CaseConversionUtil.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.util; +package com.jmsoftware.maf.springbootstarter.util; import java.util.Random; import java.util.regex.Pattern; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/FileUtil.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/FileUtil.java similarity index 97% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/FileUtil.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/FileUtil.java index 07d58ccb..1a989433 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/FileUtil.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/FileUtil.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.util; +package com.jmsoftware.maf.springbootstarter.util; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/RequestUtil.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/RequestUtil.java similarity index 94% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/RequestUtil.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/RequestUtil.java index fa060e5a..2d457424 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/RequestUtil.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/RequestUtil.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.util; +package com.jmsoftware.maf.springbootstarter.util; import cn.hutool.core.util.StrUtil; diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/ResponseUtil.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/ResponseUtil.java similarity index 97% rename from spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/ResponseUtil.java rename to spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/ResponseUtil.java index fa8bbb4c..cdaa84c1 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverspringbootstarter/util/ResponseUtil.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/util/ResponseUtil.java @@ -1,4 +1,4 @@ -package com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.util; +package com.jmsoftware.maf.springbootstarter.util; import com.fasterxml.jackson.databind.ObjectMapper; import com.jmsoftware.maf.common.bean.ResponseBodyBean; diff --git a/spring-boot-starter/src/main/resources/META-INF/spring.factories b/spring-boot-starter/src/main/resources/META-INF/spring.factories index 77c4a2b8..da2eb1dc 100644 --- a/spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.jmsoftware.maf.muscleandfitnessserverspringbootstarter.configuration.MuscleAndFitnessServerAutoConfiguration + com.jmsoftware.maf.springbootstarter.configuration.MafAutoConfiguration