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

Commit a9c0f9c

Browse files
author
Petr Bouda
committed
Removing HK2 ServiceLocator from containers and container factories.
Change-Id: I3dcdc976c31750a5d5836765b543ba0cd2bf0360
1 parent abd5406 commit a9c0f9c

File tree

16 files changed

+106
-140
lines changed

16 files changed

+106
-140
lines changed

containers/grizzly2-http/src/main/java/org/glassfish/jersey/grizzly2/httpserver/GrizzlyHttpContainer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@
7676
import org.glassfish.jersey.server.spi.Container;
7777
import org.glassfish.jersey.server.spi.ContainerResponseWriter;
7878

79-
import org.glassfish.hk2.api.ServiceLocator;
80-
8179
import org.glassfish.grizzly.CompletionHandler;
8280
import org.glassfish.grizzly.http.server.HttpHandler;
8381
import org.glassfish.grizzly.http.server.Request;
@@ -342,10 +340,10 @@ private void rethrow(final Throwable error) {
342340
* Create a new Grizzly HTTP container.
343341
*
344342
* @param application JAX-RS / Jersey application to be deployed on Grizzly HTTP container.
345-
* @param parentLocator parent injection manager.
343+
* @param parentContext DI provider specific context with application's registered bindings.
346344
*/
347-
/* package */ GrizzlyHttpContainer(final Application application, final ServiceLocator parentLocator) {
348-
this.appHandler = new ApplicationHandler(application, new GrizzlyBinder(), parentLocator);
345+
/* package */ GrizzlyHttpContainer(final Application application, final Object parentContext) {
346+
this.appHandler = new ApplicationHandler(application, new GrizzlyBinder(), parentContext);
349347
cacheConfigSetStatusOverSendError();
350348
cacheConfigEnableLeadingContextPathSlashes();
351349
}

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2016 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -50,8 +50,6 @@
5050
import org.glassfish.jersey.server.ResourceConfig;
5151
import org.glassfish.jersey.server.spi.Container;
5252

53-
import org.glassfish.hk2.api.ServiceLocator;
54-
5553
import org.glassfish.grizzly.http.server.HttpHandler;
5654
import org.glassfish.grizzly.http.server.HttpHandlerRegistration;
5755
import org.glassfish.grizzly.http.server.HttpServer;
@@ -202,20 +200,19 @@ public static HttpServer createHttpServer(final URI uri,
202200
* @param config web application configuration.
203201
* @param secure used for call {@link NetworkListener#setSecure(boolean)}.
204202
* @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}.
205-
* @param parentLocator {@link org.glassfish.hk2.api.ServiceLocator} to become a parent of the locator used by
206-
* {@link org.glassfish.jersey.server.ApplicationHandler}
203+
* @param parentContext DI provider specific context with application's registered bindings.
207204
* @return newly created {@code HttpServer}.
208205
* @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
209206
* @see GrizzlyHttpContainer
210-
* @see org.glassfish.hk2.api.ServiceLocator
211207
* @since 2.12
212208
*/
213209
public static HttpServer createHttpServer(final URI uri,
214210
final ResourceConfig config,
215211
final boolean secure,
216212
final SSLEngineConfigurator sslEngineConfigurator,
217-
final ServiceLocator parentLocator) {
218-
return createHttpServer(uri, new GrizzlyHttpContainer(config, parentLocator), secure, sslEngineConfigurator, true);
213+
final Object parentContext) {
214+
return createHttpServer(uri, new GrizzlyHttpContainer(config, parentContext), secure, sslEngineConfigurator,
215+
true);
219216
}
220217

221218
/**
@@ -224,18 +221,16 @@ public static HttpServer createHttpServer(final URI uri,
224221
* @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path
225222
* segment will be used as context path, the rest will be ignored.
226223
* @param config web application configuration.
227-
* @param parentLocator {@link org.glassfish.hk2.api.ServiceLocator} to become a parent of the locator used by
228-
* {@link org.glassfish.jersey.server.ApplicationHandler}
224+
* @param parentContext DI provider specific context with application's registered bindings.
229225
* @return newly created {@code HttpServer}.
230226
* @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance.
231227
* @see GrizzlyHttpContainer
232-
* @see org.glassfish.hk2.api.ServiceLocator
233228
* @since 2.12
234229
*/
235230
public static HttpServer createHttpServer(final URI uri,
236231
final ResourceConfig config,
237-
final ServiceLocator parentLocator) {
238-
return createHttpServer(uri, new GrizzlyHttpContainer(config, parentLocator), false, null, true);
232+
final Object parentContext) {
233+
return createHttpServer(uri, new GrizzlyHttpContainer(config, parentContext), false, null, true);
239234
}
240235

241236
/**

containers/jdk-http/src/main/java/org/glassfish/jersey/jdkhttp/JdkHttpHandlerContainer.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -69,8 +69,6 @@
6969
import org.glassfish.jersey.server.spi.Container;
7070
import org.glassfish.jersey.server.spi.ContainerResponseWriter;
7171

72-
import org.glassfish.hk2.api.ServiceLocator;
73-
7472
import com.sun.net.httpserver.Headers;
7573
import com.sun.net.httpserver.HttpExchange;
7674
import com.sun.net.httpserver.HttpHandler;
@@ -101,11 +99,11 @@ public class JdkHttpHandlerContainer implements HttpHandler, Container {
10199
/**
102100
* Create new lightweight Java SE HTTP server container.
103101
*
104-
* @param application JAX-RS / Jersey application to be deployed on the container.
105-
* @param parentLocator parent HK2 service locator.
102+
* @param application JAX-RS / Jersey application to be deployed on the container.
103+
* @param parentContext DI provider specific context with application's registered bindings.
106104
*/
107-
JdkHttpHandlerContainer(final Application application, final ServiceLocator parentLocator) {
108-
this.appHandler = new ApplicationHandler(application, null, parentLocator);
105+
JdkHttpHandlerContainer(final Application application, final Object parentContext) {
106+
this.appHandler = new ApplicationHandler(application, null, parentContext);
109107
}
110108

111109
@Override

containers/jdk-http/src/main/java/org/glassfish/jersey/jdkhttp/JdkHttpServerFactory.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2016 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -51,21 +51,18 @@
5151

5252
import javax.net.ssl.SSLContext;
5353

54+
import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
5455
import org.glassfish.jersey.jdkhttp.internal.LocalizationMessages;
5556
import org.glassfish.jersey.process.JerseyProcessingUncaughtExceptionHandler;
5657
import org.glassfish.jersey.server.ResourceConfig;
5758
import org.glassfish.jersey.server.spi.Container;
5859

59-
import org.glassfish.hk2.api.ServiceLocator;
60-
6160
import com.sun.net.httpserver.HttpContext;
6261
import com.sun.net.httpserver.HttpHandler;
6362
import com.sun.net.httpserver.HttpServer;
6463
import com.sun.net.httpserver.HttpsConfigurator;
6564
import com.sun.net.httpserver.HttpsServer;
6665

67-
import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
68-
6966
/**
7067
* Factory for creating {@link HttpServer JDK HttpServer} instances to run Jersey applications.
7168
*
@@ -118,17 +115,15 @@ public static HttpServer createHttpServer(final URI uri, final ResourceConfig co
118115
*
119116
* @param uri the {@link URI uri} on which the Jersey application will be deployed.
120117
* @param configuration the Jersey server-side application configuration.
121-
* @param parentLocator {@link org.glassfish.hk2.api.ServiceLocator} to become a parent of the locator used by
122-
* {@link org.glassfish.jersey.server.ApplicationHandler}
118+
* @param parentContext DI provider specific context with application's registered bindings.
123119
* @return Newly created {@link HttpServer}.
124120
* @throws ProcessingException thrown when problems during server creation occurs.
125121
* @see org.glassfish.jersey.jdkhttp.JdkHttpHandlerContainer
126-
* @see org.glassfish.hk2.api.ServiceLocator
127122
* @since 2.12
128123
*/
129124
public static HttpServer createHttpServer(final URI uri, final ResourceConfig configuration,
130-
final ServiceLocator parentLocator) {
131-
return createHttpServer(uri, new JdkHttpHandlerContainer(configuration, parentLocator), true);
125+
final Object parentContext) {
126+
return createHttpServer(uri, new JdkHttpHandlerContainer(configuration, parentContext), true);
132127
}
133128

134129
/**
@@ -181,21 +176,20 @@ public static HttpServer createHttpServer(final URI uri, final ResourceConfig co
181176
* The {@code start} flag controls whether or not the returned {@link HttpServer JDK HttpServer} is started.
182177
* </p>
183178
*
184-
* @param uri the {@link URI uri} on which the Jersey application will be deployed.
185-
* @param configuration the Jersey server-side application configuration.
186-
* @param parentLocator {@link org.glassfish.hk2.api.ServiceLocator} to become a parent of the locator used by
187-
* {@link org.glassfish.jersey.server.ApplicationHandler}
188-
* @param sslContext custom {@link SSLContext} to be passed to the server
189-
* @param start if set to {@code false}, the created server will not be automatically started.
179+
* @param uri the {@link URI uri} on which the Jersey application will be deployed.
180+
* @param configuration the Jersey server-side application configuration.
181+
* @param parentContext DI provider specific context with application's registered bindings.
182+
* @param sslContext custom {@link SSLContext} to be passed to the server
183+
* @param start if set to {@code false}, the created server will not be automatically started.
190184
* @return Newly created {@link HttpServer}.
191185
* @throws ProcessingException thrown when problems during server creation occurs.
192186
* @since 2.18
193187
*/
194188
public static HttpServer createHttpServer(final URI uri, final ResourceConfig configuration,
195-
final ServiceLocator parentLocator,
189+
final Object parentContext,
196190
final SSLContext sslContext, final boolean start) {
197191
return createHttpServer(uri,
198-
new JdkHttpHandlerContainer(configuration, parentLocator),
192+
new JdkHttpHandlerContainer(configuration, parentContext),
199193
sslContext,
200194
start
201195
);

containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/ServletProperties.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -41,8 +41,6 @@
4141

4242
import org.glassfish.jersey.internal.util.PropertiesClass;
4343

44-
import org.glassfish.hk2.api.ServiceLocator;
45-
4644
/**
4745
* Jersey servlet container configuration properties.
4846
*
@@ -164,7 +162,7 @@ public final class ServletProperties {
164162
public static final String QUERY_PARAMS_AS_FORM_PARAMS_DISABLED = "jersey.config.servlet.form.queryParams.disabled";
165163

166164
/**
167-
* Identifies the object that will be used as a parent {@link ServiceLocator} in the Jersey
165+
* Identifies the object that will be used as a parent {@code HK2 ServiceLocator} in the Jersey
168166
* {@link WebComponent}.
169167
* <p></p>
170168
* This property gives a possibility to use HK2 services that are registered and/or created

containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/WebComponent.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@
111111
import org.glassfish.jersey.servlet.spi.FilterUrlMappingsProvider;
112112
import org.glassfish.jersey.uri.UriComponent;
113113

114-
import org.glassfish.hk2.api.ServiceLocator;
115-
116114
/**
117115
* An common Jersey web component that may be extended by a Servlet and/or
118116
* Filter implementation, or encapsulated by a Servlet or Filter implementation.
@@ -331,7 +329,7 @@ public WebComponent(final WebConfig webConfig, ResourceConfig resourceConfig) th
331329
final AbstractBinder webComponentBinder = new WebComponentBinder(resourceConfig.getProperties());
332330
resourceConfig.register(webComponentBinder);
333331

334-
final ServiceLocator locator = (ServiceLocator) webConfig.getServletContext()
332+
final Object locator = webConfig.getServletContext()
335333
.getAttribute(ServletProperties.SERVICE_LOCATOR);
336334

337335
this.appHandler = new ApplicationHandler(resourceConfig, webComponentBinder, locator);

containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@
8080
import org.glassfish.jersey.server.spi.Container;
8181
import org.glassfish.jersey.server.spi.ContainerResponseWriter;
8282

83-
import org.glassfish.hk2.api.ServiceLocator;
84-
8583
import org.eclipse.jetty.continuation.Continuation;
8684
import org.eclipse.jetty.continuation.ContinuationListener;
8785
import org.eclipse.jetty.continuation.ContinuationSupport;
@@ -455,11 +453,11 @@ public void doStop() throws Exception {
455453
/**
456454
* Create a new Jetty HTTP container.
457455
*
458-
* @param application JAX-RS / Jersey application to be deployed on Jetty HTTP container.
459-
* @param parentLocator parent injection manager.
456+
* @param application JAX-RS / Jersey application to be deployed on Jetty HTTP container.
457+
* @param parentContext DI provider specific context with application's registered bindings.
460458
*/
461-
JettyHttpContainer(final Application application, final ServiceLocator parentLocator) {
462-
this.appHandler = new ApplicationHandler(application, new JettyBinder(), parentLocator);
459+
JettyHttpContainer(final Application application, final Object parentContext) {
460+
this.appHandler = new ApplicationHandler(application, new JettyBinder(), parentContext);
463461
}
464462

465463
/**

containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainerFactory.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2016 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -51,8 +51,6 @@
5151
import org.glassfish.jersey.server.ResourceConfig;
5252
import org.glassfish.jersey.server.spi.Container;
5353

54-
import org.glassfish.hk2.api.ServiceLocator;
55-
5654
import org.eclipse.jetty.server.Connector;
5755
import org.eclipse.jetty.server.HttpConfiguration;
5856
import org.eclipse.jetty.server.HttpConnectionFactory;
@@ -173,21 +171,19 @@ public static Server createServer(final URI uri, final ResourceConfig configurat
173171
* are ignored If the URI port is not present then port 143 will be
174172
* used. The URI path, query and fragment components are ignored.
175173
* @param config the resource configuration.
176-
* @param parentLocator {@link org.glassfish.hk2.api.ServiceLocator} to become a parent of the locator used by
177-
* {@link org.glassfish.jersey.server.ApplicationHandler}
174+
* @param parentContext DI provider specific context with application's registered bindings.
178175
* @param start if set to false, server will not get started, this allows end users to set
179176
* additional properties on the underlying listener.
180177
* @return newly created {@link Server}.
181178
*
182179
* @throws ProcessingException in case of any failure when creating a new Jetty {@code Server} instance.
183180
* @throws IllegalArgumentException if {@code uri} is {@code null}.
184181
* @see JettyHttpContainer
185-
* @see org.glassfish.hk2.api.ServiceLocator
186182
* @since 2.12
187183
*/
188184
public static Server createServer(final URI uri, final ResourceConfig config, final boolean start,
189-
final ServiceLocator parentLocator) {
190-
return createServer(uri, null, new JettyHttpContainer(config, parentLocator), start);
185+
final Object parentContext) {
186+
return createServer(uri, null, new JettyHttpContainer(config, parentContext), start);
191187
}
192188

193189

@@ -201,18 +197,16 @@ public static Server createServer(final URI uri, final ResourceConfig config, fi
201197
* are ignored If the URI port is not present then port 143 will be
202198
* used. The URI path, query and fragment components are ignored.
203199
* @param config the resource configuration.
204-
* @param parentLocator {@link org.glassfish.hk2.api.ServiceLocator} to become a parent of the locator used by
205-
* {@link org.glassfish.jersey.server.ApplicationHandler}
200+
* @param parentContext DI provider specific context with application's registered bindings.
206201
* @return newly created {@link Server}.
207202
*
208203
* @throws ProcessingException in case of any failure when creating a new Jetty {@code Server} instance.
209204
* @throws IllegalArgumentException if {@code uri} is {@code null}.
210205
* @see JettyHttpContainer
211-
* @see org.glassfish.hk2.api.ServiceLocator
212206
* @since 2.12
213207
*/
214-
public static Server createServer(final URI uri, final ResourceConfig config, final ServiceLocator parentLocator) {
215-
return createServer(uri, null, new JettyHttpContainer(config, parentLocator), true);
208+
public static Server createServer(final URI uri, final ResourceConfig config, final Object parentContext) {
209+
return createServer(uri, null, new JettyHttpContainer(config, parentContext), true);
216210
}
217211

218212
/**

containers/simple-http/src/main/java/org/glassfish/jersey/simple/SimpleContainer.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979
import org.glassfish.jersey.server.spi.ContainerResponseWriter;
8080
import org.glassfish.jersey.server.spi.ContainerResponseWriter.TimeoutHandler;
8181

82-
import org.glassfish.hk2.api.ServiceLocator;
83-
8482
import org.simpleframework.common.thread.DaemonFactory;
8583
import org.simpleframework.http.Address;
8684
import org.simpleframework.http.Request;
@@ -473,12 +471,11 @@ void onServerStop() {
473471
/**
474472
* Create a new Simple framework HTTP container.
475473
*
476-
* @param application JAX-RS / Jersey application to be deployed on Simple framework HTTP
477-
* container.
478-
* @param parentLocator parent HK2 injection manager.
474+
* @param application JAX-RS / Jersey application to be deployed on Simple framework HTTP container.
475+
* @param parentContext DI provider specific context with application's registered bindings.
479476
*/
480-
SimpleContainer(final Application application, final ServiceLocator parentLocator) {
481-
this.appHandler = new ApplicationHandler(application, new SimpleBinder(), parentLocator);
477+
SimpleContainer(final Application application, final Object parentContext) {
478+
this.appHandler = new ApplicationHandler(application, new SimpleBinder(), parentContext);
482479
this.scheduler = new ScheduledThreadPoolExecutor(2, new DaemonFactory(TimeoutDispatcher.class));
483480
}
484481

0 commit comments

Comments
 (0)