All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codingapi.tx.springcloud.interceptor.TxManagerInterceptor Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package com.codingapi.tx.springcloud.interceptor;

import com.codingapi.tx.aop.service.AspectBeforeService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by lorne on 2017/6/7.
 */

@Component
public class TxManagerInterceptor {

    @Autowired
    private AspectBeforeService aspectBeforeService;

    public Object around(ProceedingJoinPoint point) throws Throwable {
        String groupId = null;
        int maxTimeOut = 0;
        try {
            RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
            HttpServletRequest request = requestAttributes == null ? null : ((ServletRequestAttributes) requestAttributes).getRequest();
            groupId = request == null ? null : request.getHeader("tx-group");
            maxTimeOut = request == null?0:Integer.parseInt(request.getHeader("tx-maxTimeOut"));
        }catch (Exception e){}
        return aspectBeforeService.around(groupId,maxTimeOut, point);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy