cn.majingjing.http.client.interceptor.impl.HttpTraceIdInterceptor Maven / Gradle / Ivy
The newest version!
package cn.majingjing.http.client.interceptor.impl;
import cn.majingjing.http.client.exception.HttpClientException;
import cn.majingjing.http.client.handler.chain.HttpChain;
import cn.majingjing.http.client.interceptor.HttpInterceptor;
import cn.majingjing.http.client.request.HttpRequest;
import cn.majingjing.http.client.response.HttpResponse;
import cn.majingjing.http.client.util.HttpConstant;
import cn.majingjing.http.client.util.StringUtils;
import java.util.Collections;
/**
* @author MaJingjing
* @date 2022/6/7 22:54
*/
public class HttpTraceIdInterceptor implements HttpInterceptor {
@Override
public HttpResponse intercept(HttpChain chain) throws HttpClientException {
final HttpRequest httpRequest = chain.getHttpRequest();
httpRequest.getHeaders().putIfAbsent(HttpConstant.TRACE_ID_NAME,StringUtils.guid());
HttpResponse response = chain.proceed(chain.getHttpRequest());
response.getHeaders().putIfAbsent(HttpConstant.TRACE_ID_NAME, Collections.unmodifiableList(Collections.singletonList(httpRequest.getTraceId())));
return response;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy