temporarily remove ui.start bundle from distro again (#424)

* temporarily remove ui.start bundle from distro again
* correctly unregister services again
* also unset the handlerRef field

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer 2018-11-03 22:59:25 +01:00 committed by Martin van Wingerden
parent 38a2624df6
commit 24d32f877c
2 changed files with 14 additions and 4 deletions

View File

@ -19,12 +19,14 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.DefaultServlet;
import org.openhab.ui.dashboard.DashboardReady; import org.openhab.ui.dashboard.DashboardReady;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.SynchronousBundleListener; import org.osgi.framework.SynchronousBundleListener;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.ComponentException; import org.osgi.service.component.ComponentException;
@ -73,6 +75,7 @@ public class RootServlet extends DefaultServlet {
private DashboardReady dashboardStarted; private DashboardReady dashboardStarted;
private LifeCycleState lifecycleState = LifeCycleState.STARTING; private LifeCycleState lifecycleState = LifeCycleState.STARTING;
private ServiceRegistration handlerRef;
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
@ -126,11 +129,11 @@ public class RootServlet extends DefaultServlet {
staticContent.setHandler(handler); staticContent.setHandler(handler);
Dictionary props = new Hashtable(); Dictionary props = new Hashtable();
props.put("contextPath", STATIC_CONTENT_URL); props.put("contextPath", STATIC_CONTENT_URL);
context.getBundleContext().registerService(ContextHandler.class.getName(), staticContent, props); handlerRef = context.getBundleContext().registerService(Handler.class.getName(), staticContent, props);
// register servlet // register servlet
try { try {
httpService.registerServlet("/", this, new Properties(), httpService.createDefaultHttpContext()); httpService.registerServlet("/", this, new Properties(), null);
} catch (ServletException | NamespaceException e) { } catch (ServletException | NamespaceException e) {
logger.error("Failed registering root servlet!", e); logger.error("Failed registering root servlet!", e);
} }
@ -168,7 +171,13 @@ public class RootServlet extends DefaultServlet {
} }
@Deactivate @Deactivate
protected void deactivate() { protected void deactivate(ComponentContext context) {
httpService.unregister("/");
if (handlerRef != null) {
handlerRef.unregister();
handlerRef = null;
}
// reset, if this component is ever reused (should normally not be the case), it should be "starting" again. // reset, if this component is ever reused (should normally not be the case), it should be "starting" again.
lifecycleState = LifeCycleState.STARTING; lifecycleState = LifeCycleState.STARTING;
} }

View File

@ -33,7 +33,8 @@
<feature prerequisite="true">shell</feature> <feature prerequisite="true">shell</feature>
<feature prerequisite="true">wrapper</feature> <feature prerequisite="true">wrapper</feature>
<!-- This bundle needs to be started early as it registers the 404 and startup pages on Jetty --> <!-- This bundle needs to be started early as it registers the 404 and startup pages on Jetty -->
<bundle start-level="30">mvn:org.openhab.core/org.openhab.ui.start/${project.version}</bundle> <!-- It is temperarily disabled due to https://github.com/openhab/openhab-core/issues/422
<bundle start-level="30">mvn:org.openhab.core/org.openhab.ui.start/${project.version}</bundle> -->
<bundle start-level="90">mvn:org.openhab.core/org.openhab.core/${project.version}</bundle> <bundle start-level="90">mvn:org.openhab.core/org.openhab.core/${project.version}</bundle>
<bundle>mvn:org.openhab.core/org.openhab.core.karaf/${project.version}</bundle> <bundle>mvn:org.openhab.core/org.openhab.core.karaf/${project.version}</bundle>
<bundle>mvn:org.openhab.core/org.openhab.io.sound/${project.version}</bundle> <bundle>mvn:org.openhab.core/org.openhab.io.sound/${project.version}</bundle>