|
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.InetSocketAddress; |
@@ -56,7 +57,7 @@ record HandlerConfig( |
56 | 57 | List<RequestInterceptor> interceptors, |
57 | 58 | List<ResponseDecorator> decorators, |
58 | 59 | ExceptionHandler exceptionHandler, |
59 | | - Map<String, HttpHandler> extras, |
| 60 | + Map<String, RequestHandler> extras, |
60 | 61 | Map<String, SchemeValidator> securityValidators, |
61 | 62 | boolean externalAuth) {} |
62 | 63 |
|
@@ -103,13 +104,13 @@ record HandlerConfig( |
103 | 104 | handlerConfig.decorators(), |
104 | 105 | renderer)); |
105 | 106 |
|
106 | | - for (Map.Entry<String, HttpHandler> e : handlerConfig.extras().entrySet()) { |
| 107 | + for (Map.Entry<String, RequestHandler> e : handlerConfig.extras().entrySet()) { |
107 | 108 | HttpContext extraCtx = httpServer.createContext(e.getKey()); |
108 | 109 | extraCtx.getFilters().add(new ExceptionFilter(exceptionHandler, renderer)); |
109 | | - extraCtx.setHandler(e.getValue()); |
| 110 | + extraCtx.setHandler(new ExtraRouteAdapter(e.getValue(), renderer)); |
110 | 111 | } |
111 | 112 |
|
112 | | - httpServer.createContext("/", Handlers.notFoundHandler()); |
| 113 | + httpServer.createContext("/", new NotFoundHandler()); |
113 | 114 | httpServer.start(); |
114 | 115 |
|
115 | 116 | this.shutdownTimeoutSeconds = shutdownTimeoutSeconds; |
@@ -156,7 +157,7 @@ public static final class Builder { |
156 | 157 | private ExceptionHandler exceptionHandler; |
157 | 158 | private int port = DEFAULT_PORT; |
158 | 159 | private int shutdownTimeoutSeconds = 0; |
159 | | - private final LinkedHashMap<String, HttpHandler> extras = new LinkedHashMap<>(); |
| 160 | + private final LinkedHashMap<String, RequestHandler> extras = new LinkedHashMap<>(); |
160 | 161 | private final Map<String, SchemeValidator> securityValidators = new LinkedHashMap<>(); |
161 | 162 | private boolean externalAuth = false; |
162 | 163 |
|
@@ -256,7 +257,7 @@ public Builder shutdownTimeoutSeconds(int shutdownTimeoutSeconds) { |
256 | 257 | * anything that isn't an OpenAPI {@code operationId}. For OpenAPI-described operations use |
257 | 258 | * {@link #handlers(Map)}. |
258 | 259 | */ |
259 | | - public Builder extraRoute(String path, HttpHandler handler) { |
| 260 | + public Builder extraRoute(String path, RequestHandler handler) { |
260 | 261 | requireNonNull(path, "path must not be null"); |
261 | 262 | requireNonNull(handler, "handler must not be null"); |
262 | 263 | if (extras.containsKey(path)) { |
|
0 commit comments