Skip to content

Package: HttpServiceFactory

HttpServiceFactory

nameinstructionbranchcomplexitylinemethod
HttpServiceFactory(HttpServer, Logger, Bundle)
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getService(Bundle, ServiceRegistration)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
stop()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
ungetService(Bundle, ServiceRegistration, Object)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.glassfish.grizzly.osgi.httpservice;
18:
19: import org.glassfish.grizzly.http.server.HttpServer;
20: import org.glassfish.grizzly.osgi.httpservice.util.Logger;
21: import org.osgi.framework.Bundle;
22: import org.osgi.framework.ServiceFactory;
23: import org.osgi.framework.ServiceRegistration;
24: import org.osgi.service.http.HttpService;
25:
26: /**
27: * Grizzly OSGi {@link HttpService} {@link ServiceFactory}.
28: *
29: * @author Hubert Iwaniuk
30: * @since Jan 20, 2009
31: */
32: public class HttpServiceFactory implements ServiceFactory {
33: private final Logger logger;
34: private final OSGiMainHandler mainHttpHandler;
35:
36: public HttpServiceFactory(HttpServer httpServer, Logger logger, Bundle bundle) {
37: this.logger = logger;
38: mainHttpHandler = new OSGiMainHandler(logger, bundle);
39: httpServer.getServerConfiguration().addHttpHandler(mainHttpHandler, "/");
40: }
41:
42: @Override
43: public HttpService getService(Bundle bundle, ServiceRegistration serviceRegistration) {
44: logger.info("Bundle: " + bundle + ", is getting HttpService with serviceRegistration: " + serviceRegistration);
45: return new HttpServiceImpl(bundle, logger);
46: }
47:
48: @Override
49: public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object httpServiceObj) {
50: logger.info("Bundle: " + bundle + ", is ungetting HttpService with serviceRegistration: " + serviceRegistration);
51: mainHttpHandler.uregisterAllLocal();
52: }
53:
54: /**
55: * Clean up.
56: */
57: public void stop() {
58: logger.info("Stoping main handler");
59: mainHttpHandler.unregisterAll();
60: }
61: }