Skip to content

Commit

Permalink
Merge pull request #26 from imrafaelmerino/v4.0.0
Browse files Browse the repository at this point in the history
V4.0.0
  • Loading branch information
imrafaelmerino committed Nov 21, 2023
2 parents 92fb363 + 221e986 commit 40f59f1
Show file tree
Hide file tree
Showing 95 changed files with 2,349 additions and 2,224 deletions.
733 changes: 436 additions & 297 deletions README.md

Large diffs are not rendered by default.

32 changes: 10 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.imrafaelmerino</groupId>
<artifactId>vertx-effect</artifactId>
<packaging>jar</packaging>
<version>3.0.1</version>
<version>4.0.0</version>
<name>vertx-effect</name>
<description>When actors meet Functional Programming</description>
<url>https://github.com/imrafaelmerino/vertx-effect</url>
Expand Down Expand Up @@ -37,12 +37,11 @@
<MAVEN-SOURCE-PLUGIN.VERSION>3.0.1</MAVEN-SOURCE-PLUGIN.VERSION>
<MAVEN-SUREFIRE-PLUGIN.VERSION>2.22.2</MAVEN-SUREFIRE-PLUGIN.VERSION>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<MAVEN-COMPILER-PLUGIN.SOURCE>11</MAVEN-COMPILER-PLUGIN.SOURCE>
<MAVEN-COMPILER-PLUGIN.TARGET>11</MAVEN-COMPILER-PLUGIN.TARGET>
<VERTX-VERSION>4.4.4</VERTX-VERSION>
<JSON-VALUES.VERSION>11.9.0</JSON-VALUES.VERSION>
<JAVA-FUN.VERSION>0.9.4</JAVA-FUN.VERSION>
<VERTX.JSON-VALUES.VERSION>0.7</VERTX.JSON-VALUES.VERSION>
<MAVEN-COMPILER-PLUGIN.SOURCE>17</MAVEN-COMPILER-PLUGIN.SOURCE>
<MAVEN-COMPILER-PLUGIN.TARGET>17</MAVEN-COMPILER-PLUGIN.TARGET>
<VERTX-VERSION>4.5.0</VERTX-VERSION>
<JAVA-FUN.VERSION>1.3.2</JAVA-FUN.VERSION>
<VERTX.JSON-VALUES.VERSION>1.0.0</VERTX.JSON-VALUES.VERSION>
<MAVEN-JAR-PLUGIN.VERSION>3.2.0</MAVEN-JAR-PLUGIN.VERSION>
<PROJECT.BUILD.SOURCE_ENCODING>UTF-8</PROJECT.BUILD.SOURCE_ENCODING>
<MAVEN-COMPILER-PLUGIN.VERSION>3.10.1</MAVEN-COMPILER-PLUGIN.VERSION>
Expand All @@ -55,22 +54,16 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${MAVEN-JAR-PLUGIN.VERSION}</version>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>vertx.effect</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
<source>${MAVEN-COMPILER-PLUGIN.SOURCE}</source>
<target>${MAVEN-COMPILER-PLUGIN.TARGET}</target>
<showWarnings>true</showWarnings>
<encoding>UTF-8</encoding>
<encoding>${project.build.sourceEncoding}</encoding>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
Expand All @@ -97,7 +90,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>${MAVEN-JAVADOC-PLUGIN.VERSION}</version>
<configuration>
<source>11</source>
<source>${MAVEN-COMPILER-PLUGIN.SOURCE}</source>
</configuration>
<executions>
<execution>
Expand All @@ -121,11 +114,6 @@
<version>${JAVA-FUN.VERSION}</version>
</dependency>

<dependency>
<groupId>com.github.imrafaelmerino</groupId>
<artifactId>json-values</artifactId>
<version>${JSON-VALUES.VERSION}</version>
</dependency>

<dependency>
<groupId>com.github.imrafaelmerino</groupId>
Expand Down
83 changes: 31 additions & 52 deletions src/main/java/vertx/effect/AbstractHttpClientModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.function.Consumer;

import java.util.stream.Collectors;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
Expand All @@ -30,6 +29,21 @@

