Skip to content

Commit af85b3e

Browse files
Merge pull request #31 from neva-dev/sdk-fix
SDK fix
2 parents d26c4b8 + 7f7ea7a commit af85b3e

File tree

5 files changed

+47
-109
lines changed

5 files changed

+47
-109
lines changed

pom.xml

+1-22
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<groupId>com.neva.felix</groupId>
2424
<artifactId>search-webconsole-plugin</artifactId>
2525
<packaging>bundle</packaging>
26-
<version>2.0.0</version>
26+
<version>2.0.1</version>
2727
<name>search-webconsole-plugin</name>
2828
<description>Search everywhere plugin for Apache Felix Web Console</description>
2929
<inceptionYear>2017</inceptionYear>
@@ -64,27 +64,6 @@
6464
</repository>
6565
</distributionManagement>
6666

67-
<repositories>
68-
<repository>
69-
<snapshots>
70-
<enabled>false</enabled>
71-
</snapshots>
72-
<id>central</id>
73-
<name>bintray</name>
74-
<url>https://jcenter.bintray.com</url>
75-
</repository>
76-
</repositories>
77-
<pluginRepositories>
78-
<pluginRepository>
79-
<snapshots>
80-
<enabled>false</enabled>
81-
</snapshots>
82-
<id>central</id>
83-
<name>bintray-plugins</name>
84-
<url>https://jcenter.bintray.com</url>
85-
</pluginRepository>
86-
</pluginRepositories>
87-
8867
<build>
8968
<resources>
9069
<resource>
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,70 @@
11
package com.neva.felix.webconsole.plugins.search;
22

3+
import com.neva.felix.webconsole.plugins.search.core.SearchService;
34
import com.neva.felix.webconsole.plugins.search.plugin.AbstractPlugin;
45
import com.neva.felix.webconsole.plugins.search.plugin.SearchPlugin;
56
import com.google.common.collect.ImmutableSet;
7+
import com.neva.felix.webconsole.plugins.search.rest.*;
68
import org.osgi.framework.BundleActivator;
79
import org.osgi.framework.BundleContext;
10+
import org.osgi.framework.ServiceRegistration;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
813

14+
import javax.servlet.Servlet;
15+
import java.util.LinkedList;
16+
import java.util.List;
917
import java.util.Set;
1018

1119
public class SearchActivator implements BundleActivator {
1220

13-
private SearchHttpTracker httpTracker;
21+
private static final Logger LOG = LoggerFactory.getLogger(SearchActivator.class);
22+
23+
private final List<ServiceRegistration> services = new LinkedList<>();
1424

1525
@Override
1626
public void start(BundleContext bundleContext) throws Exception {
1727
for (AbstractPlugin plugin : getPlugins(bundleContext)) {
18-
plugin.register();
28+
ServiceRegistration service = bundleContext.registerService(Servlet.class.getName(), plugin, plugin.getProps());
29+
if (service != null) {
30+
services.add(service);
31+
} else {
32+
LOG.error("Cannot register plugin '{}' as OSGi service", plugin.getClass().getName());
33+
}
34+
}
35+
for (RestServlet servlet : getServlets(bundleContext)) {
36+
ServiceRegistration service = bundleContext.registerService(Servlet.class.getName(), servlet, servlet.createProps());
37+
if (service != null) {
38+
services.add(service);
39+
} else {
40+
LOG.error("Cannot register plugin servlet '{}' as OSGi service", servlet.getClass().getName());
41+
}
1942
}
20-
21-
httpTracker = new SearchHttpTracker(bundleContext);
22-
httpTracker.open();
2343
}
2444

2545
@Override
2646
public void stop(BundleContext bundleContext) throws Exception {
27-
httpTracker.close();
28-
httpTracker = null;
47+
for (ServiceRegistration service : services) {
48+
service.unregister();
49+
}
2950
}
3051

3152
private Set<AbstractPlugin> getPlugins(BundleContext bundleContext) {
32-
return ImmutableSet.<AbstractPlugin>of(
53+
return ImmutableSet.of(
3354
new SearchPlugin(bundleContext)
3455
);
3556
}
57+
58+
private ImmutableSet<RestServlet> getServlets(BundleContext context) {
59+
return ImmutableSet.of(
60+
new ByPhraseServlet(context),
61+
new BundleDownloadServlet(context),
62+
new BundleClassesServlet(context),
63+
new ClassDecompileServlet(context),
64+
new ClassSearchServlet(context),
65+
new SourceGenerateServlet(context),
66+
new FileDownloadServlet(context),
67+
new BundleAssembleServlet(context)
68+
);
69+
}
3670
}

src/main/java/com/neva/felix/webconsole/plugins/search/SearchHttpTracker.java

-65
This file was deleted.

src/main/java/com/neva/felix/webconsole/plugins/search/plugin/AbstractPlugin.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.apache.felix.webconsole.AbstractWebConsolePlugin;
66
import org.osgi.framework.BundleContext;
77

8-
import javax.servlet.Servlet;
98
import javax.servlet.ServletException;
109
import javax.servlet.http.HttpServletRequest;
1110
import javax.servlet.http.HttpServletResponse;
@@ -33,7 +32,7 @@ protected void renderContent(HttpServletRequest request, HttpServletResponse res
3332
response.getWriter().write(content);
3433
}
3534

36-
protected Dictionary<String, Object> createProps() {
35+
public Dictionary<String, Object> getProps() {
3736
final Dictionary<String, Object> props = new Hashtable<>();
3837

3938
props.put("felix.webconsole.label", getLabel());
@@ -42,10 +41,8 @@ protected Dictionary<String, Object> createProps() {
4241
return props;
4342
}
4443

45-
public void register() {
46-
bundleContext.registerService(Servlet.class.getName(), this, createProps());
47-
}
4844

45+
// do not remove it - https://felix.apache.org/documentation/subprojects/apache-felix-web-console/extending-the-apache-felix-web-console/providing-resources.html
4946
public URL getResource(final String path) {
5047
String prefix = "/" + getLabel() + "/";
5148
if (path.startsWith(prefix)) {
@@ -54,5 +51,4 @@ public URL getResource(final String path) {
5451

5552
return null;
5653
}
57-
5854
}

src/main/java/com/neva/felix/webconsole/plugins/search/rest/RestServlet.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.neva.felix.webconsole.plugins.search.rest;
22

3-
import com.neva.felix.webconsole.plugins.search.core.SearchPaths;
43
import com.neva.felix.webconsole.plugins.search.utils.TemplateRenderer;
54
import org.osgi.framework.BundleContext;
65

@@ -23,13 +22,8 @@ public RestServlet(BundleContext bundleContext) {
2322

2423
public Dictionary<String, Object> createProps() {
2524
Dictionary<String, Object> props = new Hashtable<>();
26-
props.put("alias", getAlias());
27-
25+
props.put("osgi.http.whiteboard.servlet.pattern", "/search/" + getAliasName());
26+
props.put("osgi.http.whiteboard.context.select", "(osgi.http.whiteboard.context.name=org.apache.felix.webconsole)");
2827
return props;
2928
}
30-
31-
public String getAlias() {
32-
return SearchPaths.from(bundleContext).pluginAlias(getAliasName());
33-
}
34-
3529
}

0 commit comments

Comments
 (0)