Skip to content

Add Http Method configuration. That will be used for sending data to target.#198

Open
ecararus wants to merge 4 commits intoAiven-Open:mainfrom
ecararus:add_http_method_configuration
Open

Add Http Method configuration. That will be used for sending data to target.#198
ecararus wants to merge 4 commits intoAiven-Open:mainfrom
ecararus:add_http_method_configuration

Conversation

@ecararus
Copy link

@ecararus ecararus commented Oct 5, 2023

Add configuration for HTTP Method for the target endpoint.
Default is POST supported values: [POST/PUT]

… endpoint, Defaulted on POST Method. Supported POST/PUT
@ecararus ecararus changed the title Add Http Method configuration. Tto be used for sending data to target. Add Http Method configuration. That will be used for sending data to target. Oct 5, 2023
@jeqo jeqo self-requested a review October 26, 2023 09:11
Fix linter reported issue
Fix Linter reported issue
Fix Linter reported issue
Copy link
Contributor

@jeqo jeqo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ecararus! Overall, this improvement looks good to add into the connector.
I added a few comments on the config enum and few other nits. Let me know if anything is unclear.

PS. To test checkstyle locally that have been failling, you can run ./gradlew checkstyleMain checkstyleTest

Comment on lines +28 to +40
public final String name;

HttpMethodsType(final String name) {
this.name = name;
}

public static HttpMethodsType forName(final String name) {
Objects.requireNonNull(name);
return Arrays.stream(values())
.filter(v -> v.name.equalsIgnoreCase(name))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("HTTP Method type: " + name));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can stick to just use the Enum name, and remove the attribute. See OAuth2AuthorizationMode which already support a configuration.

Comment on lines +58 to +64
switch (config.httpMethod()) {
case POST:
return httpRequestBuilder
.build(config).POST(HttpRequest.BodyPublishers.ofString(body));
case PUT:
return httpRequestBuilder
.build(config).PUT(HttpRequest.BodyPublishers.ofString(body));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move the repeated code up

Suggested change
switch (config.httpMethod()) {
case POST:
return httpRequestBuilder
.build(config).POST(HttpRequest.BodyPublishers.ofString(body));
case PUT:
return httpRequestBuilder
.build(config).PUT(HttpRequest.BodyPublishers.ofString(body));
final var httpRequest = httpRequestBuilder.build(config);
switch (config.httpMethod()) {
case POST:
return httpRequest.POST(HttpRequest.BodyPublishers.ofString(body));
case PUT:
return httpRequest.PUT(HttpRequest.BodyPublishers.ofString(body));


}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change

// Check the messages have been sent once
messages.forEach(
message -> bodyPublishers.verify(() -> HttpRequest.BodyPublishers.ofString(eq(message)), times(1)));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change

.get(as(InstanceOfAssertFactories.DURATION))
.hasSeconds(config.httpTimeout());
assertThat(httpRequest.method()).isEqualTo("POST");
assertThat(httpRequest.method()).isEqualTo(HttpMethodsType.POST.name());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can stick to the string values here, so if enum changes, then tests will fail. Same for new put tests

Comment on lines +51 to 53
final var requestBuilder = prepareRequest(body);
return sendWithRetries(requestBuilder, HttpResponseHandler.ON_HTTP_ERROR_RESPONSE_HANDLER,
config.maxRetries());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can improve the naming here

Suggested change
final var requestBuilder = prepareRequest(body);
return sendWithRetries(requestBuilder, HttpResponseHandler.ON_HTTP_ERROR_RESPONSE_HANDLER,
config.maxRetries());
final var request = prepareRequest(body);
return sendWithRetries(request, HttpResponseHandler.ON_HTTP_ERROR_RESPONSE_HANDLER, config.maxRetries());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants