suxiaoyang 6 роки тому
батько
коміт
c1f9e11c1d

+ 1 - 1
cat-starter/src/main/java/com/yihu/cat/CatOkHttpInterceptor.java

@ -18,7 +18,7 @@ public class CatOkHttpInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Transaction t = Cat.newTransaction(CatConstants.TYPE_CALL, request.url().toString());
        Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, request.url().toString());
        try {
            //保存和传递CAT调用链上下文
            CatContext ctx = new CatContext();

+ 21 - 5
cat-starter/src/main/java/com/yihu/cat/CatServletFilter.java

@ -7,9 +7,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * http://tx.cat.weimob.com/cat/doc.html - 部分说明文档
 * Filter - Cat基础过滤器
 * Created by progr1mmer on 2018/9/4.
 */
@ -27,7 +29,7 @@ public class CatServletFilter implements Filter {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        CatHeaderRequestWrapper headerRequestWrapper = new CatHeaderRequestWrapper(request);
        if (isRoot(request)) {
            Transaction t = Cat.newTransaction(CatConstants.TYPE_CALL, request.getRequestURL().toString());
            Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, request.getRequestURL().toString());
            try {
                Cat.logEvent("Request.remoteHost", request.getRemoteHost());
                Cat.logEvent("Request.params", objectMapper.writeValueAsString(request.getParameterMap()));
@ -39,13 +41,20 @@ public class CatServletFilter implements Filter {
                headerRequestWrapper.putHeader(Cat.Context.CHILD, catContext.getProperty(Cat.Context.CHILD));
                filterChain.doFilter(headerRequestWrapper, servletResponse);
                if (null == request.getAttribute(CatErrorConstants.ERROR_FOR_CAT)) {
                    t.setStatus(Transaction.SUCCESS);
                    Integer status = ((HttpServletResponse) servletResponse).getStatus();
                    if (status != 500) {
                        t.setStatus(Transaction.SUCCESS);
                    } else {
                        Cat.logError(new IllegalStateException(status.toString()));
                        t.setStatus(new IllegalStateException(status.toString()));
                    }
                } else {
                    Cat.logError((Exception)request.getAttribute(CatErrorConstants.ERROR_FOR_CAT));
                    t.setStatus((Exception)request.getAttribute(CatErrorConstants.ERROR_FOR_CAT));
                }
            } catch (Exception e) {
                Cat.logError(e);
                t.setStatus(e);
                Cat.getProducer().logError(e);
                throw e;
            } finally {
                t.complete();
@ -62,13 +71,20 @@ public class CatServletFilter implements Filter {
                Cat.logEvent("Request.params", objectMapper.writeValueAsString(request.getParameterMap()));
                filterChain.doFilter(headerRequestWrapper, servletResponse);
                if (null == request.getAttribute(CatErrorConstants.ERROR_FOR_CAT)) {
                    t.setStatus(Transaction.SUCCESS);
                    Integer status = ((HttpServletResponse) servletResponse).getStatus();
                    if (status != 500) {
                        t.setStatus(Transaction.SUCCESS);
                    } else {
                        Cat.logError(new IllegalStateException(status.toString()));
                        t.setStatus(new IllegalStateException(status.toString()));
                    }
                } else {
                    Cat.logError((Exception)request.getAttribute(CatErrorConstants.ERROR_FOR_CAT));
                    t.setStatus((Exception)request.getAttribute(CatErrorConstants.ERROR_FOR_CAT));
                }
            } catch (Exception e) {
                t.setStatus(e);
                Cat.logError(e);
                t.setStatus(e);
                throw e;
            } finally {
                t.complete();