diff --git a/pom.xml b/pom.xml
index ec5de92..4f70b18 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
com.neva.felix
search-webconsole-plugin
bundle
- 2.0.0
+ 2.0.1
search-webconsole-plugin
Search everywhere plugin for Apache Felix Web Console
2017
@@ -64,27 +64,6 @@
-
-
-
- false
-
- central
- bintray
- https://jcenter.bintray.com
-
-
-
-
-
- false
-
- central
- bintray-plugins
- https://jcenter.bintray.com
-
-
-
diff --git a/src/main/java/com/neva/felix/webconsole/plugins/search/SearchActivator.java b/src/main/java/com/neva/felix/webconsole/plugins/search/SearchActivator.java
index 080f033..3426324 100644
--- a/src/main/java/com/neva/felix/webconsole/plugins/search/SearchActivator.java
+++ b/src/main/java/com/neva/felix/webconsole/plugins/search/SearchActivator.java
@@ -1,36 +1,70 @@
package com.neva.felix.webconsole.plugins.search;
+import com.neva.felix.webconsole.plugins.search.core.SearchService;
import com.neva.felix.webconsole.plugins.search.plugin.AbstractPlugin;
import com.neva.felix.webconsole.plugins.search.plugin.SearchPlugin;
import com.google.common.collect.ImmutableSet;
+import com.neva.felix.webconsole.plugins.search.rest.*;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.servlet.Servlet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Set;
public class SearchActivator implements BundleActivator {
- private SearchHttpTracker httpTracker;
+ private static final Logger LOG = LoggerFactory.getLogger(SearchActivator.class);
+
+ private final List services = new LinkedList<>();
@Override
public void start(BundleContext bundleContext) throws Exception {
for (AbstractPlugin plugin : getPlugins(bundleContext)) {
- plugin.register();
+ ServiceRegistration service = bundleContext.registerService(Servlet.class.getName(), plugin, plugin.getProps());
+ if (service != null) {
+ services.add(service);
+ } else {
+ LOG.error("Cannot register plugin '{}' as OSGi service", plugin.getClass().getName());
+ }
+ }
+ for (RestServlet servlet : getServlets(bundleContext)) {
+ ServiceRegistration service = bundleContext.registerService(Servlet.class.getName(), servlet, servlet.createProps());
+ if (service != null) {
+ services.add(service);
+ } else {
+ LOG.error("Cannot register plugin servlet '{}' as OSGi service", servlet.getClass().getName());
+ }
}
-
- httpTracker = new SearchHttpTracker(bundleContext);
- httpTracker.open();
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
- httpTracker.close();
- httpTracker = null;
+ for (ServiceRegistration service : services) {
+ service.unregister();
+ }
}
private Set getPlugins(BundleContext bundleContext) {
- return ImmutableSet.of(
+ return ImmutableSet.of(
new SearchPlugin(bundleContext)
);
}
+
+ private ImmutableSet getServlets(BundleContext context) {
+ return ImmutableSet.of(
+ new ByPhraseServlet(context),
+ new BundleDownloadServlet(context),
+ new BundleClassesServlet(context),
+ new ClassDecompileServlet(context),
+ new ClassSearchServlet(context),
+ new SourceGenerateServlet(context),
+ new FileDownloadServlet(context),
+ new BundleAssembleServlet(context)
+ );
+ }
}
diff --git a/src/main/java/com/neva/felix/webconsole/plugins/search/SearchHttpTracker.java b/src/main/java/com/neva/felix/webconsole/plugins/search/SearchHttpTracker.java
deleted file mode 100644
index 88937c5..0000000
--- a/src/main/java/com/neva/felix/webconsole/plugins/search/SearchHttpTracker.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.neva.felix.webconsole.plugins.search;
-
-import com.neva.felix.webconsole.plugins.search.rest.*;
-import com.google.common.collect.ImmutableSet;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.http.HttpService;
-import org.osgi.service.http.NamespaceException;
-import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.ServletException;
-import java.util.Set;
-
-public class SearchHttpTracker extends ServiceTracker {
-
- private static final Logger LOG = LoggerFactory.getLogger(SearchHttpTracker.class);
-
- private final Set restServlets;
-
- public SearchHttpTracker(BundleContext context) {
- super(context, HttpService.class.getName(), null);
- this.restServlets = createRestServlets();
- }
-
- @Override
- public Object addingService(ServiceReference reference) {
- HttpService httpService = (HttpService) super.addingService(reference);
- if (httpService == null)
- return null;
-
- try {
- for (RestServlet restServlet : restServlets) {
- httpService.registerServlet(restServlet.getAlias(), restServlet, restServlet.createProps(), null);
- }
- } catch (NamespaceException | ServletException e) {
- LOG.error("Cannot register REST servlet for search webconsole plugin.", e);
- }
-
- return httpService;
- }
-
- public void removedService(ServiceReference reference, Object service) {
- HttpService httpService = (HttpService) service;
- for (RestServlet restServlet : restServlets) {
- httpService.unregister(restServlet.getAlias());
- }
-
- super.removedService(reference, service);
- }
-
- private ImmutableSet createRestServlets() {
- return ImmutableSet.of(
- new ByPhraseServlet(context),
- new BundleDownloadServlet(context),
- new BundleClassesServlet(context),
- new ClassDecompileServlet(context),
- new ClassSearchServlet(context),
- new SourceGenerateServlet(context),
- new FileDownloadServlet(context),
- new BundleAssembleServlet(context)
- );
- }
-}
diff --git a/src/main/java/com/neva/felix/webconsole/plugins/search/plugin/AbstractPlugin.java b/src/main/java/com/neva/felix/webconsole/plugins/search/plugin/AbstractPlugin.java
index d844c26..d973273 100644
--- a/src/main/java/com/neva/felix/webconsole/plugins/search/plugin/AbstractPlugin.java
+++ b/src/main/java/com/neva/felix/webconsole/plugins/search/plugin/AbstractPlugin.java
@@ -5,7 +5,6 @@
import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.osgi.framework.BundleContext;
-import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -33,7 +32,7 @@ protected void renderContent(HttpServletRequest request, HttpServletResponse res
response.getWriter().write(content);
}
- protected Dictionary createProps() {
+ public Dictionary getProps() {
final Dictionary props = new Hashtable<>();
props.put("felix.webconsole.label", getLabel());
@@ -42,10 +41,8 @@ protected Dictionary createProps() {
return props;
}
- public void register() {
- bundleContext.registerService(Servlet.class.getName(), this, createProps());
- }
+ // do not remove it - https://felix.apache.org/documentation/subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/providing-resources.html
public URL getResource(final String path) {
String prefix = "/" + getLabel() + "/";
if (path.startsWith(prefix)) {
@@ -54,5 +51,4 @@ public URL getResource(final String path) {
return null;
}
-
}
diff --git a/src/main/java/com/neva/felix/webconsole/plugins/search/rest/RestServlet.java b/src/main/java/com/neva/felix/webconsole/plugins/search/rest/RestServlet.java
index b0b69b9..e4da397 100644
--- a/src/main/java/com/neva/felix/webconsole/plugins/search/rest/RestServlet.java
+++ b/src/main/java/com/neva/felix/webconsole/plugins/search/rest/RestServlet.java
@@ -1,6 +1,5 @@
package com.neva.felix.webconsole.plugins.search.rest;
-import com.neva.felix.webconsole.plugins.search.core.SearchPaths;
import com.neva.felix.webconsole.plugins.search.utils.TemplateRenderer;
import org.osgi.framework.BundleContext;
@@ -23,13 +22,8 @@ public RestServlet(BundleContext bundleContext) {
public Dictionary createProps() {
Dictionary props = new Hashtable<>();
- props.put("alias", getAlias());
-
+ props.put("osgi.http.whiteboard.servlet.pattern", "/search/" + getAliasName());
+ props.put("osgi.http.whiteboard.context.select", "(osgi.http.whiteboard.context.name=org.apache.felix.webconsole)");
return props;
}
-
- public String getAlias() {
- return SearchPaths.from(bundleContext).pluginAlias(getAliasName());
- }
-
}