Skip to content

Commit

Permalink
http response untouched
Browse files Browse the repository at this point in the history
  • Loading branch information
zeluciojr committed Dec 6, 2024
1 parent 514fbc4 commit 7600658
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 55 deletions.
117 changes: 62 additions & 55 deletions 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>http-client</artifactId>
<version>0.0.2</version>
<version>1.1.0</version>
<packaging>jar</packaging>
<licenses>
<license>
Expand Down Expand Up @@ -63,58 +63,65 @@
<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>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>deployment</id>
<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>
</profile>
</profiles>

</project>
2 changes: 2 additions & 0 deletions src/main/java/com/cae/http_client/HttpRequestModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public interface HttpRequestModel {

HttpResponse sendRequest();

<T> T sendRequestReturning(Class<T> typeOfExpectedResponseBody);

<T> T sendRequestReturning(TypeReference<T> typeReference);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/cae/http_client/HttpResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public interface HttpResponse{
Expand Down Expand Up @@ -45,4 +47,9 @@ public interface HttpResponse{
* @param checkOnResponse the action to be executed in case of needing handling
*/
void ifNeedsHandling(Consumer<HttpResponse> checkOnResponse);

/**
* @return the response headers
*/
Map<String, List<String>> getHeaders();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cae.http_client.implementations;

import com.cae.http_client.HttpRequestMethod;
import com.cae.http_client.HttpResponse;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand All @@ -25,6 +26,11 @@ public static AbstractHttpRequestModel of(String uri, HttpRequestMethod method,
return httpRequest;
}

@Override
public HttpResponse sendRequest() {
return HttpRequestExecutionManager.of(this).run();
}

@Override
public <T> T sendRequestReturning(Class<T> typeOfExpectedResponseBody) {
return HttpRequestExecutionManager.of(this).run().getBodyAs(typeOfExpectedResponseBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;

import java.net.http.HttpHeaders;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;

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

@Override
public Map<String, List<String>> getHeaders() {
return Optional.ofNullable(this.unwrappedHttpResponse.headers())
.map(HttpHeaders::map)
.orElse(new HashMap<>());
}

private boolean isNot2xx() {
var statusString = this.getStatusCode().toString();
return (statusString.charAt(0) != '2');
Expand Down

0 comments on commit 7600658

Please sign in to comment.