Skip to content

Commit bdf49b5

Browse files
authored
Merge pull request #6 from clean-arch-enablers-project/feature/returning-the-http-response-untouched
Feature/returning the http response untouched
2 parents 514fbc4 + 63bf20c commit bdf49b5

File tree

5 files changed

+94
-55
lines changed

5 files changed

+94
-55
lines changed

pom.xml

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<url>https://github.com/clean-arch-enablers-project/cae-utils-http-client/blob/main/README.md</url>
99
<groupId>com.clean-arch-enablers</groupId>
1010
<artifactId>http-client</artifactId>
11-
<version>0.0.2</version>
11+
<version>1.1.1</version>
1212
<packaging>jar</packaging>
1313
<licenses>
1414
<license>
@@ -44,6 +44,11 @@
4444
<artifactId>jackson-databind</artifactId>
4545
<version>2.16.1</version>
4646
</dependency>
47+
<dependency>
48+
<groupId>com.fasterxml.jackson.core</groupId>
49+
<artifactId>jackson-core</artifactId>
50+
<version>2.16.1</version>
51+
</dependency>
4752
<dependency>
4853
<groupId>org.junit.jupiter</groupId>
4954
<artifactId>junit-jupiter-engine</artifactId>
@@ -63,58 +68,65 @@
6368
<scope>test</scope>
6469
</dependency>
6570
</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>deploy</phase>
112-
<goals>
113-
<goal>sign</goal>
114-
</goals>
115-
</execution>
116-
</executions>
117-
</plugin>
118-
</plugins>
119-
</build>
71+
72+
<profiles>
73+
<profile>
74+
<id>deployment</id>
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.sonatype.central</groupId>
79+
<artifactId>central-publishing-maven-plugin</artifactId>
80+
<version>0.4.0</version>
81+
<extensions>true</extensions>
82+
<configuration>
83+
<publishingServerId>central</publishingServerId>
84+
<tokenAuth>true</tokenAuth>
85+
</configuration>
86+
</plugin>
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-javadoc-plugin</artifactId>
90+
<version>3.3.0</version>
91+
<executions>
92+
<execution>
93+
<id>attach-javadocs</id>
94+
<goals>
95+
<goal>jar</goal>
96+
</goals>
97+
</execution>
98+
</executions>
99+
</plugin>
100+
<plugin>
101+
<groupId>org.apache.maven.plugins</groupId>
102+
<artifactId>maven-source-plugin</artifactId>
103+
<version>3.2.1</version>
104+
<executions>
105+
<execution>
106+
<id>attach-sources</id>
107+
<goals>
108+
<goal>jar</goal>
109+
</goals>
110+
</execution>
111+
</executions>
112+
</plugin>
113+
<plugin>
114+
<groupId>org.apache.maven.plugins</groupId>
115+
<artifactId>maven-gpg-plugin</artifactId>
116+
<version>1.6</version>
117+
<executions>
118+
<execution>
119+
<id>sign-artifacts</id>
120+
<phase>verify</phase>
121+
<goals>
122+
<goal>sign</goal>
123+
</goals>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
</plugins>
128+
</build>
129+
</profile>
130+
</profiles>
131+
120132
</project>

src/main/java/com/cae/http_client/HttpRequestModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
public interface HttpRequestModel {
66

7+
HttpResponse sendRequest();
8+
79
<T> T sendRequestReturning(Class<T> typeOfExpectedResponseBody);
810

911
<T> T sendRequestReturning(TypeReference<T> typeReference);

src/main/java/com/cae/http_client/HttpResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.core.type.TypeReference;
44

5+
import java.util.List;
6+
import java.util.Map;
57
import java.util.function.Consumer;
68

79
public interface HttpResponse{
@@ -45,4 +47,9 @@ public interface HttpResponse{
4547
* @param checkOnResponse the action to be executed in case of needing handling
4648
*/
4749
void ifNeedsHandling(Consumer<HttpResponse> checkOnResponse);
50+
51+
/**
52+
* @return the response headers
53+
*/
54+
Map<String, List<String>> getHeaders();
4855
}

src/main/java/com/cae/http_client/implementations/HttpRequestModelImplementation.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cae.http_client.implementations;
22

33
import com.cae.http_client.HttpRequestMethod;
4+
import com.cae.http_client.HttpResponse;
45
import com.fasterxml.jackson.core.type.TypeReference;
56
import lombok.AccessLevel;
67
import lombok.NoArgsConstructor;
@@ -25,6 +26,11 @@ public static AbstractHttpRequestModel of(String uri, HttpRequestMethod method,
2526
return httpRequest;
2627
}
2728

29+
@Override
30+
public HttpResponse sendRequest() {
31+
return HttpRequestExecutionManager.of(this).run();
32+
}
33+
2834
@Override
2935
public <T> T sendRequestReturning(Class<T> typeOfExpectedResponseBody) {
3036
return HttpRequestExecutionManager.of(this).run().getBodyAs(typeOfExpectedResponseBody);

src/main/java/com/cae/http_client/implementations/HttpResponseImplementation.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import com.fasterxml.jackson.core.JsonProcessingException;
77
import com.fasterxml.jackson.core.type.TypeReference;
88

9+
import java.net.http.HttpHeaders;
10+
import java.util.HashMap;
11+
import java.util.List;
12+
import java.util.Map;
13+
import java.util.Optional;
914
import java.util.function.Consumer;
1015

1116
public class HttpResponseImplementation extends AbstractHttpResponse{
@@ -53,6 +58,13 @@ public void ifNeedsHandling(Consumer<HttpResponse> checkOnResponse) {
5358
checkOnResponse.accept(this);
5459
}
5560

61+
@Override
62+
public Map<String, List<String>> getHeaders() {
63+
return Optional.ofNullable(this.unwrappedHttpResponse.headers())
64+
.map(HttpHeaders::map)
65+
.orElse(new HashMap<>());
66+
}
67+
5668
private boolean isNot2xx() {
5769
var statusString = this.getStatusCode().toString();
5870
return (statusString.charAt(0) != '2');

0 commit comments

Comments
 (0)