ru.redcom.lib.integration.api.client.dadata.HeaderRequestInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dadata-api-client Show documentation
Show all versions of dadata-api-client Show documentation
DaData.ru Standardization API client java library
The newest version!
/*
* Copyright (c) 2018 Boris Fox, REDCOM-Internet CJSC
* All rights reserved.
*/
package ru.redcom.lib.integration.api.client.dadata;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
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.lang.NonNull;
import java.io.IOException;
/**
* Request Interceptor to add credentials headers.
*
* @author boris
*/
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
class HeaderRequestInterceptor implements ClientHttpRequestInterceptor {
@NonNull private final String headerName;
@NonNull private final String headerValue;
@NonNull
@Override
public ClientHttpResponse intercept(@NonNull final HttpRequest request, @NonNull final byte[] body,
@NonNull final ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().set(headerName, headerValue);
return execution.execute(request, body);
}
}