Skip to content

Commit

Permalink
Merge pull request #31 from neva-dev/sdk-fix
Browse files Browse the repository at this point in the history
SDK fix
  • Loading branch information
krystian-panek-vmltech authored Dec 15, 2023
2 parents d26c4b8 + 7f7ea7a commit af85b3e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 109 deletions.
23 changes: 1 addition & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>com.neva.felix</groupId>
<artifactId>search-webconsole-plugin</artifactId>
<packaging>bundle</packaging>
<version>2.0.0</version>
<version>2.0.1</version>
<name>search-webconsole-plugin</name>
<description>Search everywhere plugin for Apache Felix Web Console</description>
<inceptionYear>2017</inceptionYear>
Expand Down Expand Up @@ -64,27 +64,6 @@
</repository>
</distributionManagement>

<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray-plugins</name>
<url>https://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>

<build>
<resources>
<resource>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ServiceRegistration> 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<AbstractPlugin> getPlugins(BundleContext bundleContext) {
return ImmutableSet.<AbstractPlugin>of(
return ImmutableSet.of(
new SearchPlugin(bundleContext)
);
}

private ImmutableSet<RestServlet> 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)
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,7 +32,7 @@ protected void renderContent(HttpServletRequest request, HttpServletResponse res
response.getWriter().write(content);
}

protected Dictionary<String, Object> createProps() {
public Dictionary<String, Object> getProps() {
final Dictionary<String, Object> props = new Hashtable<>();

props.put("felix.webconsole.label", getLabel());
Expand All @@ -42,10 +41,8 @@ protected Dictionary<String, Object> 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)) {
Expand All @@ -54,5 +51,4 @@ public URL getResource(final String path) {

return null;
}

}
Original file line number Diff line number Diff line change
@@ -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;

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

public Dictionary<String, Object> createProps() {
Dictionary<String, Object> 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());
}

}

0 comments on commit af85b3e

Please sign in to comment.