mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-29 13:34:40 +08:00
(improvement)(build) Add spotless during the build process. (#1639)
This commit is contained in:
@@ -20,22 +20,28 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
@RestControllerAdvice(annotations = RestController.class)
|
||||
public class ResponseAdvice implements ResponseBodyAdvice<Object> {
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
@Autowired private ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {
|
||||
public boolean supports(
|
||||
MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {
|
||||
return !methodParameter.getDeclaringClass().isAssignableFrom(BasicErrorController.class);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object result, MethodParameter methodParameter, MediaType mediaType,
|
||||
Class<? extends HttpMessageConverter<?>> aClass, ServerHttpRequest serverHttpRequest,
|
||||
ServerHttpResponse serverHttpResponse) {
|
||||
public Object beforeBodyWrite(
|
||||
Object result,
|
||||
MethodParameter methodParameter,
|
||||
MediaType mediaType,
|
||||
Class<? extends HttpMessageConverter<?>> aClass,
|
||||
ServerHttpRequest serverHttpRequest,
|
||||
ServerHttpResponse serverHttpResponse) {
|
||||
// 判断当前请求是否是 Swagger 相关的请求
|
||||
String path = serverHttpRequest.getURI().getPath();
|
||||
if (path.startsWith("/swagger") || path.startsWith("/v3/api-docs") || path.startsWith("/v2/api-docs")) {
|
||||
if (path.startsWith("/swagger")
|
||||
|| path.startsWith("/v3/api-docs")
|
||||
|| path.startsWith("/v2/api-docs")) {
|
||||
return result;
|
||||
}
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
@@ -47,4 +53,4 @@ public class ResponseAdvice implements ResponseBodyAdvice<Object> {
|
||||
}
|
||||
return ResultData.success(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.tencent.supersonic.advice;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.ResultData;
|
||||
import com.tencent.supersonic.common.pojo.enums.ReturnCode;
|
||||
import com.tencent.supersonic.common.pojo.exception.AccessException;
|
||||
import com.tencent.supersonic.common.pojo.exception.CommonException;
|
||||
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
||||
import com.tencent.supersonic.common.pojo.exception.InvalidPermissionException;
|
||||
import com.tencent.supersonic.common.pojo.ResultData;
|
||||
import com.tencent.supersonic.common.pojo.enums.ReturnCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
@@ -16,9 +16,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
@RestControllerAdvice
|
||||
public class RestExceptionHandler {
|
||||
|
||||
/**
|
||||
* default global exception handler
|
||||
*/
|
||||
/** default global exception handler */
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResultData<String> exception(Exception e) {
|
||||
@@ -53,5 +51,4 @@ public class RestExceptionHandler {
|
||||
log.error("default global exception", e);
|
||||
return ResultData.fail(e.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.tencent.supersonic.config;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.LaxRedirectStrategy;
|
||||
@@ -10,19 +9,25 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
||||
HttpComponentsClientHttpRequestFactory httpRequestFactory =
|
||||
new HttpComponentsClientHttpRequestFactory();
|
||||
httpRequestFactory.setConnectionRequestTimeout(2000);
|
||||
httpRequestFactory.setConnectTimeout(10000);
|
||||
httpRequestFactory.setReadTimeout(7200000);
|
||||
HttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
|
||||
HttpClient httpClient =
|
||||
HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
|
||||
httpRequestFactory.setHttpClient(httpClient);
|
||||
RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
|
||||
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
||||
restTemplate
|
||||
.getMessageConverters()
|
||||
.set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
||||
return restTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,4 @@ public class SpringContextUtil implements ApplicationContextAware {
|
||||
|
||||
return "dev";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ import org.springframework.boot.web.server.ErrorPageRegistry;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* error page config
|
||||
*/
|
||||
/** error page config */
|
||||
@Component
|
||||
public class ErrorPageConfig implements ErrorPageRegistrar {
|
||||
|
||||
@@ -17,4 +15,4 @@ public class ErrorPageConfig implements ErrorPageRegistrar {
|
||||
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/webapp/index.html");
|
||||
registry.addErrorPages(error404Page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,11 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/webapp/**")
|
||||
.addResourceLocations("classpath:/webapp/");
|
||||
registry.addResourceHandler("/webapp/**").addResourceLocations("classpath:/webapp/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/").setViewName("forward:webapp/index.html");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user