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

com.cloud.boot.exception.support.ActionTrackInterceptor Maven / Gradle / Ivy

package com.cloud.boot.exception.support;

import com.alibaba.fastjson.JSONObject;
import com.cloud.boot.util.encryption.AESUtil;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;
import java.io.IOException;

@Component
public class ActionTrackInterceptor implements ClientHttpRequestInterceptor {

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
            throws IOException {
        HttpHeaders headers = request.getHeaders();
        long time = System.currentTimeMillis();
        String key = AESUtil.encrypt(String.valueOf(time), null);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("value", time);
        jsonObject.put("key", key);
        headers.add("cus_referer", jsonObject.toString());
        // 保证请求继续被执行
        return execution.execute(request, body);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy