Skip to content

Commit b202e06

Browse files
authored
Merge pull request #1 from clean-arch-enablers-project/migrating-code
Migrating code
2 parents cc5a5ea + 8bc3fe4 commit b202e06

File tree

57 files changed

+1971
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1971
-1
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
34+
35+
settings.xml

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Apache License
23
Version 2.0, January 2004
34
http://www.apache.org/licenses/
@@ -198,4 +199,4 @@
198199
distributed under the License is distributed on an "AS IS" BASIS,
199200
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200201
See the License for the specific language governing permissions and
201-
limitations under the License.
202+
limitations under the License.

pom.xml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<name>CAE HTTP Client</name>
7+
<description>Meant for enabling applications to use HTTP at ease, without having to compromise the clean state of the overall architecture.</description>
8+
<url>https://github.com/clean-arch-enablers-project/cae-utils-http-client/blob/main/README.md</url>
9+
<groupId>com.clean-arch-enablers</groupId>
10+
<artifactId>http-client</artifactId>
11+
<version>0.0.1</version>
12+
<packaging>jar</packaging>
13+
<licenses>
14+
<license>
15+
<name>Apache License, Version 2.0</name>
16+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
17+
</license>
18+
</licenses>
19+
<scm>
20+
<url>https://github.com/clean-arch-enablers-project/cae-utils-http-client</url>
21+
</scm>
22+
<developers>
23+
<developer>
24+
<name>Zé Lúcio Jr.</name>
25+
<email>joselucioalmeidajunior@gmail.com</email>
26+
<url>https://github.com/zeluciojr</url>
27+
</developer>
28+
</developers>
29+
30+
<properties>
31+
<maven.compiler.source>11</maven.compiler.source>
32+
<maven.compiler.target>11</maven.compiler.target>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
</properties>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.projectlombok</groupId>
39+
<artifactId>lombok</artifactId>
40+
<version>1.18.24</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.fasterxml.jackson.core</groupId>
44+
<artifactId>jackson-databind</artifactId>
45+
<version>2.16.1</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter-engine</artifactId>
50+
<version>5.9.0</version>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.mockito</groupId>
55+
<artifactId>mockito-core</artifactId>
56+
<version>4.8.0</version>
57+
<scope>test</scope>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.mockito</groupId>
61+
<artifactId>mockito-junit-jupiter</artifactId>
62+
<version>4.8.0</version>
63+
<scope>test</scope>
64+
</dependency>
65+
</dependencies>
66+
<build>
67+
<plugins>
68+
<plugin>
69+
<groupId>org.sonatype.central</groupId>
70+
<artifactId>central-publishing-maven-plugin</artifactId>
71+
<version>0.4.0</version>
72+
<extensions>true</extensions>
73+
<configuration>
74+
<publishingServerId>central</publishingServerId>
75+
<tokenAuth>true</tokenAuth>
76+
</configuration>
77+
</plugin>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-javadoc-plugin</artifactId>
81+
<version>3.3.0</version>
82+
<executions>
83+
<execution>
84+
<id>attach-javadocs</id>
85+
<goals>
86+
<goal>jar</goal>
87+
</goals>
88+
</execution>
89+
</executions>
90+
</plugin>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-source-plugin</artifactId>
94+
<version>3.2.1</version>
95+
<executions>
96+
<execution>
97+
<id>attach-sources</id>
98+
<goals>
99+
<goal>jar</goal>
100+
</goals>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
<plugin>
105+
<groupId>org.apache.maven.plugins</groupId>
106+
<artifactId>maven-gpg-plugin</artifactId>
107+
<version>1.6</version>
108+
<executions>
109+
<execution>
110+
<id>sign-artifacts</id>
111+
<phase>verify</phase>
112+
<goals>
113+
<goal>sign</goal>
114+
</goals>
115+
</execution>
116+
</executions>
117+
</plugin>
118+
</plugins>
119+
</build>
120+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.clean_arch_enablers.http_client;
2+
3+
@FunctionalInterface
4+
public interface ExceptionHandler {
5+
6+
/**
7+
* Method which will be called when handling an exception
8+
* @param exception the exception to handle
9+
*/
10+
void handle(Exception exception);
11+
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.clean_arch_enablers.http_client;
2+
3+
import com.clean_arch_enablers.http_client.commons.HandlersFactory;
4+
5+
import java.util.Map;
6+
7+
public interface HttpExceptionHandlersByExceptionTypeFactory extends HandlersFactory<Map<Class<? extends Exception>, ExceptionHandler>> { }
8+
9+
10+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.clean_arch_enablers.http_client;
2+
3+
public interface HttpRequestBuilder extends HttpRequestBuilderForHandlers, HttpRequestBuilderForRetrying{
4+
5+
HttpRequestBuilder headerOf(String key, String value);
6+
HttpRequestBuilder headersFactory(HttpRequestHeaderFactory httpRequestHeaderFactory);
7+
HttpRequestBuilder pathVariableOf(String pathVariablePlaceholder, String pathVariableValue);
8+
HttpRequestBuilder queryParameterOf(String queryParameterName, String queryParameterValue);
9+
HttpRequestBuilder proxyAddress(String host, Integer port);
10+
HttpRequestModel finishBuildingModel();
11+
12+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.clean_arch_enablers.http_client;
2+
3+
/**
4+
* Builder component for attaching handlers to the request model.
5+
*/
6+
public interface HttpRequestBuilderForHandlers {
7+
8+
9+
/**
10+
* Attaches a handler by the number which represents the HTTP status code
11+
* @param statusCode the number of the HTTP status code: 404, 400, 503...
12+
* @param httpResponseHandler an arrow function which implements the Functional Interface of HttpResponseHandler
13+
* @return the builder instance for further attachments
14+
*/
15+
HttpRequestBuilder handlerByHttpStatusCode(Integer statusCode, HttpResponseHandler httpResponseHandler);
16+
17+
/**
18+
* Attaches a group of handlers by the numbers which represent HTTP statuses code from within the factory
19+
* @param httpResponseHandlersByStatusCodeFactory the factory from which the handlers will be made
20+
* @return the builder instance for further attachments
21+
*/
22+
HttpRequestBuilder handlersByHttpStatusCodeFactory(HttpResponseHandlersByStatusCodeFactory httpResponseHandlersByStatusCodeFactory);
23+
24+
/**
25+
* Attaches a handler for any unsuccessful HTTP response
26+
* @param httpResponseHandler an arrow function which implements the Functional Interface of HttpResponseHandler
27+
* @return the builder instance for further attachments
28+
*/
29+
HttpRequestBuilder handlerForAnyUnsuccessfulResponse(HttpResponseHandler httpResponseHandler);
30+
31+
/**
32+
* Attaches a group of handlers by types of exceptions from within the factory
33+
* @param httpExceptionHandlersByExceptionTypeFactory the factory from which the handlers will be made
34+
* @return the builder instance for further attachments
35+
*/
36+
HttpRequestBuilder handlersByExceptionTypeFactory(HttpExceptionHandlersByExceptionTypeFactory httpExceptionHandlersByExceptionTypeFactory);
37+
38+
/**
39+
* Attaches a handler by type of exception
40+
* @param exceptionType the type of the exception which will trigger the execution of the following handler
41+
* @param exceptionHandler an arrow function which implements the Functional Interface of ExceptionHandler
42+
* @return the builder instance for further attachments
43+
*/
44+
HttpRequestBuilder handlerByExceptionType(Class<? extends Exception> exceptionType, ExceptionHandler exceptionHandler);
45+
46+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.clean_arch_enablers.http_client;
2+
3+
import com.clean_arch_enablers.http_client.commons.RetriersByExceptionTypeFactory;
4+
5+
public interface HttpRequestBuilderForRetrying {
6+
7+
HttpRequestBuilder retrierByHttpStatusCode(Integer statusCode, RetrierModel retrierModel);
8+
HttpRequestBuilder retriersByHttpStatusCodeFactory(RetriersByStatusCodeFactory retriersByStatusCodeFactory);
9+
HttpRequestBuilder retriersByExceptionTypeFactory(RetriersByExceptionTypeFactory retriersByExceptionTypeFactory);
10+
HttpRequestBuilder retrierByExceptionType(Class<? extends Exception> exceptionType, RetrierModel retrierModel);
11+
12+
}
13+
14+
15+
16+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.clean_arch_enablers.http_client;
2+
3+
import java.util.Map;
4+
5+
/**
6+
* Factory for HTTP Request Headers
7+
*/
8+
public interface HttpRequestHeaderFactory {
9+
10+
/**
11+
* This method will be called under the hood when an instance of this type is passed during the building process of a HttpRequestModel instance.
12+
* @return a map in which the keys are the HTTP Headers and the values are their respective HTTP Header Values
13+
*/
14+
Map<String, String> makeHeaders();
15+
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.clean_arch_enablers.http_client;
2+
3+
4+
import com.clean_arch_enablers.http_client.implementations.AbstractHttpRequestModel;
5+
import com.clean_arch_enablers.http_client.implementations.exceptions.RetryNeededOnExceptionThrownException;
6+
7+
public interface HttpRequestMethod {
8+
9+
HttpResponse execute(AbstractHttpRequestModel httpRequestModel) throws RetryNeededOnExceptionThrownException;
10+
11+
}

0 commit comments

Comments
 (0)