Skip to content

Commit 93f74d8

Browse files
committed
feat: Replace per-route extras wiring with ExtrasRouter
Wire the single ExtrasRouter at "/" instead of creating one HttpContext per extra route. Delete ExtraRouteAdapter and NotFoundHandler, whose logic now lives in ExtrasRouter. Guard against extras when basePath is "/".
1 parent 7bce13d commit 93f74d8

4 files changed

Lines changed: 6 additions & 134 deletions

File tree

src/main/java/com/retailsvc/http/OpenApiServer.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
import com.retailsvc.http.internal.DispatchHandler;
88
import com.retailsvc.http.internal.ExceptionFilter;
9-
import com.retailsvc.http.internal.ExtraRouteAdapter;
9+
import com.retailsvc.http.internal.ExtrasRouter;
1010
import com.retailsvc.http.internal.FormTypeMapper;
11-
import com.retailsvc.http.internal.NotFoundHandler;
1211
import com.retailsvc.http.internal.PemSslContext;
1312
import com.retailsvc.http.internal.RequestPreparationFilter;
1413
import com.retailsvc.http.internal.ResponseRenderer;
@@ -134,14 +133,12 @@ record HandlerConfig(
134133
handlerConfig.decorators(),
135134
renderer));
136135

137-
for (Map.Entry<String, RequestHandler> e : handlerConfig.extras().entrySet()) {
138-
HttpContext extraCtx = httpServer.createContext(e.getKey());
139-
extraCtx.getFilters().add(new ExceptionFilter(exceptionHandler, renderer));
140-
extraCtx.setHandler(new ExtraRouteAdapter(e.getValue(), renderer));
141-
}
142-
143136
if (!"/".equals(basePath)) {
144-
httpServer.createContext("/", new NotFoundHandler());
137+
ExtrasRouter extrasRouter = new ExtrasRouter(handlerConfig.extras(), renderer);
138+
HttpContext extrasCtx = httpServer.createContext("/", extrasRouter);
139+
extrasCtx.getFilters().add(new ExceptionFilter(exceptionHandler, renderer));
140+
} else if (!handlerConfig.extras().isEmpty()) {
141+
throw new IllegalStateException("extras cannot be registered when basePath is '/'");
145142
}
146143
httpServer.start();
147144

src/main/java/com/retailsvc/http/internal/ExtraRouteAdapter.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/java/com/retailsvc/http/internal/NotFoundHandler.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/test/java/com/retailsvc/http/internal/ExtraRouteAdapterTest.java

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)