Skip to content

Package: HttpServiceImpl

HttpServiceImpl

nameinstructionbranchcomplexitylinemethod
HttpServiceImpl(Bundle, Logger)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
createDefaultHttpContext()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
registerFilter(Filter, String, Dictionary, HttpContext)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
registerResources(String, String, HttpContext)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
registerServlet(String, Servlet, Dictionary, HttpContext)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
unregister(String)
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%
unregisterFilter(Filter)
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 java.util.Dictionary;
20:
21: import org.glassfish.grizzly.osgi.httpservice.util.Logger;
22: import org.osgi.framework.Bundle;
23: import org.osgi.service.http.HttpContext;
24: import org.osgi.service.http.HttpService;
25: import org.osgi.service.http.NamespaceException;
26:
27: import jakarta.servlet.Filter;
28: import jakarta.servlet.Servlet;
29: import jakarta.servlet.ServletException;
30:
31: /**
32: * Grizzly OSGi HttpService implementation.
33: *
34: * @author Hubert Iwaniuk
35: * @since Jan 20, 2009
36: */
37: public class HttpServiceImpl implements HttpServiceExtension {
38:
39: private final Logger logger;
40: private final Bundle bundle;
41:
42: final OSGiMainHandler mainHttpHandler;
43:
44: // ------------------------------------------------------------ Constructors
45:
46: /**
47: * {@link HttpService} constructor.
48: *
49: * @param bundle {@link org.osgi.framework.Bundle} that got this instance of {@link org.osgi.service.http.HttpService}.
50: * @param logger {@link org.glassfish.grizzly.osgi.httpservice.util.Logger} utility to be used here.
51: */
52: public HttpServiceImpl(final Bundle bundle, final Logger logger) {
53: this.bundle = bundle;
54: this.logger = logger;
55: mainHttpHandler = new OSGiMainHandler(logger, bundle);
56: }
57:
58: // ------------------------------------------------ Methods from HttpService
59:
60: /**
61: * {@inheritDoc}
62: */
63: @Override
64: public HttpContext createDefaultHttpContext() {
65: return new HttpContextImpl(bundle);
66: }
67:
68: /**
69: * {@inheritDoc}
70: */
71: @Override
72: public void registerServlet(final String alias, final Servlet servlet, final Dictionary initparams, HttpContext httpContext)
73: throws ServletException, NamespaceException {
74:
75: logger.info("Registering servlet: " + servlet + ", under: " + alias + ", with: " + initparams + " and context: " + httpContext);
76:
77: mainHttpHandler.registerServletHandler(alias, servlet, initparams, httpContext, this);
78: }
79:
80: /**
81: * {@inheritDoc}
82: */
83: @Override
84: public void registerResources(final String alias, String prefix, HttpContext httpContext) throws NamespaceException {
85:
86: logger.info("Registering resource: alias: " + alias + ", prefix: " + prefix + " and context: " + httpContext);
87:
88: mainHttpHandler.registerResourceHandler(alias, httpContext, prefix, this);
89: }
90:
91: /**
92: * {@inheritDoc}
93: */
94: @Override
95: public void unregister(final String alias) {
96: logger.info("Unregistering alias: " + alias);
97: mainHttpHandler.unregisterAlias(alias);
98: }
99:
100: // --------------------------------------- Methods from HttpServiceExtension
101:
102: /**
103: * {@inheritDoc}
104: */
105: @Override
106: public void registerFilter(Filter filter, String urlPattern, Dictionary initParams, HttpContext context) throws ServletException {
107: logger.info("Registering servlet: " + filter + ", under url-pattern: " + urlPattern + ", with: " + initParams + " and context: " + context);
108: mainHttpHandler.registerFilter(filter, urlPattern, initParams, context, this);
109: }
110:
111: /**
112: * {@inheritDoc}
113: */
114: @Override
115: public void unregisterFilter(Filter filter) {
116: logger.info("Unregister filter: " + filter);
117: mainHttpHandler.unregisterFilter(filter);
118: }
119:
120: }