Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to get handler in e.g. middlewares #30

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/org/javawebstack/http/router/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.javawebstack.abstractdata.*;
import org.javawebstack.abstractdata.mapper.Mapper;
import org.javawebstack.http.router.adapter.IHTTPSocket;
import org.javawebstack.http.router.handler.RequestHandler;
import org.javawebstack.http.router.multipart.Part;
import org.javawebstack.http.router.multipart.content.InMemoryCache;
import org.javawebstack.http.router.multipart.content.PartContentCache;
Expand All @@ -15,6 +16,7 @@
import org.javawebstack.validator.Validator;

import java.io.*;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -36,6 +38,7 @@ public static Exchange current() {
private final IHTTPSocket socket;
private final Map<String, Object> attributes = new HashMap<>();
private List<Part> parts = null;
private RequestHandler finalHandler;

public Exchange(HTTPRouter router, IHTTPSocket socket) {
this.router = router;
Expand Down Expand Up @@ -365,4 +368,12 @@ public MimeType getMimeType() {
return MimeType.byMimeType(contentType.getValue().toLowerCase(Locale.ROOT));
}

protected Exchange setFinalHandler(RequestHandler finalHandler) {
this.finalHandler = finalHandler;
return this;
}

public RequestHandler getFinalHandler() {
return finalHandler;
}
}
1 change: 1 addition & 0 deletions src/main/java/org/javawebstack/http/router/HTTPRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public void execute(Exchange exchange) {
continue;
exchange.getPathVariables().putAll(pathVariables);
for (RequestHandler handler : route.getHandlers()) {
exchange.setFinalHandler(handler);
response = handler.handle(exchange);
if (exchange.getMethod() == HTTPMethod.WEBSOCKET) {
Exchange.exchanges.remove();
Expand Down