diff --git a/example/example-application/pom.xml b/example/example-application/pom.xml index c61d2469..bfb05799 100644 --- a/example/example-application/pom.xml +++ b/example/example-application/pom.xml @@ -5,7 +5,7 @@ springboot-example com.codingapi.springboot - 3.3.6 + 3.3.10 4.0.0 diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java b/example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java index b1d2cba3..34b02124 100644 --- a/example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java +++ b/example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java @@ -1,6 +1,8 @@ package com.codingapi.example.handler; +import com.codingapi.example.event.AEvent; import com.codingapi.example.event.CEvent; +import com.codingapi.springboot.framework.event.EventPusher; import com.codingapi.springboot.framework.event.EventTraceContext; import com.codingapi.springboot.framework.event.IHandler; import lombok.extern.slf4j.Slf4j; @@ -14,7 +16,7 @@ public class CHandler implements IHandler { public void handler(CEvent event) { log.info("c event:{},eventKey:{}", event, EventTraceContext.getInstance().getEventKey()); -// EventPusher.push(new AEvent()); +// EventPusher.push(new AEvent(),true); // throw new RuntimeException("c handler error"); } diff --git a/example/example-domain/pom.xml b/example/example-domain/pom.xml index 3a437d43..ca585179 100644 --- a/example/example-domain/pom.xml +++ b/example/example-domain/pom.xml @@ -5,7 +5,7 @@ springboot-example com.codingapi.springboot - 3.3.6 + 3.3.10 4.0.0 diff --git a/example/example-infra-flow/pom.xml b/example/example-infra-flow/pom.xml index 4ede4627..95ce0607 100644 --- a/example/example-infra-flow/pom.xml +++ b/example/example-infra-flow/pom.xml @@ -5,7 +5,7 @@ springboot-example com.codingapi.springboot - 3.3.6 + 3.3.10 4.0.0 diff --git a/example/example-infra-jpa/pom.xml b/example/example-infra-jpa/pom.xml index 9809444d..0159872f 100644 --- a/example/example-infra-jpa/pom.xml +++ b/example/example-infra-jpa/pom.xml @@ -5,7 +5,7 @@ springboot-example com.codingapi.springboot - 3.3.6 + 3.3.10 4.0.0 diff --git a/example/example-server/pom.xml b/example/example-server/pom.xml index 71ec3c93..06f6e28d 100644 --- a/example/example-server/pom.xml +++ b/example/example-server/pom.xml @@ -5,7 +5,7 @@ springboot-example com.codingapi.springboot - 3.3.6 + 3.3.10 4.0.0 diff --git a/example/pom.xml b/example/pom.xml index 7c000f17..08914efa 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -17,7 +17,7 @@ springboot-example - 3.3.6 + 3.3.10 springboot-example springboot-example project for Spring Boot diff --git a/pom.xml b/pom.xml index 59cb5b08..56c6bdcd 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.codingapi.springboot springboot-parent - 3.3.6 + 3.3.10 https://github.com/codingapi/springboot-framewrok springboot-parent diff --git a/springboot-starter-data-fast/pom.xml b/springboot-starter-data-fast/pom.xml index 537cc3ec..a16f8486 100644 --- a/springboot-starter-data-fast/pom.xml +++ b/springboot-starter-data-fast/pom.xml @@ -5,7 +5,7 @@ springboot-parent com.codingapi.springboot - 3.3.6 + 3.3.10 4.0.0 diff --git a/springboot-starter-flow/pom.xml b/springboot-starter-flow/pom.xml index 0fedb300..ad52840d 100644 --- a/springboot-starter-flow/pom.xml +++ b/springboot-starter-flow/pom.xml @@ -6,7 +6,7 @@ springboot-parent com.codingapi.springboot - 3.3.6 + 3.3.10 springboot-starter-flow @@ -46,5 +46,30 @@ + + + + org.jacoco + jacoco-maven-plugin + 0.8.12 + + + + prepare-agent + + + + report + test + + report + + + + + + + + diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java index 7e032bd8..cb98e66d 100644 --- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java +++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java @@ -97,7 +97,7 @@ public void urge(long recordId, IFlowOperator currentOperator) { // 推送催办消息 for (FlowRecord record : todoRecords) { IFlowOperator pushOperator = record.getCurrentOperator(); - EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_URGE, record, pushOperator, flowWork, null)); + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_URGE, record, pushOperator, flowWork, null),true); } } @@ -220,10 +220,10 @@ public void transfer(long recordId, IFlowOperator currentOperator, IFlowOperator flowRecordRepository.save(List.of(transferRecord)); // 推送转办消息 - EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TRANSFER, flowRecord, currentOperator, flowWork, snapshot.toBindData())); + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TRANSFER, flowRecord, currentOperator, flowWork, snapshot.toBindData()),true); // 推送待办消息 - EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, transferRecord, targetOperator, flowWork, snapshot.toBindData())); + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, transferRecord, targetOperator, flowWork, snapshot.toBindData()),true); } @@ -327,8 +327,8 @@ public FlowResult startFlow(String workCode, IFlowOperator operator, IBindData b // 推送事件消息 for (FlowRecord record : records) { - EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_CREATE, record, operator, flowWork, snapshot.toBindData())); - EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, record, operator, flowWork, snapshot.toBindData())); + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_CREATE, record, operator, flowWork, snapshot.toBindData()),true); + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, record, operator, flowWork, snapshot.toBindData()),true); } // 当前的审批记录 return new FlowResult(flowWork, records); @@ -426,7 +426,7 @@ public FlowResult submitFlow(long recordId, IFlowOperator currentOperator, IBind flowRecordRepository.update(flowRecord); flowRecordRepository.finishFlowRecordByProcessId(flowRecord.getProcessId()); - EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_FINISH, flowRecord, currentOperator, flowWork, snapshot.toBindData())); + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_FINISH, flowRecord, currentOperator, flowWork, snapshot.toBindData()),true); return new FlowResult(flowWork, flowRecord); } @@ -465,12 +465,12 @@ public FlowResult submitFlow(long recordId, IFlowOperator currentOperator, IBind // 推送审批事件消息 int eventState = flowSourceDirection == FlowSourceDirection.PASS ? FlowApprovalEvent.STATE_PASS : FlowApprovalEvent.STATE_REJECT; - EventPusher.push(new FlowApprovalEvent(eventState, flowRecord, currentOperator, flowWork, snapshot.toBindData())); + EventPusher.push(new FlowApprovalEvent(eventState, flowRecord, currentOperator, flowWork, snapshot.toBindData()),true); // 推送待办事件消息 for (FlowRecord record : records) { IFlowOperator pushOperator = record.getCurrentOperator(); - EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, record, pushOperator, flowWork, snapshot.toBindData())); + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO, record, pushOperator, flowWork, snapshot.toBindData()),true); } return new FlowResult(flowWork, records); @@ -514,7 +514,7 @@ public void recall(long recordId, IFlowOperator currentOperator) { flowRecordRepository.update(flowRecord); flowRecordRepository.delete(childrenRecords); - EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_RECALL, flowRecord, currentOperator, flowWork, null)); + EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_RECALL, flowRecord, currentOperator, flowWork, null),true); } } diff --git a/springboot-starter-security/pom.xml b/springboot-starter-security/pom.xml index 7224f6f0..302d295c 100644 --- a/springboot-starter-security/pom.xml +++ b/springboot-starter-security/pom.xml @@ -6,7 +6,7 @@ springboot-parent com.codingapi.springboot - 3.3.6 + 3.3.10 springboot-starter-security diff --git a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/AutoConfiguration.java b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/AutoConfiguration.java index 54a77d48..2f40a953 100644 --- a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/AutoConfiguration.java +++ b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/AutoConfiguration.java @@ -71,7 +71,7 @@ public void preHandle(HttpServletRequest request, HttpServletResponse response, } @Override - public LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest, Token token) { + public LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest,UserDetails user, Token token) { LoginResponse loginResponse = new LoginResponse(); loginResponse.setToken(token.getToken()); loginResponse.setUsername(token.getUsername()); diff --git a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAccessDeniedHandler.java b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAccessDeniedHandler.java index 191d1dfc..a1a9bafd 100644 --- a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAccessDeniedHandler.java +++ b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAccessDeniedHandler.java @@ -20,6 +20,10 @@ public class MyAccessDeniedHandler implements AccessDeniedHandler { public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { log.debug("access denied"); String content = JSONObject.toJSONString(Response.buildFailure("not.access", "please check user authentication.")); + // 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8 + response.setContentType("application/json;charset=UTF-8"); + response.setCharacterEncoding("UTF-8"); + IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8); } } diff --git a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAuthenticationFilter.java b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAuthenticationFilter.java index dd414bdd..2fb81212 100644 --- a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAuthenticationFilter.java +++ b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyAuthenticationFilter.java @@ -80,6 +80,10 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse private void writeResponse(HttpServletResponse servletResponse, Response returnResponse) throws IOException { String content = JSONObject.toJSONString(returnResponse); + // 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8 + servletResponse.setContentType("application/json;charset=UTF-8"); + servletResponse.setCharacterEncoding("UTF-8"); + IOUtils.write(content, servletResponse.getOutputStream(), StandardCharsets.UTF_8); } diff --git a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLoginFilter.java b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLoginFilter.java index 728760b3..a110aa32 100644 --- a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLoginFilter.java +++ b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLoginFilter.java @@ -6,10 +6,15 @@ import com.codingapi.springboot.security.dto.request.LoginRequest; import com.codingapi.springboot.security.dto.request.LoginRequestContext; import com.codingapi.springboot.security.dto.response.LoginResponse; -import com.codingapi.springboot.security.gateway.TokenGateway; import com.codingapi.springboot.security.gateway.Token; import com.codingapi.springboot.security.gateway.TokenContext; +import com.codingapi.springboot.security.gateway.TokenGateway; import com.codingapi.springboot.security.properties.CodingApiSecurityProperties; +import io.jsonwebtoken.Header; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.springframework.security.authentication.AuthenticationManager; @@ -18,14 +23,10 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.stream.Collectors; @@ -58,7 +59,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ throw new AuthenticationServiceException("request stream read was null."); } try { - loginHandler.preHandle(request,response,login); + loginHandler.preHandle(request, response, login); } catch (Exception e) { throw new AuthenticationServiceException(e.getLocalizedMessage()); } @@ -69,15 +70,20 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ @Override protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { log.debug("login success authentication ~"); - User user = (User) authResult.getPrincipal(); + UserDetails user = (UserDetails) authResult.getPrincipal(); LoginRequest loginRequest = LoginRequestContext.getInstance().get(); Token token = tokenGateway.create(user.getUsername(), loginRequest.getPassword(), user.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()), TokenContext.getExtra()); - LoginResponse loginResponse = loginHandler.postHandle(request,response,loginRequest,token); + LoginResponse loginResponse = loginHandler.postHandle(request, response, loginRequest, user, token); String content = JSONObject.toJSONString(SingleResponse.of(loginResponse)); + + // 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8 + response.setContentType("application/json;charset=UTF-8"); + response.setCharacterEncoding("UTF-8"); + IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8); LoginRequestContext.getInstance().clean(); @@ -89,7 +95,13 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException { log.debug("login fail authentication ~"); String content = JSONObject.toJSONString(Response.buildFailure("login.error", failed.getMessage())); + + // 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8 + response.setContentType("application/json;charset=UTF-8"); + response.setCharacterEncoding("UTF-8"); + IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8); + LoginRequestContext.getInstance().clean(); } } diff --git a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLogoutSuccessHandler.java b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLogoutSuccessHandler.java index 16a86c68..247bad68 100644 --- a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLogoutSuccessHandler.java +++ b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyLogoutSuccessHandler.java @@ -20,6 +20,10 @@ public class MyLogoutSuccessHandler implements LogoutSuccessHandler { public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { log.debug("logout success ~"); String content = JSONObject.toJSONString(Response.buildSuccess()); + // 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8 + response.setContentType("application/json;charset=UTF-8"); + response.setCharacterEncoding("UTF-8"); + IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8); } } diff --git a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyUnAuthenticationEntryPoint.java b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyUnAuthenticationEntryPoint.java index ecc91b95..84716a70 100644 --- a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyUnAuthenticationEntryPoint.java +++ b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/MyUnAuthenticationEntryPoint.java @@ -20,6 +20,10 @@ public class MyUnAuthenticationEntryPoint implements AuthenticationEntryPoint { public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { log.debug("no authentication ~"); String content = JSONObject.toJSONString(Response.buildFailure("not.login", "please to login.")); + // 设置响应的 Content-Type 为 JSON,并指定字符编码为 UTF-8 + response.setContentType("application/json;charset=UTF-8"); + response.setCharacterEncoding("UTF-8"); + IOUtils.write(content, response.getOutputStream(), StandardCharsets.UTF_8); } } diff --git a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/SecurityLoginHandler.java b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/SecurityLoginHandler.java index d367eeab..a9e68ba8 100644 --- a/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/SecurityLoginHandler.java +++ b/springboot-starter-security/src/main/java/com/codingapi/springboot/security/filter/SecurityLoginHandler.java @@ -5,11 +5,13 @@ import com.codingapi.springboot.security.gateway.Token; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; public interface SecurityLoginHandler { void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest) throws Exception; - LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest, Token token); + LoginResponse postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest loginRequest, UserDetails user, Token token); } diff --git a/springboot-starter/pom.xml b/springboot-starter/pom.xml index 61ea65e9..84c7d44a 100644 --- a/springboot-starter/pom.xml +++ b/springboot-starter/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot springboot-parent - 3.3.6 + 3.3.10 springboot-starter diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/DomainEventContext.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/DomainEventContext.java index a22799e2..7d10e38c 100644 --- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/DomainEventContext.java +++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/DomainEventContext.java @@ -23,9 +23,13 @@ public static DomainEventContext getInstance() { return instance; } - private void push(IEvent event, boolean sync) { + private void push(IEvent event, boolean sync,boolean hasLoopEvent) { if (context != null) { String traceId = EventTraceContext.getInstance().getOrCreateTrace(); + if(hasLoopEvent){ + EventTraceContext.getInstance().clearTrace(); + traceId = EventTraceContext.getInstance().getOrCreateTrace(); + } EventTraceContext.getInstance().addEvent(traceId,event); context.publishEvent(new DomainEvent(event, sync,traceId)); } @@ -36,13 +40,13 @@ private void push(IEvent event, boolean sync) { * @see EventPusher * 默认 同步事件 */ - public void push(IEvent event) { + public void push(IEvent event,boolean hasLoopEvent) { if (event instanceof IAsyncEvent) { - this.push(event, false); + this.push(event, false,hasLoopEvent); } else if (event instanceof ISyncEvent) { - this.push(event, true); + this.push(event, true,hasLoopEvent); } else { - this.push(event, true); + this.push(event, true,hasLoopEvent); } } diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/EventPusher.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/EventPusher.java index ee90ddd8..333569ea 100644 --- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/EventPusher.java +++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/EventPusher.java @@ -5,7 +5,23 @@ */ public class EventPusher { + /** + * 推送事件 + * 默认将自动检测事件是否有循环事件,当出现循环事件时,系统将会抛出循环调用异常。 + * @param event 事件 + */ public static void push(IEvent event) { - DomainEventContext.getInstance().push(event); + push(event, false); + } + + /** + * 推送事件 + * 默认将自动检测事件是否有循环事件,当出现循环事件时,系统将会抛出循环调用异常。 + * 设置hasLoopEvent为true,将不会检测循环事件。 + * @param event 事件 + * @param hasLoopEvent 是否有循环事件 + */ + public static void push(IEvent event, boolean hasLoopEvent) { + DomainEventContext.getInstance().push(event, hasLoopEvent); } } diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/EventTraceContext.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/EventTraceContext.java index 844d2cf9..562e2768 100644 --- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/EventTraceContext.java +++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/event/EventTraceContext.java @@ -45,12 +45,19 @@ public String getEventKey() { return threadLocal.get(); } + /** + * create event key + * @param traceId traceId + */ void createEventKey(String traceId) { String eventKey = traceId + "#" + RandomGenerator.randomString(8); eventKeyState.put(eventKey, false); threadLocal.set(eventKey); } + /** + * check event state + */ void checkEventState() { String eventKey = threadLocal.get(); if (eventKey != null) { @@ -66,6 +73,11 @@ void checkEventState() { threadLocal.remove(); } + /** + * add event + * @param traceId traceId + * @param event event + */ void addEvent(String traceId, IEvent event) { boolean hasEventLoop = EventStackContext.getInstance().checkEventLoop(traceId, event); if (hasEventLoop) { @@ -78,4 +90,18 @@ void addEvent(String traceId, IEvent event) { } EventStackContext.getInstance().addEvent(traceId, event); } + + /** + * clear trace + */ + public void clearTrace() { + String eventKey = threadLocal.get(); + if (eventKey != null) { + String traceId = eventKey.split("#")[0]; + traceKeys.remove(traceId); + EventStackContext.getInstance().remove(traceId); + eventKeyState.remove(eventKey); + threadLocal.remove(); + } + } } diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/exception/EventException.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/exception/EventException.java index 68462e73..5a506fec 100644 --- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/exception/EventException.java +++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/exception/EventException.java @@ -13,5 +13,8 @@ public class EventException extends RuntimeException { public EventException(List error) { super(error.stream().map(Exception::getMessage).collect(Collectors.joining("\n"))); this.error = error; + for (Exception e : error) { + e.printStackTrace(); + } } }