Add Http Method configuration. That will be used for sending data to target.#198
Add Http Method configuration. That will be used for sending data to target.#198ecararus wants to merge 4 commits intoAiven-Open:mainfrom
Conversation
… endpoint, Defaulted on POST Method. Supported POST/PUT
Fix linter reported issue
Fix Linter reported issue
Fix Linter reported issue
jeqo
left a comment
There was a problem hiding this comment.
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.
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.
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)); |
|
|
||
| } | ||
|
|
||
|
|
| // Check the messages have been sent once | ||
| messages.forEach( | ||
| message -> bodyPublishers.verify(() -> HttpRequest.BodyPublishers.ofString(eq(message)), times(1))); | ||
|
|
| .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.
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.
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]