Skip to content

Commit e93388f

Browse files
Rene SprietsmaRene Sprietsma
authored andcommitted
removed dep
1 parent 8d78a35 commit e93388f

File tree

22 files changed

+130
-116
lines changed

22 files changed

+130
-116
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Inspired by ['Build You Own Web Framework In Go'](https://www.nicolasmerouze.com
1212

1313
```java
1414

15-
BiHandlers<HttpServerRequest, Void> handlers = compose(
15+
ServerRequestHandlers<Void> chain = build(
1616
new ExceptionHandler<>(),
1717
new ResponseTimeHandler<>(),
1818
new TimeoutHandler<>(vertx),
@@ -21,7 +21,7 @@ Inspired by ['Build You Own Web Framework In Go'](https://www.nicolasmerouze.com
2121
n.accept(req, arg);
2222
});
2323

24-
BiConsumer<HttpServerRequest, Void> handler = handlers.apply(
24+
BiConsumer<HttpServerRequest, Void> handler = chain.apply(
2525
(e, a) -> logger.error(a),
2626
(e, a) -> logger.info(a));
2727

pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
<dependency>
2121
<groupId>io.vertx</groupId>
2222
<artifactId>vertx-core</artifactId>
23-
<version>3.2.0</version>
24-
</dependency>
25-
26-
<dependency>
27-
<groupId>com.github.spriet2000</groupId>
28-
<artifactId>handlers</artifactId>
29-
<version>0.1.0-SNAPSHOT</version>
23+
<version>3.4.0-SNAPSHOT</version>
3024
</dependency>
3125

3226
<dependency>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.github.spriet2000.vertx.handlers.core.http;
2+
3+
import io.vertx.core.http.HttpServerRequest;
4+
5+
import java.util.ArrayList;
6+
import java.util.Collections;
7+
import java.util.List;
8+
import java.util.function.BiConsumer;
9+
import java.util.function.BiFunction;
10+
import java.util.stream.Collectors;
11+
12+
public class ServerRequestHandlers<A> {
13+
14+
private List<BiFunction<BiConsumer<HttpServerRequest, Throwable>, BiConsumer<HttpServerRequest, A>, BiConsumer<HttpServerRequest, A>>> handlers = new ArrayList<>();
15+
16+
public ServerRequestHandlers() {
17+
}
18+
19+
@SafeVarargs
20+
public ServerRequestHandlers(BiFunction<BiConsumer<HttpServerRequest, Throwable>, BiConsumer<HttpServerRequest, A>, BiConsumer<HttpServerRequest, A>>... handlers) {
21+
Collections.addAll(this.handlers, handlers);
22+
}
23+
24+
@SafeVarargs
25+
public ServerRequestHandlers(ServerRequestHandlers<A>... handlers) {
26+
for (ServerRequestHandlers<A> handler : handlers) {
27+
this.handlers.addAll(handler.handlers.stream().collect(Collectors.toList()));
28+
}
29+
}
30+
31+
@SafeVarargs
32+
public static <A> ServerRequestHandlers<A> build(ServerRequestHandlers<A>... handlers) {
33+
return new ServerRequestHandlers<>(handlers);
34+
}
35+
36+
@SafeVarargs
37+
public static <A> ServerRequestHandlers<A> build(BiFunction<BiConsumer<HttpServerRequest, Throwable>, BiConsumer<HttpServerRequest, A>, BiConsumer<HttpServerRequest, A>>... handlers) {
38+
return new ServerRequestHandlers<>(handlers);
39+
}
40+
41+
public BiConsumer<HttpServerRequest, A> apply(BiConsumer<HttpServerRequest, Throwable> exceptionHandler, BiConsumer<HttpServerRequest, A> successHandler) {
42+
BiConsumer<HttpServerRequest, A> last = successHandler;
43+
for (int i = handlers.size() - 1; i >= 0; i--) {
44+
final BiConsumer<HttpServerRequest, A> previous = last;
45+
last = handlers.get(i).apply(
46+
exceptionHandler,
47+
previous);
48+
}
49+
return last;
50+
}
51+
52+
@SafeVarargs
53+
public final ServerRequestHandlers<A> andThen(BiConsumer<HttpServerRequest, A>... consumers) {
54+
for (BiConsumer<HttpServerRequest, A> consumer : consumers) {
55+
handlers.add((f, n) -> consumer);
56+
}
57+
return this;
58+
}
59+
60+
@SafeVarargs
61+
public final ServerRequestHandlers<A> andThen(BiFunction<BiConsumer<HttpServerRequest, Throwable>, BiConsumer<HttpServerRequest, A>, BiConsumer<HttpServerRequest, A>>... handlers) {
62+
Collections.addAll(this.handlers, handlers);
63+
return this;
64+
}
65+
66+
@SafeVarargs
67+
public final ServerRequestHandlers<A> andThen(ServerRequestHandlers<A>... handlers) {
68+
for (ServerRequestHandlers<A> handler : handlers) {
69+
this.handlers.addAll(handler.handlers.stream().collect(Collectors.toList()));
70+
}
71+
return this;
72+
}
73+
}

src/main/java/com/github/spriet2000/vertx/handlers/http/server/ext/impl/EndHandler.java renamed to src/main/java/com/github/spriet2000/vertx/handlers/extensions/basic/impl/EndHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.spriet2000.vertx.handlers.http.server.ext.impl;
1+
package com.github.spriet2000.vertx.handlers.extensions.basic.impl;
22

33
import io.vertx.core.http.HttpServerRequest;
44

src/main/java/com/github/spriet2000/vertx/handlers/http/server/ext/impl/ExceptionHandler.java renamed to src/main/java/com/github/spriet2000/vertx/handlers/extensions/basic/impl/ExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.spriet2000.vertx.handlers.http.server.ext.impl;
1+
package com.github.spriet2000.vertx.handlers.extensions.basic.impl;
22

33
import io.vertx.core.http.HttpServerRequest;
44

src/main/java/com/github/spriet2000/vertx/handlers/http/server/ext/impl/LogHandler.java renamed to src/main/java/com/github/spriet2000/vertx/handlers/extensions/basic/impl/LogHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.spriet2000.vertx.handlers.http.server.ext.impl;
1+
package com.github.spriet2000.vertx.handlers.extensions.basic.impl;
22

33
import io.vertx.core.http.HttpServerRequest;
44
import io.vertx.core.logging.Logger;

src/main/java/com/github/spriet2000/vertx/handlers/http/server/ext/impl/ResponseTimeHandler.java renamed to src/main/java/com/github/spriet2000/vertx/handlers/extensions/basic/impl/ResponseTimeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.spriet2000.vertx.handlers.http.server.ext.impl;
1+
package com.github.spriet2000.vertx.handlers.extensions.basic.impl;
22

33
import io.vertx.core.http.HttpServerRequest;
44

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.github.spriet2000.vertx.handlers.extensions.bodyParser;
2+
3+
4+
public interface Body<T> {
5+
void body(T body);
6+
7+
T body();
8+
}

src/main/java/com/github/spriet2000/vertx/handlers/http/server/ext/bodyParser/BodyParseException.java renamed to src/main/java/com/github/spriet2000/vertx/handlers/extensions/bodyParser/BodyParseException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.spriet2000.vertx.handlers.http.server.ext.bodyParser;
1+
package com.github.spriet2000.vertx.handlers.extensions.bodyParser;
22

33

44
public final class BodyParseException extends Exception {

src/main/java/com/github/spriet2000/vertx/handlers/http/server/ext/bodyParser/impl/JsonBodyParser.java renamed to src/main/java/com/github/spriet2000/vertx/handlers/extensions/bodyParser/impl/JsonBodyParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package com.github.spriet2000.vertx.handlers.http.server.ext.bodyParser.impl;
1+
package com.github.spriet2000.vertx.handlers.extensions.bodyParser.impl;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import com.github.spriet2000.vertx.handlers.http.server.ext.bodyParser.Body;
5-
import com.github.spriet2000.vertx.handlers.http.server.ext.bodyParser.BodyParseException;
4+
import com.github.spriet2000.vertx.handlers.extensions.bodyParser.Body;
5+
import com.github.spriet2000.vertx.handlers.extensions.bodyParser.BodyParseException;
66
import io.netty.handler.codec.http.HttpHeaders;
77
import io.vertx.core.buffer.Buffer;
88
import io.vertx.core.http.HttpMethod;

0 commit comments

Comments
 (0)