59
59
import org .glassfish .grizzly .http .server .ServerConfiguration ;
60
60
import org .glassfish .grizzly .ssl .SSLEngineConfigurator ;
61
61
import org .glassfish .grizzly .utils .Charsets ;
62
+ import org .glassfish .grizzly .PortRange ;
62
63
63
64
import org .glassfish .jersey .internal .guava .ThreadFactoryBuilder ;
64
65
@@ -92,6 +93,20 @@ public static HttpServer createHttpServer(final URI uri) {
92
93
return createHttpServer (uri , (GrizzlyHttpContainer ) null , false , null , true );
93
94
}
94
95
96
+ /**
97
+ * Create new {@link HttpServer} instance.
98
+ *
99
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
100
+ * as context path, the rest as well as the port will be ignored.
101
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
102
+ * randomly chosen between this port range.
103
+ * @return newly created {@code HttpServer}.
104
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
105
+ */
106
+ public static HttpServer createHttpServer (final URI uri , final PortRange portRange ) {
107
+ return createHttpServer (uri , portRange , (GrizzlyHttpContainer ) null , false , null , true );
108
+ }
109
+
95
110
/**
96
111
* Create new {@link HttpServer} instance.
97
112
*
@@ -106,6 +121,22 @@ public static HttpServer createHttpServer(final URI uri, final boolean start) {
106
121
return createHttpServer (uri , (GrizzlyHttpContainer ) null , false , null , start );
107
122
}
108
123
124
+ /**
125
+ * Create new {@link HttpServer} instance.
126
+ *
127
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
128
+ * as context path, the rest as well as the port will be ignored.
129
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
130
+ * randomly chosen between this port range.
131
+ * @param start if set to false, server will not get started, which allows to configure the underlying transport
132
+ * layer, see above for details.
133
+ * @return newly created {@code HttpServer}.
134
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
135
+ */
136
+ public static HttpServer createHttpServer (final URI uri , final PortRange portRange , final boolean start ) {
137
+ return createHttpServer (uri , portRange , (GrizzlyHttpContainer ) null , false , null , start );
138
+ }
139
+
109
140
/**
110
141
* Create new {@link HttpServer} instance.
111
142
*
@@ -125,6 +156,29 @@ public static HttpServer createHttpServer(final URI uri, final ResourceConfig co
125
156
);
126
157
}
127
158
159
+ /**
160
+ * Create new {@link HttpServer} instance.
161
+ *
162
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
163
+ * as context path, the rest as well as the port will be ignored.
164
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
165
+ * randomly chosen between this port range.
166
+ * @param configuration web application configuration.
167
+ * @return newly created {@code HttpServer}.
168
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
169
+ */
170
+ public static HttpServer createHttpServer (final URI uri , final PortRange portRange ,
171
+ final ResourceConfig configuration ) {
172
+ return createHttpServer (
173
+ uri ,
174
+ portRange ,
175
+ new GrizzlyHttpContainer (configuration ),
176
+ false ,
177
+ null ,
178
+ true
179
+ );
180
+ }
181
+
128
182
/**
129
183
* Create new {@link HttpServer} instance.
130
184
*
@@ -145,6 +199,30 @@ public static HttpServer createHttpServer(final URI uri, final ResourceConfig co
145
199
start );
146
200
}
147
201
202
+ /**
203
+ * Create new {@link HttpServer} instance.
204
+ *
205
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
206
+ * as context path, the rest as well as the port will be ignored.
207
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
208
+ * randomly chosen between this port range.
209
+ * @param configuration web application configuration.
210
+ * @param start if set to false, server will not get started, which allows to configure the underlying
211
+ * transport layer, see above for details.
212
+ * @return newly created {@code HttpServer}.
213
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
214
+ */
215
+ public static HttpServer createHttpServer (final URI uri , final PortRange portRange ,
216
+ final ResourceConfig configuration , final boolean start ) {
217
+ return createHttpServer (
218
+ uri ,
219
+ portRange ,
220
+ new GrizzlyHttpContainer (configuration ),
221
+ false ,
222
+ null ,
223
+ start );
224
+ }
225
+
148
226
/**
149
227
* Create new {@link HttpServer} instance.
150
228
*
@@ -168,6 +246,33 @@ public static HttpServer createHttpServer(final URI uri,
168
246
true );
169
247
}
170
248
249
+ /**
250
+ * Create new {@link HttpServer} instance.
251
+ *
252
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
253
+ * as context path, the rest as well as the port will be ignored.
254
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
255
+ * randomly chosen between this port range.
256
+ * @param configuration web application configuration.
257
+ * @param secure used for call {@link NetworkListener#setSecure(boolean)}.
258
+ * @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}.
259
+ * @return newly created {@code HttpServer}.
260
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
261
+ */
262
+ public static HttpServer createHttpServer (final URI uri ,
263
+ final PortRange portRange ,
264
+ final ResourceConfig configuration ,
265
+ final boolean secure ,
266
+ final SSLEngineConfigurator sslEngineConfigurator ) {
267
+ return createHttpServer (
268
+ uri ,
269
+ portRange ,
270
+ new GrizzlyHttpContainer (configuration ),
271
+ secure ,
272
+ sslEngineConfigurator ,
273
+ true );
274
+ }
275
+
171
276
/**
172
277
* Create new {@link HttpServer} instance.
173
278
*
@@ -194,6 +299,36 @@ public static HttpServer createHttpServer(final URI uri,
194
299
start );
195
300
}
196
301
302
+ /**
303
+ * Create new {@link HttpServer} instance.
304
+ *
305
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
306
+ * as context path, the rest as well as the port will be ignored.
307
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
308
+ * randomly chosen between this port range.
309
+ * @param configuration web application configuration.
310
+ * @param secure used for call {@link NetworkListener#setSecure(boolean)}.
311
+ * @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}.
312
+ * @param start if set to false, server will not get started, which allows to configure the
313
+ * underlying transport, see above for details.
314
+ * @return newly created {@code HttpServer}.
315
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
316
+ */
317
+ public static HttpServer createHttpServer (final URI uri ,
318
+ final PortRange portRange ,
319
+ final ResourceConfig configuration ,
320
+ final boolean secure ,
321
+ final SSLEngineConfigurator sslEngineConfigurator ,
322
+ final boolean start ) {
323
+ return createHttpServer (
324
+ uri ,
325
+ portRange ,
326
+ new GrizzlyHttpContainer (configuration ),
327
+ secure ,
328
+ sslEngineConfigurator ,
329
+ start );
330
+ }
331
+
197
332
/**
198
333
* Create new {@link HttpServer} instance.
199
334
*
@@ -218,6 +353,34 @@ public static HttpServer createHttpServer(final URI uri,
218
353
return createHttpServer (uri , new GrizzlyHttpContainer (config , parentLocator ), secure , sslEngineConfigurator , true );
219
354
}
220
355
356
+ /**
357
+ * Create new {@link HttpServer} instance.
358
+ *
359
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
360
+ * as context path, the rest as well as the port will be ignored.
361
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
362
+ * randomly chosen between this port range.
363
+ * @param config web application configuration.
364
+ * @param secure used for call {@link NetworkListener#setSecure(boolean)}.
365
+ * @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}.
366
+ * @param parentLocator {@link org.glassfish.hk2.api.ServiceLocator} to become a parent of the locator used by
367
+ * {@link org.glassfish.jersey.server.ApplicationHandler}
368
+ * @return newly created {@code HttpServer}.
369
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
370
+ * @see GrizzlyHttpContainer
371
+ * @see org.glassfish.hk2.api.ServiceLocator
372
+ * @since 2.3.29
373
+ */
374
+ public static HttpServer createHttpServer (final URI uri ,
375
+ final PortRange portRange ,
376
+ final ResourceConfig config ,
377
+ final boolean secure ,
378
+ final SSLEngineConfigurator sslEngineConfigurator ,
379
+ final ServiceLocator parentLocator ) {
380
+ return createHttpServer (uri , portRange , new GrizzlyHttpContainer (config , parentLocator ), secure ,
381
+ sslEngineConfigurator , true );
382
+ }
383
+
221
384
/**
222
385
* Create new {@link HttpServer} instance.
223
386
*
@@ -238,6 +401,29 @@ public static HttpServer createHttpServer(final URI uri,
238
401
return createHttpServer (uri , new GrizzlyHttpContainer (config , parentLocator ), false , null , true );
239
402
}
240
403
404
+ /**
405
+ * Create new {@link HttpServer} instance.
406
+ *
407
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
408
+ * as context path, the rest as well as the port will be ignored.
409
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
410
+ * randomly chosen between this port range.
411
+ * @param config web application configuration.
412
+ * @param parentLocator {@link org.glassfish.hk2.api.ServiceLocator} to become a parent of the locator used by
413
+ * {@link org.glassfish.jersey.server.ApplicationHandler}
414
+ * @return newly created {@code HttpServer}.
415
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
416
+ * @see GrizzlyHttpContainer
417
+ * @see org.glassfish.hk2.api.ServiceLocator
418
+ * @since 2.12
419
+ */
420
+ public static HttpServer createHttpServer (final URI uri ,
421
+ final PortRange portRange ,
422
+ final ResourceConfig config ,
423
+ final ServiceLocator parentLocator ) {
424
+ return createHttpServer (uri , portRange , new GrizzlyHttpContainer (config , parentLocator ), false , null , true );
425
+ }
426
+
241
427
/**
242
428
* Create new {@link HttpServer} instance.
243
429
*
@@ -258,12 +444,45 @@ public static HttpServer createHttpServer(final URI uri,
258
444
final SSLEngineConfigurator sslEngineConfigurator ,
259
445
final boolean start ) {
260
446
447
+ return createHttpServer (uri , null , handler , secure , sslEngineConfigurator , start );
448
+ }
449
+
450
+ /**
451
+ * Create new {@link HttpServer} instance.
452
+ *
453
+ * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used
454
+ * as context path, the rest as well as the port will be ignored.
455
+ * @param portRange port range on which the {@link ApplicationHandler} will be bound. One available port will be
456
+ * randomly chosen between this port range.
457
+ * @param handler {@link HttpHandler} instance.
458
+ * @param secure used for call {@link NetworkListener#setSecure(boolean)}.
459
+ * @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}.
460
+ * @param start if set to false, server will not get started, this allows end users to set
461
+ * additional properties on the underlying listener.
462
+ * @return newly created {@code HttpServer}.
463
+ * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
464
+ * @see GrizzlyHttpContainer
465
+ */
466
+ public static HttpServer createHttpServer (final URI uri ,
467
+ final PortRange portRange ,
468
+ final GrizzlyHttpContainer handler ,
469
+ final boolean secure ,
470
+ final SSLEngineConfigurator sslEngineConfigurator ,
471
+ final boolean start ) {
472
+
261
473
final String host = (uri .getHost () == null ) ? NetworkListener .DEFAULT_NETWORK_HOST : uri .getHost ();
262
- final int port = (uri .getPort () == -1 )
263
- ? (secure ? Container .DEFAULT_HTTPS_PORT : Container .DEFAULT_HTTP_PORT )
264
- : uri .getPort ();
265
474
266
- final NetworkListener listener = new NetworkListener ("grizzly" , host , port );
475
+ final NetworkListener listener ;
476
+
477
+ if (portRange != null ) {
478
+ listener = new NetworkListener ("grizzly" , host , portRange );
479
+ } else {
480
+ final int port = (uri .getPort () == -1 )
481
+ ? (secure ? Container .DEFAULT_HTTPS_PORT : Container .DEFAULT_HTTP_PORT )
482
+ : uri .getPort ();
483
+
484
+ listener = new NetworkListener ("grizzly" , host , port );
485
+ }
267
486
268
487
listener .getTransport ().getWorkerThreadPoolConfig ().setThreadFactory (new ThreadFactoryBuilder ()
269
488
.setNameFormat ("grizzly-http-server-%d" )
0 commit comments