Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<url>https://github.com/clean-arch-enablers-project/cae-utils-http-client/blob/main/README.md</url>
<groupId>com.clean-arch-enablers</groupId>
<artifactId>cae-http-client</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>
<licenses>
<license>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/cae/http_client/HttpRequestStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface HttpRequestStarter {
HttpRequestBuilder startGetRequestFor(String url);
HttpRequestBuilder startPostRequestFor(String url, HttpRequest.BodyPublisher body);
HttpRequestBuilder startPutRequestFor(String url, HttpRequest.BodyPublisher body);
HttpRequestBuilder startPatchRequestFor(String url, HttpRequest.BodyPublisher body);
HttpRequestBuilder startDeleteRequestFor(String url);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public static HttpRequest makeFinalRequestForPutMethodFrom(AbstractHttpRequestMo
return finallyBuildIt(finalHttpRequestBuilder, httpRequestModel);
}

public static HttpRequest makeFinalRequestForPatchMethodFrom(AbstractHttpRequestModel httpRequestModel) {
var finalHttpRequestBuilder = HttpRequest.newBuilder().method("PATCH", httpRequestModel.body);
return finallyBuildIt(finalHttpRequestBuilder, httpRequestModel);
}

public static HttpRequest makeFinalRequestForDeleteMethodFrom(AbstractHttpRequestModel httpRequestModel) {
var finalHttpRequestBuilder = HttpRequest.newBuilder().DELETE();
return finallyBuildIt(finalHttpRequestBuilder, httpRequestModel);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.cae.http_client.implementations;

import com.cae.http_client.HttpRequestMethod;
import com.cae.http_client.HttpResponse;
import com.cae.http_client.implementations.exceptions.RetryNeededOnExceptionThrownException;

public class HttpRequestPatchMethod implements HttpRequestMethod {
@Override
public HttpResponse execute(AbstractHttpRequestModel httpRequestModel) throws RetryNeededOnExceptionThrownException {
var finalRequest = FinalHttpRequestFactory.makeFinalRequestForPatchMethodFrom(httpRequestModel);
try {
var unwrappedResponse = FinalHttpRequestExecutor.of(httpRequestModel).execute(finalRequest);
return new HttpResponseImplementation(httpRequestModel, unwrappedResponse);
}
catch (Exception exception) {
ExceptionThrownByHttpRequestChecker.of(httpRequestModel).checkOn(exception);
throw exception;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public HttpRequestBuilder startPutRequestFor(String url, HttpRequest.BodyPublish
return HttpRequestBuilderImplementation.of(HttpRequestModelImplementation.of(url, new HttpRequestPutMethod(), body));
}

@Override
public HttpRequestBuilder startPatchRequestFor(String url, HttpRequest.BodyPublisher body) {
return HttpRequestBuilderImplementation.of(HttpRequestModelImplementation.of(url, new HttpRequestPatchMethod(), body));
}

@Override
public HttpRequestBuilder startDeleteRequestFor(String url) {
return HttpRequestBuilderImplementation.of(HttpRequestModelImplementation.of(url, new HttpRequestDeleteMethod()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ void shouldReturnNonNullInstanceOfBuilderWhenStartingForPutMethod(){
Assertions.assertNotNull(this.httpRequestStarter.startPutRequestFor("http://localhost:2222", HttpRequest.BodyPublishers.ofString("{someRandomJsonField: \"someRandomValue\"}")));
}

@Test
@DisplayName("Should return non null instance of builder when starting for patch method")
void shouldReturnNonNullInstanceOfBuilderWhenStartingForPatchMethod(){
Assertions.assertNotNull(this.httpRequestStarter.startPatchRequestFor("http://localhost:2222", HttpRequest.BodyPublishers.ofString("{someRandomJsonField: \"someRandomValue\"}")));
}


}