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

Commit 4fd1481

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

File tree

16 files changed

+105
-138
lines changed

16 files changed

+105
-138
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: 11 additions & 16 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-2015 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
@@ -56,8 +56,6 @@
5656
import org.glassfish.jersey.server.ResourceConfig;
5757
import org.glassfish.jersey.server.spi.Container;
5858

59-
import org.glassfish.hk2.api.ServiceLocator;
60-
6159
import com.sun.net.httpserver.HttpContext;
6260
import com.sun.net.httpserver.HttpHandler;
6361
import com.sun.net.httpserver.HttpServer;
@@ -118,17 +116,15 @@ public static HttpServer createHttpServer(final URI uri, final ResourceConfig co
118116
*
119117
* @param uri the {@link URI uri} on which the Jersey application will be deployed.
120118
* @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}
119+
* @param parentContext DI provider specific context with application's registered bindings.
123120
* @return Newly created {@link HttpServer}.
124121
* @throws ProcessingException thrown when problems during server creation occurs.
125122
* @see org.glassfish.jersey.jdkhttp.JdkHttpHandlerContainer
126-
* @see org.glassfish.hk2.api.ServiceLocator
127123
* @since 2.12
128124
*/
129125
public static HttpServer createHttpServer(final URI uri, final ResourceConfig configuration,
130-
final ServiceLocator parentLocator) {
131-
return createHttpServer(uri, new JdkHttpHandlerContainer(configuration, parentLocator), true);
126+
final Object parentContext) {
127+
return createHttpServer(uri, new JdkHttpHandlerContainer(configuration, parentContext), true);
132128
}
133129

134130
/**
@@ -181,21 +177,20 @@ public static HttpServer createHttpServer(final URI uri, final ResourceConfig co
181177
* The {@code start} flag controls whether or not the returned {@link HttpServer JDK HttpServer} is started.
182178
* </p>
183179
*
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.
180+
* @param uri the {@link URI uri} on which the Jersey application will be deployed.
181+
* @param configuration the Jersey server-side application configuration.
182+
* @param parentContext DI provider specific context with application's registered bindings.
183+
* @param sslContext custom {@link SSLContext} to be passed to the server
184+
* @param start if set to {@code false}, the created server will not be automatically started.
190185
* @return Newly created {@link HttpServer}.
191186
* @throws ProcessingException thrown when problems during server creation occurs.
192187
* @since 2.18
193188
*/
194189
public static HttpServer createHttpServer(final URI uri, final ResourceConfig configuration,
195-
final ServiceLocator parentLocator,
190+
final Object parentContext,
196191
final SSLContext sslContext, final boolean start) {
197192
return createHttpServer(uri,
198-
new JdkHttpHandlerContainer(configuration, parentLocator),
193+
new JdkHttpHandlerContainer(configuration, parentContext),
199194
sslContext,
200195
start
201196
);

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
@@ -110,8 +110,6 @@
110110
import org.glassfish.jersey.servlet.spi.FilterUrlMappingsProvider;
111111
import org.glassfish.jersey.uri.UriComponent;
112112

113-
import org.glassfish.hk2.api.ServiceLocator;
114-
115113
import jersey.repackaged.com.google.common.base.Predicate;
116114
import jersey.repackaged.com.google.common.collect.Collections2;
117115

@@ -333,7 +331,7 @@ public WebComponent(final WebConfig webConfig, ResourceConfig resourceConfig) th
333331
final AbstractBinder webComponentBinder = new WebComponentBinder(resourceConfig.getProperties());
334332
resourceConfig.register(webComponentBinder);
335333

336-
final ServiceLocator locator = (ServiceLocator) webConfig.getServletContext()
334+
final Object locator = webConfig.getServletContext()
337335
.getAttribute(ServletProperties.SERVICE_LOCATOR);
338336

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

192188

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

217211
/**

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)