-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ModelBindCheckMiddleware, moved SerializedResponseTransformer t…
…o http-router, incremented dependency versions
- Loading branch information
Showing
4 changed files
with
36 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/org/javawebstack/webutils/middleware/ModelBindCheckMiddleware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.javawebstack.webutils.middleware; | ||
|
||
import org.javawebstack.httpserver.Exchange; | ||
import org.javawebstack.httpserver.handler.RequestHandler; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
public class ModelBindCheckMiddleware implements RequestHandler { | ||
|
||
private final BiFunction<Exchange, String, Object> handler; | ||
|
||
public ModelBindCheckMiddleware() { | ||
this(ModelBindCheckMiddleware::defaultHandler); | ||
} | ||
|
||
public ModelBindCheckMiddleware(BiFunction<Exchange, String, Object> handler) { | ||
this.handler = handler; | ||
} | ||
|
||
public Object handle(Exchange exchange) { | ||
for (String key : exchange.getPathVariables().keySet()) { | ||
if (exchange.getPathVariables().get(key) == null) | ||
return handler.apply(exchange, key); | ||
} | ||
return null; | ||
} | ||
|
||
private static Object defaultHandler(Exchange exchange, String key) { | ||
exchange.status(404); | ||
return "Not Found"; | ||
} | ||
|
||
} |
3 changes: 1 addition & 2 deletions
3
...tils/middlewares/RateLimitMiddleware.java → ...utils/middleware/RateLimitMiddleware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
src/main/java/org/javawebstack/webutils/middleware/SerializedResponseTransformer.java
This file was deleted.
Oops, something went wrong.