package info.aspirecn.iov.sjjh.servicenode.fed.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;

/**
 * @author jianggang
 * @Date 2018/11/21 14:07:12
 * @Description
 */

@Slf4j
public class RequestForwardFiler extends ZuulFilter {

    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return FilterConstants.PRE_DECORATION_FILTER_ORDER + 1;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run(){
        RequestContext context = RequestContext.getCurrentContext();
        Object originalRequestPath = context.get(FilterConstants.REQUEST_URI_KEY);
        log.info("originalRequestPath:{}",originalRequestPath);
        String modifiedRequestPath = "/api/portal/v1" + originalRequestPath;
        log.info("modifiedRequestPath:{}",modifiedRequestPath);
        context.put(FilterConstants.REQUEST_URI_KEY,modifiedRequestPath);
        log.info("------------>{}",modifiedRequestPath);
        return null;
    }
}
