-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add Http Method configuration. That will be used for sending data to target. #198
base: main
Are you sure you want to change the base?
Conversation
… endpoint, Defaulted on POST Method. Supported POST/PUT
Fix linter reported issue
Fix Linter reported issue
Fix Linter reported issue
There was a problem hiding this 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
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)); | ||
} |
There was a problem hiding this comment.
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.
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)); |
There was a problem hiding this comment.
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
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)); |
|
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
// Check the messages have been sent once | ||
messages.forEach( | ||
message -> bodyPublishers.verify(() -> HttpRequest.BodyPublishers.ofString(eq(message)), times(1))); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
@@ -88,7 +89,7 @@ void shouldBuildDefaultHttpRequest() throws Exception { | |||
.isPresent() | |||
.get(as(InstanceOfAssertFactories.DURATION)) | |||
.hasSeconds(config.httpTimeout()); | |||
assertThat(httpRequest.method()).isEqualTo("POST"); | |||
assertThat(httpRequest.method()).isEqualTo(HttpMethodsType.POST.name()); |
There was a problem hiding this comment.
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
final var requestBuilder = prepareRequest(body); | ||
return sendWithRetries(requestBuilder, HttpResponseHandler.ON_HTTP_ERROR_RESPONSE_HANDLER, | ||
config.maxRetries()); |
There was a problem hiding this comment.
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
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()); |
Add configuration for HTTP Method for the target endpoint.
Default is POST supported values: [POST/PUT]