@@ -66,8 +66,8 @@ record HandlerConfig(
6666 Map <String , RequestHandler > extras ,
6767 boolean externalAuth ,
6868 List <AfterResponseHook > afterHooks ,
69- long maxDecompressedRequestBytes ,
70- long minimumGzipResponseBytes ) {}
69+ RequestBodyReader bodyReader ,
70+ ResponseRenderer renderer ) {}
7171
7272 OpenApiServer (
7373 List <SpecBinding > bindings ,
@@ -86,7 +86,6 @@ record HandlerConfig(
8686 requireNonNull (bodyMappers , "bodyMappers must not be null" );
8787
8888 long t0 = System .currentTimeMillis ();
89- ExceptionHandler exceptionHandler = handlerConfig .exceptionHandler ();
9089
9190 InetSocketAddress socketAddress =
9291 (bindAddress == null )
@@ -95,26 +94,8 @@ record HandlerConfig(
9594 this .httpServer = createHttpServer (socketAddress , sslContext );
9695 httpServer .setExecutor (newThreadPerTaskExecutor (ofVirtual ().name ("http-" , 0 ).factory ()));
9796
98- ResponseRenderer renderer =
99- new ResponseRenderer (bodyMappers , handlerConfig .minimumGzipResponseBytes ());
100- RequestBodyReader bodyReader =
101- new RequestBodyReader (handlerConfig .maxDecompressedRequestBytes ());
102- boolean anyBindingAtRoot =
103- wireBindings (
104- httpServer ,
105- bindings ,
106- bodyMappers ,
107- handlerConfig ,
108- exceptionHandler ,
109- renderer ,
110- bodyReader );
111- wireExtras (
112- httpServer ,
113- anyBindingAtRoot ,
114- handlerConfig .extras (),
115- exceptionHandler ,
116- renderer ,
117- bodyReader );
97+ boolean anyBindingAtRoot = wireBindings (httpServer , bindings , bodyMappers , handlerConfig );
98+ wireExtras (httpServer , anyBindingAtRoot , handlerConfig );
11899
119100 httpServer .start ();
120101 this .shutdownTimeoutSeconds = shutdownTimeoutSeconds ;
@@ -131,42 +112,26 @@ private static HttpServer createHttpServer(InetSocketAddress addr, SSLContext ss
131112 return HttpServer .create (addr , 0 );
132113 }
133114
134- @ SuppressWarnings ("java:S107" )
135115 private static boolean wireBindings (
136116 HttpServer httpServer ,
137117 List <SpecBinding > bindings ,
138118 Map <String , TypeMapper > bodyMappers ,
139- HandlerConfig handlerConfig ,
140- ExceptionHandler exceptionHandler ,
141- ResponseRenderer renderer ,
142- RequestBodyReader bodyReader ) {
119+ HandlerConfig handlerConfig ) {
143120 boolean anyBindingAtRoot = false ;
144121 for (SpecBinding binding : bindings ) {
145122 String basePath = Optional .ofNullable (binding .spec ().basePath ()).orElse ("/" );
146123 anyBindingAtRoot |= "/" .equals (basePath );
147- wireBinding (
148- httpServer ,
149- basePath ,
150- binding ,
151- bodyMappers ,
152- handlerConfig ,
153- exceptionHandler ,
154- renderer ,
155- bodyReader );
124+ wireBinding (httpServer , basePath , binding , bodyMappers , handlerConfig );
156125 }
157126 return anyBindingAtRoot ;
158127 }
159128
160- @ SuppressWarnings ("java:S107" )
161129 private static void wireBinding (
162130 HttpServer httpServer ,
163131 String basePath ,
164132 SpecBinding binding ,
165133 Map <String , TypeMapper > bodyMappers ,
166- HandlerConfig handlerConfig ,
167- ExceptionHandler exceptionHandler ,
168- ResponseRenderer renderer ,
169- RequestBodyReader bodyReader ) {
134+ HandlerConfig handlerConfig ) {
170135 Map <String , Operation > operationsById =
171136 binding .spec ().operations ().stream ()
172137 .collect (Collectors .toUnmodifiableMap (Operation ::operationId , op -> op ));
@@ -178,10 +143,10 @@ private static void wireBinding(
178143 binding .router (),
179144 binding .validator (),
180145 bodyMappers ,
181- exceptionHandler ,
182- renderer ,
146+ handlerConfig . exceptionHandler () ,
147+ handlerConfig . renderer () ,
183148 handlerConfig .afterHooks (),
184- bodyReader ));
149+ handlerConfig . bodyReader () ));
185150 ctx .getFilters ()
186151 .add (
187152 new SecurityFilter (
@@ -195,26 +160,25 @@ private static void wireBinding(
195160 binding .handlers (),
196161 handlerConfig .interceptors (),
197162 handlerConfig .decorators (),
198- renderer ));
163+ handlerConfig . renderer () ));
199164 }
200165
201166 private static void wireExtras (
202- HttpServer httpServer ,
203- boolean anyBindingAtRoot ,
204- Map <String , RequestHandler > extras ,
205- ExceptionHandler exceptionHandler ,
206- ResponseRenderer renderer ,
207- RequestBodyReader bodyReader ) {
167+ HttpServer httpServer , boolean anyBindingAtRoot , HandlerConfig handlerConfig ) {
168+ Map <String , RequestHandler > extras = handlerConfig .extras ();
208169 if (anyBindingAtRoot ) {
209170 if (!extras .isEmpty ()) {
210171 throw new IllegalStateException (
211172 "extras cannot be registered when a binding owns basePath '/'" );
212173 }
213174 return ;
214175 }
215- ExtrasRouter extrasRouter = new ExtrasRouter (extras , renderer , bodyReader );
176+ ExtrasRouter extrasRouter =
177+ new ExtrasRouter (extras , handlerConfig .renderer (), handlerConfig .bodyReader ());
216178 HttpContext extrasCtx = httpServer .createContext ("/" , extrasRouter );
217- extrasCtx .getFilters ().add (new ExceptionFilter (exceptionHandler , renderer ));
179+ extrasCtx
180+ .getFilters ()
181+ .add (new ExceptionFilter (handlerConfig .exceptionHandler (), handlerConfig .renderer ()));
218182 }
219183
220184 private void logStartup (long t0 ) {
@@ -510,8 +474,8 @@ public OpenApiServer build() throws IOException {
510474 extras ,
511475 externalAuth ,
512476 List .copyOf (afterHooks ),
513- maxDecompressedRequestBytes ,
514- minimumGzipResponseBytes );
477+ new RequestBodyReader ( maxDecompressedRequestBytes ) ,
478+ new ResponseRenderer ( resolved , minimumGzipResponseBytes ) );
515479 int resolvedPort = resolvePort ();
516480 SSLContext sslContext =
517481 httpsCertChain != null ? PemSslContext .load (httpsCertChain , httpsPrivateKey ) : null ;
0 commit comments