public abstract class AbstractHttpClientModule extends VertxModule {

protected final HttpClientOptions httpOptions;
protected final String httpClientAddress;
protected Lambdac<JsObj, JsObj> httpClient;

public AbstractHttpClientModule(final HttpClientOptions options,
final String address
) {
if (requireNonNull(address).isBlank())
throw new IllegalArgumentException("address is empty");

this.httpClientAddress = address;
this.httpOptions = requireNonNull(options);

}

private static JsObj toJsObj(Buffer buffer, HttpClientResponse httpResp) {
return STATUS_CODE_LENS.set.apply(httpResp.statusCode())
.andThen(STATUS_MESSAGE_OPT.set.apply(httpResp.statusMessage()))
Expand Down Expand Up @@ -79,22 +93,6 @@ private static ReplyException getHttpReplyException(Throwable exc) {
}
}


protected final HttpClientOptions httpOptions;
protected final String httpClientAddress;
protected Lambdac<JsObj, JsObj> httpClient;

public AbstractHttpClientModule(final HttpClientOptions options,
final String address
) {
if (requireNonNull(address).isBlank())
throw new IllegalArgumentException("address is empty");

this.httpClientAddress = address;
this.httpOptions = requireNonNull(options);

}

private static JsArray cookies2JsArray(final List<String> cookies) {
if (cookies == null || cookies.isEmpty()) return JsArray.empty();
return JsArray.ofIterable(cookies.stream()
Expand All @@ -119,37 +117,20 @@ Consumer<Message<JsObj>> consumer(final HttpClient client) {
reqEvent.host = options.getHost();

switch (type) {
case 0:
execReq(client, message, reqEvent, options, GET);
break;
case 1:
execBodyReq(client, message, reqEvent, HttpReq.BYTES_BODY_LENS.get.apply(req), options, POST);
break;
case 2:
execBodyReq(client, message, reqEvent, HttpReq.BYTES_BODY_LENS.get.apply(req), options, PUT);
break;
case 3:
execReq(client, message, reqEvent, options, DELETE);
break;
case 4:
execReq(client, message, reqEvent, options, OPTIONS);
break;
case 5:
execReq(client, message, reqEvent, options, HEAD);
break;
case 6:
execReq(client, message, reqEvent, options, TRACE);
break;
case 7:
execBodyReq(client, message, reqEvent, HttpReq.BYTES_BODY_LENS.get.apply(req), options, PATCH);
break;

default:
message.reply(new ReplyException(RECIPIENT_FAILURE,
HTTP_METHOD_NOT_IMPLEMENTED_CODE,
"The method type " + type + " is not supported. Supported types are in enum HttpReqBuilder.TYPE."
)
);
case 0 -> execReq(client, message, reqEvent, options, GET);
case 1 -> execBodyReq(client, message, reqEvent, HttpReq.BYTES_BODY_LENS.get.apply(req), options, POST);
case 2 -> execBodyReq(client, message, reqEvent, HttpReq.BYTES_BODY_LENS.get.apply(req), options, PUT);
case 3 -> execReq(client, message, reqEvent, options, DELETE);
case 4 -> execReq(client, message, reqEvent, options, OPTIONS);
case 5 -> execReq(client, message, reqEvent, options, HEAD);
case 6 -> execReq(client, message, reqEvent, options, TRACE);
case 7 ->
execBodyReq(client, message, reqEvent, HttpReq.BYTES_BODY_LENS.get.apply(req), options, PATCH);
default -> message.reply(new ReplyException(RECIPIENT_FAILURE,
HTTP_METHOD_NOT_IMPLEMENTED_CODE,
"The method type " + type + " is not supported. Supported types are in enum HttpReqBuilder.TYPE."
)
);
}
};
}
Expand Down Expand Up @@ -271,9 +252,7 @@ protected final void initialize() {

@Override
protected final void deploy() {
this.deployConsumer(
httpClientAddress,
consumer(vertx.createHttpClient(httpOptions))
);
this.deployConsumer(httpClientAddress,
consumer(vertx.createHttpClient(httpOptions)));
}
}

0 comments on commit 40f59f1

Please sign in to comment.