|
|
@ -41,45 +41,46 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
|
|
|
.getLogger(SeataHandlerInterceptor.class);
|
|
|
|
.getLogger(SeataHandlerInterceptor.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
|
|
|
String xid = RootContext.getXID();
|
|
|
|
Object handler) {
|
|
|
|
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
|
|
|
String xid = RootContext.getXID();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
|
|
|
log.debug("xid in RootContext {} xid in RpcContext {}", xid, rpcXid);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("xid in RootContext {} xid in RpcContext {}", xid, rpcXid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(xid) && rpcXid != null) {
|
|
|
|
if (StringUtils.isBlank(xid) && rpcXid != null) {
|
|
|
|
RootContext.bind(rpcXid);
|
|
|
|
RootContext.bind(rpcXid);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("bind {} to RootContext", rpcXid);
|
|
|
|
log.debug("bind {} to RootContext", rpcXid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
|
|
|
|
|
|
|
Object handler, Exception e) {
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(RootContext.getXID())) {
|
|
|
|
|
|
|
|
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
if (StringUtils.isEmpty(rpcXid)) {
|
|
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
|
|
|
|
return;
|
|
|
|
if (StringUtils.isNotBlank(RootContext.getXID())) {
|
|
|
|
}
|
|
|
|
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(rpcXid)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!rpcXid.equalsIgnoreCase(unbindXid)) {
|
|
|
|
if (!rpcXid.equalsIgnoreCase(unbindXid)) {
|
|
|
|
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);
|
|
|
|
log.warn("bind {} back to RootContext", unbindXid);
|
|
|
|
log.warn("bind {} back to RootContext", unbindXid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|