mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
judging xid status to avoid repeated processing
This commit is contained in:
parent
742d84bc53
commit
d383fb4677
@ -40,10 +40,15 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
|||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(SeataHandlerInterceptor.class);
|
.getLogger(SeataHandlerInterceptor.class);
|
||||||
|
|
||||||
|
public static final String BIND_XID = "BIND_XID";
|
||||||
|
|
||||||
|
public static final String UNBIND_XID = "UNBIND_XID";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||||
Object handler) {
|
Object handler) {
|
||||||
|
Object xid_status = request.getAttribute(BIND_XID);
|
||||||
|
if (null == xid_status || !(boolean)xid_status) {
|
||||||
String xid = RootContext.getXID();
|
String xid = RootContext.getXID();
|
||||||
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -52,10 +57,12 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
|||||||
|
|
||||||
if (xid == null && rpcXid != null) {
|
if (xid == null && rpcXid != null) {
|
||||||
RootContext.bind(rpcXid);
|
RootContext.bind(rpcXid);
|
||||||
|
request.setAttribute(BIND_XID, true);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("bind {} to RootContext", rpcXid);
|
log.debug("bind {} to RootContext", rpcXid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +76,8 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object xid_status = request.getAttribute(UNBIND_XID);
|
||||||
|
if (null == xid_status || !(boolean)xid_status) {
|
||||||
String unbindXid = RootContext.unbind();
|
String unbindXid = RootContext.unbind();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("unbind {} from RootContext", unbindXid);
|
log.debug("unbind {} from RootContext", unbindXid);
|
||||||
@ -77,9 +86,11 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
|||||||
log.warn("xid in change during RPC from {} to {}", rpcXid, unbindXid);
|
log.warn("xid in change during RPC from {} to {}", rpcXid, unbindXid);
|
||||||
if (unbindXid != null) {
|
if (unbindXid != null) {
|
||||||
RootContext.bind(unbindXid);
|
RootContext.bind(unbindXid);
|
||||||
|
request.setAttribute(UNBIND_XID, true);
|
||||||
log.warn("bind {} back to RootContext", unbindXid);
|
log.warn("bind {} back to RootContext", unbindXid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user