|
6 | 6 |
|
7 | 7 | import com.retailsvc.http.internal.DispatchHandler; |
8 | 8 | import com.retailsvc.http.internal.ExceptionFilter; |
| 9 | +import com.retailsvc.http.internal.ExtraRouteAdapter; |
9 | 10 | import com.retailsvc.http.internal.FormTypeMapper; |
| 11 | +import com.retailsvc.http.internal.NotFoundHandler; |
10 | 12 | import com.retailsvc.http.internal.RequestPreparationFilter; |
11 | 13 | import com.retailsvc.http.internal.ResponseRenderer; |
12 | 14 | import com.retailsvc.http.internal.Router; |
|
18 | 20 | import com.retailsvc.http.spec.security.SecurityScheme; |
19 | 21 | import com.retailsvc.http.validate.DefaultValidator; |
20 | 22 | import com.sun.net.httpserver.HttpContext; |
21 | | -import com.sun.net.httpserver.HttpHandler; |
22 | 23 | import com.sun.net.httpserver.HttpServer; |
23 | 24 | import java.io.IOException; |
24 | 25 | import java.net.InetAddress; |
@@ -57,7 +58,7 @@ record HandlerConfig( |
57 | 58 | List<RequestInterceptor> interceptors, |
58 | 59 | List<ResponseDecorator> decorators, |
59 | 60 | ExceptionHandler exceptionHandler, |
60 | | - Map<String, HttpHandler> extras, |
| 61 | + Map<String, RequestHandler> extras, |
61 | 62 | Map<String, SchemeValidator> securityValidators, |
62 | 63 | boolean externalAuth) {} |
63 | 64 |
|
@@ -110,14 +111,14 @@ record HandlerConfig( |
110 | 111 | handlerConfig.decorators(), |
111 | 112 | renderer)); |
112 | 113 |
|
113 | | - for (Map.Entry<String, HttpHandler> e : handlerConfig.extras().entrySet()) { |
| 114 | + for (Map.Entry<String, RequestHandler> e : handlerConfig.extras().entrySet()) { |
114 | 115 | HttpContext extraCtx = httpServer.createContext(e.getKey()); |
115 | 116 | extraCtx.getFilters().add(new ExceptionFilter(exceptionHandler, renderer)); |
116 | | - extraCtx.setHandler(e.getValue()); |
| 117 | + extraCtx.setHandler(new ExtraRouteAdapter(e.getValue(), renderer)); |
117 | 118 | } |
118 | 119 |
|
119 | 120 | if (!"/".equals(basePath)) { |
120 | | - httpServer.createContext("/", Handlers.notFoundHandler()); |
| 121 | + httpServer.createContext("/", new NotFoundHandler()); |
121 | 122 | } |
122 | 123 | httpServer.start(); |
123 | 124 |
|
@@ -180,7 +181,7 @@ public static final class Builder { |
180 | 181 | private int port = DEFAULT_PORT; |
181 | 182 | private InetAddress bindAddress; |
182 | 183 | private int shutdownTimeoutSeconds = 0; |
183 | | - private final LinkedHashMap<String, HttpHandler> extras = new LinkedHashMap<>(); |
| 184 | + private final LinkedHashMap<String, RequestHandler> extras = new LinkedHashMap<>(); |
184 | 185 | private final Map<String, SchemeValidator> securityValidators = new LinkedHashMap<>(); |
185 | 186 | private boolean externalAuth = false; |
186 | 187 |
|
@@ -294,7 +295,7 @@ public Builder shutdownTimeoutSeconds(int shutdownTimeoutSeconds) { |
294 | 295 | * anything that isn't an OpenAPI {@code operationId}. For OpenAPI-described operations use |
295 | 296 | * {@link #handlers(Map)}. |
296 | 297 | */ |
297 | | - public Builder extraRoute(String path, HttpHandler handler) { |
| 298 | + public Builder extraRoute(String path, RequestHandler handler) { |
298 | 299 | requireNonNull(path, "path must not be null"); |
299 | 300 | requireNonNull(handler, "handler must not be null"); |
300 | 301 | if (extras.containsKey(path)) { |
|
0 commit comments