From 0a8bc6daf3aa55760a86ddf1f199828ac5e337c9 Mon Sep 17 00:00:00 2001 From: tianliyong Date: Sat, 5 Nov 2022 18:03:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E7=B1=BB=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/swagger/SwaggerAutoConfiguration.java | 30 ++++----- ...piCoreEntity.java => ApiCoreResponse.java} | 4 +- ...piListEntity.java => ApiListResponse.java} | 54 +++++++-------- ...piPageEntity.java => ApiPageResponse.java} | 66 +++++++++---------- .../http/{ApiEntity.java => ApiResponse.java} | 64 +++++++++--------- .../filter/OrderedBadRequestFilter.java | 28 ++++---- ...va => ApiCoreResponseMethodParameter.java} | 10 +-- ...va => ApiCoreResponseMethodProcessor.java} | 16 ++--- .../oauth/CustomOAuth2ExceptionRenderer.java | 6 +- .../SpringOAuth2AuthenticationEntryPoint.java | 4 +- 10 files changed, 141 insertions(+), 141 deletions(-) rename axzo-common-web/src/main/java/cn.axzo.framework.web/http/{ApiCoreEntity.java => ApiCoreResponse.java} (94%) rename axzo-common-web/src/main/java/cn.axzo.framework.web/http/{ApiListEntity.java => ApiListResponse.java} (61%) rename axzo-common-web/src/main/java/cn.axzo.framework.web/http/{ApiPageEntity.java => ApiPageResponse.java} (60%) rename axzo-common-web/src/main/java/cn.axzo.framework.web/http/{ApiEntity.java => ApiResponse.java} (63%) rename axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/{ApiCoreEntityMethodParameter.java => ApiCoreResponseMethodParameter.java} (74%) rename axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/{ApiCoreEntityMethodProcessor.java => ApiCoreResponseMethodProcessor.java} (66%) diff --git a/axzo-common-autoconfigure/src/main/java/cn/axzo/framework/autoconfigure/web/swagger/SwaggerAutoConfiguration.java b/axzo-common-autoconfigure/src/main/java/cn/axzo/framework/autoconfigure/web/swagger/SwaggerAutoConfiguration.java index 054860c..e6cf128 100644 --- a/axzo-common-autoconfigure/src/main/java/cn/axzo/framework/autoconfigure/web/swagger/SwaggerAutoConfiguration.java +++ b/axzo-common-autoconfigure/src/main/java/cn/axzo/framework/autoconfigure/web/swagger/SwaggerAutoConfiguration.java @@ -7,9 +7,9 @@ import cn.axzo.framework.domain.web.result.ApiListResult; import cn.axzo.framework.domain.web.result.ApiPageResult; import cn.axzo.framework.domain.web.result.ApiResult; import cn.axzo.framework.context.Placeholders; -import cn.axzo.framework.web.http.ApiEntity; -import cn.axzo.framework.web.http.ApiListEntity; -import cn.axzo.framework.web.http.ApiPageEntity; +import cn.axzo.framework.web.http.ApiResponse; +import cn.axzo.framework.web.http.ApiListResponse; +import cn.axzo.framework.web.http.ApiPageResponse; import com.fasterxml.classmate.TypeResolver; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -124,35 +124,35 @@ public class SwaggerAutoConfiguration { ); } - @ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiEntity") + @ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiResponse") @Bean - public AlternateTypeRule apiEntityAlternateTypeRule(TypeResolver typeResolver) { + public AlternateTypeRule apiResponseAlternateTypeRule(TypeResolver typeResolver) { return AlternateTypeRules.newRule( - typeResolver.resolve(ApiEntity.class, WildcardType.class), + typeResolver.resolve(ApiResponse.class, WildcardType.class), typeResolver.resolve(ApiResult.class, WildcardType.class) ); } - @ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiEntity") + @ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiResponse") @Bean - public AlternateTypeRule callableApiEntityAlternateTypeRule(TypeResolver typeResolver) { + public AlternateTypeRule callableApiResponseAlternateTypeRule(TypeResolver typeResolver) { return newRule( - typeResolver.resolve(Callable.class, typeResolver.resolve(ApiEntity.class, WildcardType.class)), + typeResolver.resolve(Callable.class, typeResolver.resolve(ApiResponse.class, WildcardType.class)), typeResolver.resolve(ApiResult.class, WildcardType.class) ); } - @ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiListEntity") + @ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiListResponse") @Bean - public AlternateTypeRule apiListEntityAlternateTypeRule(TypeResolver typeResolver) { - return newRule(typeResolver.resolve(ApiListEntity.class, WildcardType.class), + public AlternateTypeRule apiListResponseAlternateTypeRule(TypeResolver typeResolver) { + return newRule(typeResolver.resolve(ApiListResponse.class, WildcardType.class), typeResolver.resolve(ApiListResult.class, WildcardType.class)); } - @ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiPageEntity") + @ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiPageResponse") @Bean - public AlternateTypeRule apiPageEntityAlternateTypeRule(TypeResolver typeResolver) { - return newRule(typeResolver.resolve(ApiPageEntity.class, WildcardType.class), + public AlternateTypeRule apiPageResponseAlternateTypeRule(TypeResolver typeResolver) { + return newRule(typeResolver.resolve(ApiPageResponse.class, WildcardType.class), typeResolver.resolve(ApiPageResult.class, WildcardType.class)); } diff --git a/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiCoreEntity.java b/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiCoreResponse.java similarity index 94% rename from axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiCoreEntity.java rename to axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiCoreResponse.java index baa17c2..0e832f3 100644 --- a/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiCoreEntity.java +++ b/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiCoreResponse.java @@ -18,7 +18,7 @@ import java.util.Set; */ @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public abstract class ApiCoreEntity> extends HttpEntity { +public abstract class ApiCoreResponse> extends HttpEntity { private final Object status; @@ -29,7 +29,7 @@ public abstract class ApiCoreEntity> extends HttpE * @param headers the entity headers * @param status the status code */ - public ApiCoreEntity(R body, MultiValueMap headers, HttpStatus status) { + public ApiCoreResponse(R body, MultiValueMap headers, HttpStatus status) { super(body, headers); Assert.notNull(status, "HttpStatus must not be null"); this.status = status; diff --git a/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiListEntity.java b/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiListResponse.java similarity index 61% rename from axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiListEntity.java rename to axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiListResponse.java index b831541..34a657f 100644 --- a/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiListEntity.java +++ b/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiListResponse.java @@ -16,7 +16,7 @@ import java.util.List; * @author liyong.tian * @since 2017/11/14 下午8:00 */ -public class ApiListEntity extends ApiCoreEntity, ApiListResult> { +public class ApiListResponse extends ApiCoreResponse, ApiListResult> { /** * Create a new {@code HttpEntity} with the given body, headers, and status code. @@ -25,7 +25,7 @@ public class ApiListEntity extends ApiCoreEntity, ApiListResult> { * @param headers the entity headers * @param status the status code */ - ApiListEntity(ApiListResult body, MultiValueMap headers, HttpStatus status) { + ApiListResponse(ApiListResult body, MultiValueMap headers, HttpStatus status) { super(body, headers, status); } @@ -35,7 +35,7 @@ public class ApiListEntity extends ApiCoreEntity, ApiListResult> { * @return the created builder * @since 4.1 */ - public static ApiListEntity ok() { + public static ApiListResponse ok() { return status(HttpStatus.OK).ok(); } @@ -46,20 +46,20 @@ public class ApiListEntity extends ApiCoreEntity, ApiListResult> { * @return the created {@code ResponseEntity} * @since 4.1 */ - public static ApiListEntity ok(List data) { + public static ApiListResponse ok(List data) { return status(HttpStatus.OK).ok(data); } - public static ApiListEntityBuilder status(@Nonnull HttpStatus status) { + public static ApiListResponseBuilder status(@Nonnull HttpStatus status) { Assert.notNull(status, "HttpStatus must not be null"); - return new ApiListEntityBuilder(status); + return new ApiListResponseBuilder(status); } - public static ApiListEntityBuilder header(String headerName, String... headerValues) { + public static ApiListResponseBuilder header(String headerName, String... headerValues) { return status(HttpStatus.OK).header(headerName, headerValues); } - public static ApiListEntityBuilder headers(HttpHeaders headers) { + public static ApiListResponseBuilder headers(HttpHeaders headers) { return status(HttpStatus.OK).headers(headers); } @@ -71,11 +71,11 @@ public class ApiListEntity extends ApiCoreEntity, ApiListResult> { * @return the created builder * @since 4.1 */ - public static ApiListEntityBuilder created(URI location) { + public static ApiListResponseBuilder created(URI location) { return status(HttpStatus.CREATED).location(location); } - public static ApiListEntityBuilder created(String location) { + public static ApiListResponseBuilder created(String location) { return status(HttpStatus.CREATED).location(Nets.uri(location)); } @@ -85,7 +85,7 @@ public class ApiListEntity extends ApiCoreEntity, ApiListResult> { * @return the created builder * @since 4.1 */ - public static ApiListEntityBuilder accepted() { + public static ApiListResponseBuilder accepted() { return status(HttpStatus.ACCEPTED); } @@ -95,7 +95,7 @@ public class ApiListEntity extends ApiCoreEntity, ApiListResult> { * @return the created builder * @since 4.1 */ - public static ApiListEntityBuilder badRequest() { + public static ApiListResponseBuilder badRequest() { return status(HttpStatus.BAD_REQUEST); } @@ -105,58 +105,58 @@ public class ApiListEntity extends ApiCoreEntity, ApiListResult> { * @return the created builder * @since 4.1 */ - public static ApiListEntityBuilder notFound() { + public static ApiListResponseBuilder notFound() { return status(HttpStatus.NOT_FOUND); } - public static class ApiListEntityBuilder extends AbstractBodySetter { + public static class ApiListResponseBuilder extends AbstractBodySetter { - private ApiListEntityBuilder(HttpStatus status) { + private ApiListResponseBuilder(HttpStatus status) { super(status); } - public ApiListEntity ok() { + public ApiListResponse ok() { return wrapper(ApiListResult.ok()); } - public ApiListEntity ok(List data) { + public ApiListResponse ok(List data) { return wrapper(ApiListResult.ok(data)); } - public ApiListEntity err(IRespCode code) { + public ApiListResponse err(IRespCode code) { return wrapper(ApiListResult.err(code)); } - public ApiListEntity err(IRespCode code, String message) { + public ApiListResponse err(IRespCode code, String message) { return wrapper(ApiListResult.err(code, message)); } - public ApiListEntity err(String message) { + public ApiListResponse err(String message) { return wrapper(ApiListResult.err(message)); } - public ApiListEntity err(IRespCode code, List data) { + public ApiListResponse err(IRespCode code, List data) { return wrapper(ApiListResult.err(code, data)); } - public ApiListEntity err(String code, String message) { + public ApiListResponse err(String code, String message) { return wrapper(ApiListResult.err(code, message)); } - public ApiListEntity build(IRespCode code) { + public ApiListResponse build(IRespCode code) { return wrapper(ApiListResult.build(code)); } - public ApiListEntity build(IRespCode code, List data) { + public ApiListResponse build(IRespCode code, List data) { return wrapper(ApiListResult.build(code, data)); } - public ApiListEntity build(String code, String message, List data) { + public ApiListResponse build(String code, String message, List data) { return wrapper(ApiListResult.build(code, message, data)); } - private ApiListEntity wrapper(ApiListResult result) { - return new ApiListEntity<>(result, super.headers, super.status); + private ApiListResponse wrapper(ApiListResult result) { + return new ApiListResponse<>(result, super.headers, super.status); } } } diff --git a/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiPageEntity.java b/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiPageResponse.java similarity index 60% rename from axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiPageEntity.java rename to axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiPageResponse.java index d0f648e..a5f6f0c 100644 --- a/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiPageEntity.java +++ b/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiPageResponse.java @@ -21,7 +21,7 @@ import java.util.List; * @author liyong.tian * @since 2017/11/14 下午7:52 */ -public class ApiPageEntity extends ApiCoreEntity, ApiPageResult> { +public class ApiPageResponse extends ApiCoreResponse, ApiPageResult> { /** * Create a new {@code HttpEntity} with the given body, headers, and status code. @@ -30,7 +30,7 @@ public class ApiPageEntity extends ApiCoreEntity, ApiPageResult body, MultiValueMap headers, HttpStatus status) { + public ApiPageResponse(ApiPageResult body, MultiValueMap headers, HttpStatus status) { super(body, headers, status); } @@ -40,7 +40,7 @@ public class ApiPageEntity extends ApiCoreEntity, ApiPageResult ApiPageEntity empty() { + public static ApiPageResponse empty() { return status(HttpStatus.OK).empty(); } @@ -51,32 +51,32 @@ public class ApiPageEntity extends ApiCoreEntity, ApiPageResult ApiPageEntity ok(Page page) { + public static ApiPageResponse ok(Page page) { return status(HttpStatus.OK).ok(page); } - public static ApiPageEntity ok(org.springframework.data.domain.Page page) { + public static ApiPageResponse ok(org.springframework.data.domain.Page page) { return status(HttpStatus.OK).ok(page); } - public static ApiPageEntity ok(PageInfo pageInfo) { + public static ApiPageResponse ok(PageInfo pageInfo) { return status(HttpStatus.OK).ok(pageInfo); } - public static ApiPageEntity ok(PageResp page) { + public static ApiPageResponse ok(PageResp page) { return status(HttpStatus.OK).ok(page); } - public static ApiPageEntityBuilder status(@Nonnull HttpStatus status) { + public static ApiPageResponseBuilder status(@Nonnull HttpStatus status) { Assert.notNull(status, "HttpStatus must not be null"); - return new ApiPageEntityBuilder(status); + return new ApiPageResponseBuilder(status); } - public static ApiPageEntityBuilder header(String headerName, String... headerValues) { + public static ApiPageResponseBuilder header(String headerName, String... headerValues) { return status(HttpStatus.OK).header(headerName, headerValues); } - public static ApiPageEntityBuilder headers(HttpHeaders headers) { + public static ApiPageResponseBuilder headers(HttpHeaders headers) { return status(HttpStatus.OK).headers(headers); } @@ -88,11 +88,11 @@ public class ApiPageEntity extends ApiCoreEntity, ApiPageResult extends ApiCoreEntity, ApiPageResult extends ApiCoreEntity, ApiPageResult extends ApiCoreEntity, ApiPageResult { + public static class ApiPageResponseBuilder extends AbstractBodySetter { - private ApiPageEntityBuilder(HttpStatus status) { + private ApiPageResponseBuilder(HttpStatus status) { super(status); } - public ApiPageEntity empty() { + public ApiPageResponse empty() { return wrapper(ApiPageResult.empty()); } - public ApiPageEntity ok(Page page) { + public ApiPageResponse ok(Page page) { return wrapper(ApiPageResult.ok(page)); } - public ApiPageEntity ok(org.springframework.data.domain.Page page) { + public ApiPageResponse ok(org.springframework.data.domain.Page page) { return wrapper(ApiPageResult.ok(page)); } - public ApiPageEntity ok(PageInfo pageInfo) { + public ApiPageResponse ok(PageInfo pageInfo) { return wrapper(ApiPageResult.ok(pageInfo)); } - public ApiPageEntity ok(PageResp page) { + public ApiPageResponse ok(PageResp page) { return wrapper(ApiPageResult.ok(page)); } - public ApiPageEntity ok(List data, Long total) { + public ApiPageResponse ok(List data, Long total) { return wrapper(ApiPageResult.ok(data, total)); } - public ApiPageEntity ok(List data, Long total, Integer pageNumber, Integer pageSize) { + public ApiPageResponse ok(List data, Long total, Integer pageNumber, Integer pageSize) { return wrapper(ApiPageResult.ok(data, total, pageNumber, pageSize)); } - public ApiPageEntity err(IRespCode code) { + public ApiPageResponse err(IRespCode code) { return wrapper(ApiPageResult.err(code)); } - public ApiPageEntity err(IRespCode code, String message) { + public ApiPageResponse err(IRespCode code, String message) { return wrapper(ApiPageResult.err(code, message)); } - public ApiPageEntity err(String code, String message) { + public ApiPageResponse err(String code, String message) { return wrapper(ApiPageResult.err(code, message)); } - public ApiPageEntity build(IRespCode code) { + public ApiPageResponse build(IRespCode code) { return wrapper(ApiPageResult.build(code)); } - public ApiPageEntity build(Long total, IRespCode code, List data, Integer pageNum, Integer pageSize) { + public ApiPageResponse build(Long total, IRespCode code, List data, Integer pageNum, Integer pageSize) { return wrapper(ApiPageResult.build(total, code, data, pageNum, pageSize)); } - public ApiPageEntity build(Long total, String code, String message, List data, + public ApiPageResponse build(Long total, String code, String message, List data, Integer pageNum, Integer pageSize) { return wrapper(ApiPageResult.build(total, code, message, data, pageNum, pageSize)); } - private ApiPageEntity wrapper(ApiPageResult result) { - return new ApiPageEntity<>(result, super.headers, super.status); + private ApiPageResponse wrapper(ApiPageResult result) { + return new ApiPageResponse<>(result, super.headers, super.status); } } } diff --git a/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiEntity.java b/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiResponse.java similarity index 63% rename from axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiEntity.java rename to axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiResponse.java index f81426a..a293b2a 100644 --- a/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiEntity.java +++ b/axzo-common-web/src/main/java/cn.axzo.framework.web/http/ApiResponse.java @@ -18,7 +18,7 @@ import java.util.function.Function; * @author liyong.tian * @since 2017/11/14 下午7:55 */ -public class ApiEntity extends ApiCoreEntity> { +public class ApiResponse extends ApiCoreResponse> { /** * Create a new {@code HttpEntity} with the given body, headers, and status code. @@ -27,16 +27,16 @@ public class ApiEntity extends ApiCoreEntity> { * @param headers the entity headers * @param status the status code */ - ApiEntity(ApiResult body, MultiValueMap headers, HttpStatus status) { + ApiResponse(ApiResult body, MultiValueMap headers, HttpStatus status) { super(body, headers, status); } - public ApiEntity map(Function mapper) { + public ApiResponse map(Function mapper) { ApiResult result = getBody().map(mapper); return status(getStatusCode()).headers(getHeaders()).wrapper(result); } - public static ApiEntity of(ResponseEntity entity) { + public static ApiResponse of(ResponseEntity entity) { return status(entity.getStatusCode()).headers(entity.getHeaders()).ok(entity.getBody()); } @@ -46,7 +46,7 @@ public class ApiEntity extends ApiCoreEntity> { * @return the created builder * @since 4.1 */ - public static ApiEntity ok() { + public static ApiResponse ok() { return status(HttpStatus.OK).ok(); } @@ -57,24 +57,24 @@ public class ApiEntity extends ApiCoreEntity> { * @return the created {@code ResponseEntity} * @since 4.1 */ - public static ApiEntity ok(E data) { + public static ApiResponse ok(E data) { return status(HttpStatus.OK).ok(data); } - public static ApiEntity build(IRespCode code, E data) { + public static ApiResponse build(IRespCode code, E data) { return status(HttpStatus.OK).build(code, data); } - public static ApiEntityBuilder status(@Nonnull HttpStatus status) { + public static ApiResponseBuilder status(@Nonnull HttpStatus status) { Assert.notNull(status, "HttpStatus must not be null"); - return new ApiEntityBuilder(status); + return new ApiResponseBuilder(status); } - public static ApiEntityBuilder header(String headerName, String... headerValues) { + public static ApiResponseBuilder header(String headerName, String... headerValues) { return status(HttpStatus.OK).header(headerName, headerValues); } - public static ApiEntityBuilder headers(HttpHeaders headers) { + public static ApiResponseBuilder headers(HttpHeaders headers) { return status(HttpStatus.OK).headers(headers); } @@ -86,11 +86,11 @@ public class ApiEntity extends ApiCoreEntity> { * @return the created builder * @since 4.1 */ - public static ApiEntityBuilder created(URI location) { + public static ApiResponseBuilder created(URI location) { return status(HttpStatus.CREATED).location(location); } - public static ApiEntityBuilder created(String location) { + public static ApiResponseBuilder created(String location) { return status(HttpStatus.CREATED).location(Nets.uri(location)); } @@ -100,7 +100,7 @@ public class ApiEntity extends ApiCoreEntity> { * @return the created builder * @since 4.1 */ - public static ApiEntityBuilder accepted() { + public static ApiResponseBuilder accepted() { return status(HttpStatus.ACCEPTED); } @@ -110,7 +110,7 @@ public class ApiEntity extends ApiCoreEntity> { * @return the created builder * @since 4.1 */ - public static ApiEntityBuilder badRequest() { + public static ApiResponseBuilder badRequest() { return status(HttpStatus.BAD_REQUEST); } @@ -120,69 +120,69 @@ public class ApiEntity extends ApiCoreEntity> { * @return the created builder * @since 4.1 */ - public static ApiEntityBuilder notFound() { + public static ApiResponseBuilder notFound() { return status(HttpStatus.NOT_FOUND); } - public static class ApiEntityBuilder extends AbstractBodySetter { + public static class ApiResponseBuilder extends AbstractBodySetter { - private ApiEntityBuilder(HttpStatus status) { + private ApiResponseBuilder(HttpStatus status) { super(status); } - public ApiEntity ok() { + public ApiResponse ok() { return wrapper(ApiResult.ok()); } - public ApiEntity ok(E data) { + public ApiResponse ok(E data) { return wrapper(ApiResult.ok(data)); } @SuppressWarnings("all") - public ApiEntity okOrNotFound(Optional optional) { + public ApiResponse okOrNotFound(Optional optional) { return optional.map(o -> wrapper(ApiResult.ok(o))).orElseGet(() -> { return wrapper(ApiResult.ok()); }); } - public ApiEntity err(IRespCode code) { + public ApiResponse err(IRespCode code) { return wrapper(ApiResult.err(code)); } - public ApiEntity err(IRespCode code, String message) { + public ApiResponse err(IRespCode code, String message) { return wrapper(ApiResult.err(code, message)); } - public ApiEntity err(IRespCode code, E data) { + public ApiResponse err(IRespCode code, E data) { return wrapper(ApiResult.err(code, data)); } - public ApiEntity err(String message) { + public ApiResponse err(String message) { return wrapper(ApiResult.err(message)); } - public ApiEntity err(String code, String message) { + public ApiResponse err(String code, String message) { return wrapper(ApiResult.err(code, message)); } - public ApiEntity with(Throwable e) { + public ApiResponse with(Throwable e) { return wrapper(ApiResult.with(e)); } - public ApiEntity build(IRespCode code) { + public ApiResponse build(IRespCode code) { return build(code, null); } - public ApiEntity build(IRespCode code, E data) { + public ApiResponse build(IRespCode code, E data) { return wrapper(ApiResult.build(code, data)); } - public ApiEntity build(String code, String message, E data) { + public ApiResponse build(String code, String message, E data) { return wrapper(ApiResult.build(code, message, data)); } - ApiEntity wrapper(ApiResult result) { - return new ApiEntity<>(result, super.headers, super.status); + ApiResponse wrapper(ApiResult result) { + return new ApiResponse<>(result, super.headers, super.status); } } } diff --git a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/filter/OrderedBadRequestFilter.java b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/filter/OrderedBadRequestFilter.java index aaf5c21..b6a39c5 100644 --- a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/filter/OrderedBadRequestFilter.java +++ b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/filter/OrderedBadRequestFilter.java @@ -2,7 +2,7 @@ package cn.axzo.framework.web.servlet.filter; import cn.axzo.framework.core.util.ClassUtil; import cn.axzo.framework.domain.web.code.BaseCode; -import cn.axzo.framework.web.http.ApiEntity; +import cn.axzo.framework.web.http.ApiResponse; import cn.axzo.framework.web.servlet.context.RequestMappingHandlerAdapterLazyAware; import io.undertow.server.RequestTooBigException; import io.undertow.server.handlers.form.MultiPartParserDefinition; @@ -87,7 +87,7 @@ public class OrderedBadRequestFilter extends OncePerRequestFilter implements Ord return; } - ApiEntity returnValue = _decideReturnValue(ex); + ApiResponse returnValue = _decideReturnValue(ex); MethodParameter returnType = new ReturnValueMethodParameter(returnValue); val returnValueHandler = _getReturnValueHandler(returnType); if (returnValueHandler == null) { @@ -125,38 +125,38 @@ public class OrderedBadRequestFilter extends OncePerRequestFilter implements Ord .orElse(null); } - private ApiEntity _decideReturnValue(Exception ex) { - ApiEntity returnValue; + private ApiResponse _decideReturnValue(Exception ex) { + ApiResponse returnValue; if (ex instanceof IllegalArgumentException) { - return ApiEntity.badRequest().err(BAD_REQUEST, ex.getMessage()); + return ApiResponse.badRequest().err(BAD_REQUEST, ex.getMessage()); } else if (ex instanceof StringIndexOutOfBoundsException) { - return ApiEntity.badRequest().err(BAD_REQUEST, ERROR_FORM_DATA_NOT_ENCODED); + return ApiResponse.badRequest().err(BAD_REQUEST, ERROR_FORM_DATA_NOT_ENCODED); } else if (ex instanceof IllegalStateException) { return _decideReturnValue((IllegalStateException) ex); } else if (ex instanceof RuntimeException) { return _decideReturnValue((RuntimeException) ex); } - return ApiEntity.status(INTERNAL_SERVER_ERROR).err(BaseCode.SERVER_ERROR); + return ApiResponse.status(INTERNAL_SERVER_ERROR).err(BaseCode.SERVER_ERROR); } - private ApiEntity _decideReturnValue(IllegalStateException ex) { + private ApiResponse _decideReturnValue(IllegalStateException ex) { if (isUndertow) { Throwable cause = ex.getCause(); if (cause instanceof RequestTooBigException) { - return ApiEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).err(PAYLOAD_TOO_LARGE, cause.getMessage()); + return ApiResponse.status(HttpStatus.PAYLOAD_TOO_LARGE).err(PAYLOAD_TOO_LARGE, cause.getMessage()); } if (cause instanceof MultiPartParserDefinition.FileTooLargeException) { - return ApiEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).err(PAYLOAD_TOO_LARGE, cause.getMessage()); + return ApiResponse.status(HttpStatus.PAYLOAD_TOO_LARGE).err(PAYLOAD_TOO_LARGE, cause.getMessage()); } } - return ApiEntity.badRequest().err(BAD_REQUEST, ex.getMessage()); + return ApiResponse.badRequest().err(BAD_REQUEST, ex.getMessage()); } - private ApiEntity _decideReturnValue(RuntimeException ex) { + private ApiResponse _decideReturnValue(RuntimeException ex) { if (ex.getCause() instanceof IOException) { - return ApiEntity.badRequest().err(BAD_REQUEST, ex.getCause().getMessage()); + return ApiResponse.badRequest().err(BAD_REQUEST, ex.getCause().getMessage()); } - return ApiEntity.badRequest().err(BAD_REQUEST, ex.getMessage()); + return ApiResponse.badRequest().err(BAD_REQUEST, ex.getMessage()); } /** diff --git a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreEntityMethodParameter.java b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreResponseMethodParameter.java similarity index 74% rename from axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreEntityMethodParameter.java rename to axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreResponseMethodParameter.java index 80068a2..fcb6f07 100644 --- a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreEntityMethodParameter.java +++ b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreResponseMethodParameter.java @@ -1,6 +1,6 @@ package cn.axzo.framework.web.servlet.method; -import cn.axzo.framework.web.http.ApiCoreEntity; +import cn.axzo.framework.web.http.ApiCoreResponse; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; @@ -11,20 +11,20 @@ import java.lang.reflect.Type; * @Author liyong.tian * @Date 2020/9/9 17:13 **/ -public class ApiCoreEntityMethodParameter extends MethodParameter { +public class ApiCoreResponseMethodParameter extends MethodParameter { private final Object returnValue; private final ResolvableType returnType; - public ApiCoreEntityMethodParameter(MethodParameter parameter, ApiCoreEntity returnValue) { + public ApiCoreResponseMethodParameter(MethodParameter parameter, ApiCoreResponse returnValue) { super(parameter); this.returnValue = returnValue.getBody(); ResolvableType generic = ResolvableType.forType(super.getGenericParameterType()).getGeneric(0); this.returnType = ResolvableType.forClassWithGenerics(returnValue.getBody().getClass(), generic); } - public ApiCoreEntityMethodParameter(ApiCoreEntityMethodParameter original) { + public ApiCoreResponseMethodParameter(ApiCoreResponseMethodParameter original) { super(original); this.returnValue = original.returnValue; this.returnType = original.returnType; @@ -48,6 +48,6 @@ public class ApiCoreEntityMethodParameter extends MethodParameter { @Override public MethodParameter clone() { - return new ApiCoreEntityMethodParameter(this); + return new ApiCoreResponseMethodParameter(this); } } diff --git a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreEntityMethodProcessor.java b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreResponseMethodProcessor.java similarity index 66% rename from axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreEntityMethodProcessor.java rename to axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreResponseMethodProcessor.java index 4f9c2fd..0536811 100644 --- a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreEntityMethodProcessor.java +++ b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/method/ApiCoreResponseMethodProcessor.java @@ -1,6 +1,6 @@ package cn.axzo.framework.web.servlet.method; -import cn.axzo.framework.web.http.ApiCoreEntity; +import cn.axzo.framework.web.http.ApiCoreResponse; import org.springframework.core.MethodParameter; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; @@ -15,17 +15,17 @@ import javax.servlet.http.HttpServletResponse; * @Author liyong.tian * @Date 2020/9/9 17:16 **/ -public class ApiCoreEntityMethodProcessor implements HandlerMethodReturnValueHandler { +public class ApiCoreResponseMethodProcessor implements HandlerMethodReturnValueHandler { private final HttpEntityMethodProcessor httpEntityMethodProcessor; - public ApiCoreEntityMethodProcessor(HttpEntityMethodProcessor httpEntityMethodProcessor) { + public ApiCoreResponseMethodProcessor(HttpEntityMethodProcessor httpEntityMethodProcessor) { this.httpEntityMethodProcessor = httpEntityMethodProcessor; } @Override public boolean supportsReturnType(MethodParameter returnType) { - return ApiCoreEntity.class.isAssignableFrom(returnType.getParameterType()); + return ApiCoreResponse.class.isAssignableFrom(returnType.getParameterType()); } @Override @@ -36,12 +36,12 @@ public class ApiCoreEntityMethodProcessor implements HandlerMethodReturnValueHan } // 设置http status - Assert.isInstanceOf(ApiCoreEntity.class, returnValue); - ApiCoreEntity apiCoreEntity = (ApiCoreEntity) returnValue; - webRequest.getNativeResponse(HttpServletResponse.class).setStatus(apiCoreEntity.getStatusCodeValue()); + Assert.isInstanceOf(ApiCoreResponse.class, returnValue); + ApiCoreResponse apiCoreResponse = (ApiCoreResponse) returnValue; + webRequest.getNativeResponse(HttpServletResponse.class).setStatus(apiCoreResponse.getStatusCodeValue()); //重写返回类型 - returnType = new ApiCoreEntityMethodParameter(returnType, apiCoreEntity); + returnType = new ApiCoreResponseMethodParameter(returnType, apiCoreResponse); httpEntityMethodProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest); } } diff --git a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/security/oauth/CustomOAuth2ExceptionRenderer.java b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/security/oauth/CustomOAuth2ExceptionRenderer.java index 4c2d4b6..6cd85e9 100644 --- a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/security/oauth/CustomOAuth2ExceptionRenderer.java +++ b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/security/oauth/CustomOAuth2ExceptionRenderer.java @@ -1,7 +1,7 @@ package cn.axzo.framework.web.servlet.security.oauth; import cn.axzo.framework.core.util.ClassUtil; -import cn.axzo.framework.web.http.ApiCoreEntity; +import cn.axzo.framework.web.http.ApiCoreResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.http.*; import org.springframework.http.converter.GenericHttpMessageConverter; @@ -54,8 +54,8 @@ public class CustomOAuth2ExceptionRenderer implements OAuth2ExceptionRenderer { if (outputMessage instanceof ServerHttpResponse) { if (httpEntity instanceof ResponseEntity) { ((ServerHttpResponse) outputMessage).setStatusCode(((ResponseEntity) httpEntity).getStatusCode()); - } else if (httpEntity instanceof ApiCoreEntity) { - ((ServerHttpResponse) outputMessage).setStatusCode(((ApiCoreEntity) httpEntity).getStatusCode()); + } else if (httpEntity instanceof ApiCoreResponse) { + ((ServerHttpResponse) outputMessage).setStatusCode(((ApiCoreResponse) httpEntity).getStatusCode()); } } HttpHeaders entityHeaders = httpEntity.getHeaders(); diff --git a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/security/oauth/SpringOAuth2AuthenticationEntryPoint.java b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/security/oauth/SpringOAuth2AuthenticationEntryPoint.java index 63f1d05..e28cae9 100644 --- a/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/security/oauth/SpringOAuth2AuthenticationEntryPoint.java +++ b/axzo-common-webmvc/src/main/java/cn/axzo/framework/web/servlet/security/oauth/SpringOAuth2AuthenticationEntryPoint.java @@ -1,7 +1,7 @@ package cn.axzo.framework.web.servlet.security.oauth; import cn.axzo.framework.domain.web.code.BaseCode; -import cn.axzo.framework.web.http.ApiEntity; +import cn.axzo.framework.web.http.ApiResponse; import org.springframework.http.HttpEntity; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageConverter; @@ -66,7 +66,7 @@ public class SpringOAuth2AuthenticationEntryPoint extends OAuth2AuthenticationEn private HttpEntity beforeBodyWrite(ResponseEntity responseEntity) { OAuth2Exception e = responseEntity.getBody(); - return ApiEntity.status(responseEntity.getStatusCode()) + return ApiResponse.status(responseEntity.getStatusCode()) .headers(responseEntity.getHeaders()) .err(BaseCode.parse(e.getHttpErrorCode()), OAuth2Util.getMessage(e)); }