Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HttpChangeConsumer.java - Adding ability to attach autorization header #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class HttpChangeConsumer extends BaseChangeConsumer implements DebeziumEn
private static final String PROP_CLIENT_TIMEOUT = "timeout.ms";
private static final String PROP_RETRIES = "retries";
private static final String PROP_RETRY_INTERVAL = "retry.interval.ms";
private static final String PROP_AUTORIZATION_HEADER = "authorization";

private static final Long HTTP_TIMEOUT = Integer.toUnsignedLong(60000); // Default to 60s
private static final int DEFAULT_RETRIES = 5;
Expand All @@ -67,6 +68,7 @@ public class HttpChangeConsumer extends BaseChangeConsumer implements DebeziumEn
void connect() throws URISyntaxException {
String sinkUrl;
String contentType;
String authorizationHeader;

client = HttpClient.newHttpClient();
final Config config = ConfigProvider.getConfig();
Expand All @@ -90,6 +92,10 @@ void connect() throws URISyntaxException {

config.getOptionalValue(PROP_PREFIX + PROP_RETRY_INTERVAL, String.class)
.ifPresent(t -> retryInterval = Duration.ofMillis(Long.parseLong(t)));

if (config.getOptionalValue(PROP_PREFIX + PROP_AUTORIZATION_HEADER, String.class) != null) {
authorizationHeader = config.getOptionalValue(PROP_PREFIX + PROP_AUTORIZATION_HEADER, String.class);
}

switch (config.getValue("debezium.format.value", String.class)) {
case "avro":
Expand All @@ -107,6 +113,10 @@ void connect() throws URISyntaxException {
LOGGER.info("Using sink URL: {}", sinkUrl);
requestBuilder = HttpRequest.newBuilder(new URI(sinkUrl)).timeout(timeoutDuration);
requestBuilder.setHeader("content-type", contentType);
if (authorizationHeader != null) {
LOGGER.info("Using authorization header {}", authorizationHeader);
requestBuilder.setHeader("authorization",authorizationHeader);
}
}

@Override
Expand Down