Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit ee23fbb

Browse files
committed
Duplicates every methods in order to introduce a parameter for the duplicated methods. Fixes JERSEY-3171.
1 parent f235f18 commit ee23fbb

File tree

1 file changed

+223
-4
lines changed

1 file changed

+223
-4
lines changed

Diff for: containers/grizzly2-http/src/main/java/org/glassfish/jersey/grizzly2/httpserver/GrizzlyHttpServerFactory.java

+223-4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.glassfish.grizzly.http.server.ServerConfiguration;
6060
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
6161
import org.glassfish.grizzly.utils.Charsets;
62+
import org.glassfish.grizzly.PortRange;
6263

6364
import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
6465

@@ -92,6 +93,20 @@ public static HttpServer createHttpServer(final URI uri) {
9293
return createHttpServer(uri, (GrizzlyHttpContainer) null, false, null, true);
9394
}
9495

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+
95110
/**
96111
* Create new {@link HttpServer} instance.
97112
*
@@ -106,6 +121,22 @@ public static HttpServer createHttpServer(final URI uri, final boolean start) {
106121
return createHttpServer(uri, (GrizzlyHttpContainer) null, false, null, start);
107122
}
108123

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+
109140
/**
110141
* Create new {@link HttpServer} instance.
111142
*
@@ -125,6 +156,29 @@ public static HttpServer createHttpServer(final URI uri, final ResourceConfig co
125156
);
126157
}
127158

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+
128182
/**
129183
* Create new {@link HttpServer} instance.
130184
*
@@ -145,6 +199,30 @@ public static HttpServer createHttpServer(final URI uri, final ResourceConfig co
145199
start);
146200
}
147201

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+
148226
/**
149227
* Create new {@link HttpServer} instance.
150228
*
@@ -168,6 +246,33 @@ public static HttpServer createHttpServer(final URI uri,
168246
true);
169247
}
170248

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+
171276
/**
172277
* Create new {@link HttpServer} instance.
173278
*
@@ -194,6 +299,36 @@ public static HttpServer createHttpServer(final URI uri,
194299
start);
195300
}
196301

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+
197332
/**
198333
* Create new {@link HttpServer} instance.
199334
*
@@ -218,6 +353,34 @@ public static HttpServer createHttpServer(final URI uri,
218353
return createHttpServer(uri, new GrizzlyHttpContainer(config, parentLocator), secure, sslEngineConfigurator, true);
219354
}
220355

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+
221384
/**
222385
* Create new {@link HttpServer} instance.
223386
*
@@ -238,6 +401,29 @@ public static HttpServer createHttpServer(final URI uri,
238401
return createHttpServer(uri, new GrizzlyHttpContainer(config, parentLocator), false, null, true);
239402
}
240403

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+
241427
/**
242428
* Create new {@link HttpServer} instance.
243429
*
@@ -258,12 +444,45 @@ public static HttpServer createHttpServer(final URI uri,
258444
final SSLEngineConfigurator sslEngineConfigurator,
259445
final boolean start) {
260446

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+
261473
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();
265474

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+
}
267486

268487
listener.getTransport().getWorkerThreadPoolConfig().setThreadFactory(new ThreadFactoryBuilder()
269488
.setNameFormat("grizzly-http-server-%d")

0 commit comments

Comments
 (0)