-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from clean-arch-enablers-project/migrating-code
Migrating code
- Loading branch information
Showing
57 changed files
with
1,971 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
settings.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<name>CAE HTTP Client</name> | ||
<description>Meant for enabling applications to use HTTP at ease, without having to compromise the clean state of the overall architecture.</description> | ||
<url>https://github.com/clean-arch-enablers-project/cae-utils-http-client/blob/main/README.md</url> | ||
<groupId>com.clean-arch-enablers</groupId> | ||
<artifactId>http-client</artifactId> | ||
<version>0.0.1</version> | ||
<packaging>jar</packaging> | ||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
</license> | ||
</licenses> | ||
<scm> | ||
<url>https://github.com/clean-arch-enablers-project/cae-utils-http-client</url> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<name>Zé Lúcio Jr.</name> | ||
<email>joselucioalmeidajunior@gmail.com</email> | ||
<url>https://github.com/zeluciojr</url> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.24</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.16.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.9.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>4.8.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-junit-jupiter</artifactId> | ||
<version>4.8.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.sonatype.central</groupId> | ||
<artifactId>central-publishing-maven-plugin</artifactId> | ||
<version>0.4.0</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<publishingServerId>central</publishingServerId> | ||
<tokenAuth>true</tokenAuth> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>3.2.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<version>1.6</version> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/clean_arch_enablers/http_client/ExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
@FunctionalInterface | ||
public interface ExceptionHandler { | ||
|
||
/** | ||
* Method which will be called when handling an exception | ||
* @param exception the exception to handle | ||
*/ | ||
void handle(Exception exception); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...java/com/clean_arch_enablers/http_client/HttpExceptionHandlersByExceptionTypeFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
import com.clean_arch_enablers.http_client.commons.HandlersFactory; | ||
|
||
import java.util.Map; | ||
|
||
public interface HttpExceptionHandlersByExceptionTypeFactory extends HandlersFactory<Map<Class<? extends Exception>, ExceptionHandler>> { } | ||
|
||
|
||
|
12 changes: 12 additions & 0 deletions
12
src/main/java/com/clean_arch_enablers/http_client/HttpRequestBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
public interface HttpRequestBuilder extends HttpRequestBuilderForHandlers, HttpRequestBuilderForRetrying{ | ||
|
||
HttpRequestBuilder headerOf(String key, String value); | ||
HttpRequestBuilder headersFactory(HttpRequestHeaderFactory httpRequestHeaderFactory); | ||
HttpRequestBuilder pathVariableOf(String pathVariablePlaceholder, String pathVariableValue); | ||
HttpRequestBuilder queryParameterOf(String queryParameterName, String queryParameterValue); | ||
HttpRequestBuilder proxyAddress(String host, Integer port); | ||
HttpRequestModel finishBuildingModel(); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/clean_arch_enablers/http_client/HttpRequestBuilderForHandlers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
/** | ||
* Builder component for attaching handlers to the request model. | ||
*/ | ||
public interface HttpRequestBuilderForHandlers { | ||
|
||
|
||
/** | ||
* Attaches a handler by the number which represents the HTTP status code | ||
* @param statusCode the number of the HTTP status code: 404, 400, 503... | ||
* @param httpResponseHandler an arrow function which implements the Functional Interface of HttpResponseHandler | ||
* @return the builder instance for further attachments | ||
*/ | ||
HttpRequestBuilder handlerByHttpStatusCode(Integer statusCode, HttpResponseHandler httpResponseHandler); | ||
|
||
/** | ||
* Attaches a group of handlers by the numbers which represent HTTP statuses code from within the factory | ||
* @param httpResponseHandlersByStatusCodeFactory the factory from which the handlers will be made | ||
* @return the builder instance for further attachments | ||
*/ | ||
HttpRequestBuilder handlersByHttpStatusCodeFactory(HttpResponseHandlersByStatusCodeFactory httpResponseHandlersByStatusCodeFactory); | ||
|
||
/** | ||
* Attaches a handler for any unsuccessful HTTP response | ||
* @param httpResponseHandler an arrow function which implements the Functional Interface of HttpResponseHandler | ||
* @return the builder instance for further attachments | ||
*/ | ||
HttpRequestBuilder handlerForAnyUnsuccessfulResponse(HttpResponseHandler httpResponseHandler); | ||
|
||
/** | ||
* Attaches a group of handlers by types of exceptions from within the factory | ||
* @param httpExceptionHandlersByExceptionTypeFactory the factory from which the handlers will be made | ||
* @return the builder instance for further attachments | ||
*/ | ||
HttpRequestBuilder handlersByExceptionTypeFactory(HttpExceptionHandlersByExceptionTypeFactory httpExceptionHandlersByExceptionTypeFactory); | ||
|
||
/** | ||
* Attaches a handler by type of exception | ||
* @param exceptionType the type of the exception which will trigger the execution of the following handler | ||
* @param exceptionHandler an arrow function which implements the Functional Interface of ExceptionHandler | ||
* @return the builder instance for further attachments | ||
*/ | ||
HttpRequestBuilder handlerByExceptionType(Class<? extends Exception> exceptionType, ExceptionHandler exceptionHandler); | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/clean_arch_enablers/http_client/HttpRequestBuilderForRetrying.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
import com.clean_arch_enablers.http_client.commons.RetriersByExceptionTypeFactory; | ||
|
||
public interface HttpRequestBuilderForRetrying { | ||
|
||
HttpRequestBuilder retrierByHttpStatusCode(Integer statusCode, RetrierModel retrierModel); | ||
HttpRequestBuilder retriersByHttpStatusCodeFactory(RetriersByStatusCodeFactory retriersByStatusCodeFactory); | ||
HttpRequestBuilder retriersByExceptionTypeFactory(RetriersByExceptionTypeFactory retriersByExceptionTypeFactory); | ||
HttpRequestBuilder retrierByExceptionType(Class<? extends Exception> exceptionType, RetrierModel retrierModel); | ||
|
||
} | ||
|
||
|
||
|
||
|
16 changes: 16 additions & 0 deletions
16
src/main/java/com/clean_arch_enablers/http_client/HttpRequestHeaderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Factory for HTTP Request Headers | ||
*/ | ||
public interface HttpRequestHeaderFactory { | ||
|
||
/** | ||
* This method will be called under the hood when an instance of this type is passed during the building process of a HttpRequestModel instance. | ||
* @return a map in which the keys are the HTTP Headers and the values are their respective HTTP Header Values | ||
*/ | ||
Map<String, String> makeHeaders(); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/clean_arch_enablers/http_client/HttpRequestMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
|
||
import com.clean_arch_enablers.http_client.implementations.AbstractHttpRequestModel; | ||
import com.clean_arch_enablers.http_client.implementations.exceptions.RetryNeededOnExceptionThrownException; | ||
|
||
public interface HttpRequestMethod { | ||
|
||
HttpResponse execute(AbstractHttpRequestModel httpRequestModel) throws RetryNeededOnExceptionThrownException; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/clean_arch_enablers/http_client/HttpRequestModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
|
||
public interface HttpRequestModel { | ||
|
||
<T> T sendRequestReturning(Class<T> typeOfExpectedResponseBody); | ||
|
||
<T> T sendRequestReturning(TypeReference<T> typeReference); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/clean_arch_enablers/http_client/HttpRequestStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
import java.net.http.HttpRequest; | ||
|
||
public interface HttpRequestStarter { | ||
|
||
HttpRequestBuilder startGetRequestFor(String url); | ||
HttpRequestBuilder startPostRequestFor(String url, HttpRequest.BodyPublisher body); | ||
HttpRequestBuilder startPutRequestFor(String url, HttpRequest.BodyPublisher body); | ||
HttpRequestBuilder startDeleteRequestFor(String url); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/clean_arch_enablers/http_client/HttpResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public interface HttpResponse{ | ||
|
||
/** | ||
* Retrieve the status code of the response | ||
* @return a number of some HTTP Status Code: 200, 204, 400, 403... | ||
*/ | ||
Integer getStatusCode(); | ||
|
||
/** | ||
* Gets the request responsible for generating this response | ||
* @return the HTTP request model object | ||
*/ | ||
HttpRequestModel getHttpRequest(); | ||
|
||
/** | ||
* Gets the response body as the parameterized type | ||
* @param bodyType the desired type for the body | ||
* @return the instance of the desired type | ||
* @param <T> the known type to map the body to | ||
*/ | ||
<T> T getBodyAs(Class<T> bodyType); | ||
|
||
/** | ||
* Gets the response body as the parameterized type | ||
* @param typeOfExpectedResponseBody the desired type for the body | ||
* @return the instance of the desired type | ||
* @param <T> the known type to map the body to | ||
*/ | ||
<T> T getBodyAs(TypeReference<T> typeOfExpectedResponseBody); | ||
|
||
/** | ||
* | ||
* @return whether the response needs handling | ||
*/ | ||
boolean needsHandling(); | ||
|
||
/** | ||
* If the instance needs handling it will execute the Consumer received as parameter | ||
* @param checkOnResponse the action to be executed in case of needing handling | ||
*/ | ||
void ifNeedsHandling(Consumer<HttpResponse> checkOnResponse); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/clean_arch_enablers/http_client/HttpResponseHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
@FunctionalInterface | ||
public interface HttpResponseHandler { | ||
|
||
/** | ||
* Method called when handling an HTTP Response | ||
* @param httpResponse the HTTP response to be handled | ||
*/ | ||
void handle(HttpResponse httpResponse); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...ain/java/com/clean_arch_enablers/http_client/HttpResponseHandlersByStatusCodeFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.clean_arch_enablers.http_client; | ||
|
||
import com.clean_arch_enablers.http_client.commons.HandlersFactory; | ||
|
||
import java.util.Map; | ||
|
||
public interface HttpResponseHandlersByStatusCodeFactory extends HandlersFactory<Map<Integer, HttpResponseHandler>> { } |
Oops, something went wrong.