34 lines
1.1 KiB
Java
34 lines
1.1 KiB
Java
package com.iconplus.smartproc.helper.context;
|
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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;
|
|
|
|
@Log4j2
|
|
@Component
|
|
public class HttpHeadersInterceptor implements ClientHttpRequestInterceptor {
|
|
|
|
@Autowired
|
|
private ApiContext apiContext;
|
|
|
|
public HttpHeadersInterceptor(ApiContext apiContext) {
|
|
this.apiContext = apiContext;
|
|
}
|
|
|
|
@Override
|
|
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
|
ClientHttpRequestExecution execution) throws IOException {
|
|
apiContext.getHttpHeaders().entrySet().stream()
|
|
.filter(x -> x.getKey() != null)
|
|
.forEach(x -> request.getHeaders().add(x.getKey(), x.getValue().get(0)));
|
|
return execution.execute(request, body);
|
|
}
|
|
|
|
}
|