Plugin management
parent
a64a525111
commit
d6f6388f8e
|
@ -14,6 +14,8 @@ import net.openesb.standalone.env.Environment;
|
|||
import net.openesb.standalone.http.HttpServer;
|
||||
import net.openesb.standalone.http.handlers.AdminConsoleHandler;
|
||||
import net.openesb.standalone.http.handlers.SitePluginHandler;
|
||||
import net.openesb.standalone.plugins.PluginsService;
|
||||
import net.openesb.standalone.plugins.rest.PluginsApplication;
|
||||
import net.openesb.standalone.settings.Settings;
|
||||
import net.openesb.standalone.utils.I18NBundle;
|
||||
import org.glassfish.grizzly.http.server.HttpHandler;
|
||||
|
@ -30,9 +32,9 @@ import org.glassfish.jersey.server.ResourceConfig;
|
|||
* @author OpenESB Community
|
||||
*/
|
||||
public class EmbeddedHttpServer implements HttpServer {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(HttpServer.class.getPackage().getName());
|
||||
|
||||
private static final Logger LOG
|
||||
= Logger.getLogger(HttpServer.class.getPackage().getName());
|
||||
private static final String HTTP_LISTENER_NAME = "openesb-http-server";
|
||||
private static final String HTTP_PORT_PROPERTY = "http.port";
|
||||
private static final String HTTP_ENABLED_PROPERTY = "http.enabled";
|
||||
|
@ -40,21 +42,23 @@ public class EmbeddedHttpServer implements HttpServer {
|
|||
private static final int DEFAULT_HTTP_PORT = 4848;
|
||||
private static final boolean DEFAULT_HTTP_ENABLED = true;
|
||||
private org.glassfish.grizzly.http.server.HttpServer httpServer = null;
|
||||
|
||||
|
||||
private final Settings settings;
|
||||
private final Environment environment;
|
||||
private boolean enabled;
|
||||
|
||||
private final SecurityProvider securityProvider;
|
||||
|
||||
private final PluginsService pluginsService;
|
||||
|
||||
@Inject
|
||||
public EmbeddedHttpServer(Settings settings, Environment environment, SecurityProvider securityProvider) {
|
||||
public EmbeddedHttpServer(Settings settings, Environment environment, SecurityProvider securityProvider, PluginsService pluginsService) {
|
||||
this.settings = settings;
|
||||
this.environment = environment;
|
||||
this.securityProvider = securityProvider;
|
||||
this.pluginsService = pluginsService;
|
||||
this.init();
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
enabled = settings.getAsBoolean(HTTP_ENABLED_PROPERTY, DEFAULT_HTTP_ENABLED);
|
||||
|
||||
|
@ -71,10 +75,10 @@ public class EmbeddedHttpServer implements HttpServer {
|
|||
|
||||
AdminConsoleHandler consoleHandler = new AdminConsoleHandler();
|
||||
config.addHttpHandler(consoleHandler.getHandler(), consoleHandler.path());
|
||||
|
||||
|
||||
SitePluginHandler pluginHandler = new SitePluginHandler(environment);
|
||||
config.addHttpHandler(pluginHandler.getHandler(), pluginHandler.path());
|
||||
|
||||
|
||||
/*
|
||||
* OESE-46
|
||||
* https://openesb.atlassian.net/browse/OESE-46
|
||||
|
@ -87,15 +91,45 @@ public class EmbeddedHttpServer implements HttpServer {
|
|||
* to JAX-RS 2.
|
||||
*/
|
||||
RuntimeDelegate.setInstance(null);
|
||||
|
||||
ResourceConfig app = new OpenESBApplication();
|
||||
app.register(new SecurityBridgeProvider());
|
||||
|
||||
HttpHandler handler = ContainerFactory.createContainer(HttpHandler.class, app);
|
||||
config.addHttpHandler(handler, "/api");
|
||||
|
||||
addManagementHandler();
|
||||
// addPluginsHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void addManagementHandler() {
|
||||
ResourceConfig app = new OpenESBApplication();
|
||||
|
||||
app.register(new AbstractBinder() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(securityProvider).to(SecurityProvider.class);
|
||||
}
|
||||
});
|
||||
|
||||
addJerseyHandler(app, "/api");
|
||||
}
|
||||
|
||||
private void addPluginsHandler() {
|
||||
ResourceConfig app = new PluginsApplication();
|
||||
|
||||
app.register(new AbstractBinder() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(pluginsService).to(PluginsService.class);
|
||||
}
|
||||
});
|
||||
|
||||
addJerseyHandler(app, "/plugins");
|
||||
}
|
||||
|
||||
private void addJerseyHandler(ResourceConfig resourceConfig, String mapping) {
|
||||
HttpHandler handler = ContainerFactory.createContainer(HttpHandler.class, resourceConfig);
|
||||
httpServer.getServerConfiguration().addHttpHandler(handler, mapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws LifecycleException {
|
||||
if (enabled) {
|
||||
|
@ -134,8 +168,8 @@ public class EmbeddedHttpServer implements HttpServer {
|
|||
LocalStringKeys.HTTP_SERVER_PORT, port));
|
||||
}
|
||||
|
||||
final org.glassfish.grizzly.http.server.HttpServer server =
|
||||
new org.glassfish.grizzly.http.server.HttpServer();
|
||||
final org.glassfish.grizzly.http.server.HttpServer server
|
||||
= new org.glassfish.grizzly.http.server.HttpServer();
|
||||
final NetworkListener listener = new NetworkListener(HTTP_LISTENER_NAME,
|
||||
binding, port);
|
||||
|
||||
|
@ -160,18 +194,9 @@ public class EmbeddedHttpServer implements HttpServer {
|
|||
public void addRestHandler(Application application, String rootURI) {
|
||||
if (enabled) {
|
||||
final ServerConfiguration config = httpServer.getServerConfiguration();
|
||||
|
||||
|
||||
HttpHandler handler = ContainerFactory.createContainer(HttpHandler.class, application);
|
||||
config.addHttpHandler(handler, rootURI);
|
||||
}
|
||||
}
|
||||
|
||||
class SecurityBridgeProvider extends AbstractBinder {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(securityProvider).to(SecurityProvider.class);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,11 +34,13 @@ public class PluginsService {
|
|||
private final Settings settings;
|
||||
private final Environment environment;
|
||||
private final Set<Plugin> plugins;
|
||||
private Set<PluginInfo> pluginInfos;
|
||||
|
||||
public PluginsService(Settings settings, Environment environment) {
|
||||
this.settings = settings;
|
||||
this.environment = environment;
|
||||
|
||||
this.pluginInfos = new HashSet<PluginInfo>();
|
||||
// Load plugins in the classloader
|
||||
loadPluginsIntoClassLoader();
|
||||
this.plugins = loadPluginsFromClasspath();
|
||||
|
@ -117,7 +119,11 @@ public class PluginsService {
|
|||
String pluginVersion = pluginProps.getProperty("version", PluginInfo.VERSION_NOT_AVAILABLE);
|
||||
Plugin plugin = loadPlugin(pluginClassName, settings);
|
||||
|
||||
PluginInfo info = new PluginInfo(plugin.name(), plugin.description(), true, pluginVersion);
|
||||
|
||||
plugins.add(plugin);
|
||||
pluginInfos.add(info);
|
||||
|
||||
} catch (Throwable e) {
|
||||
LOGGER.log(Level.SEVERE, "Failed to load plugin from [" + pluginUrl + "]", e);
|
||||
} finally {
|
||||
|
@ -164,6 +170,10 @@ public class PluginsService {
|
|||
return plugins;
|
||||
}
|
||||
|
||||
public Set<PluginInfo> pluginInfos() {
|
||||
return pluginInfos;
|
||||
}
|
||||
|
||||
public Collection<Class<? extends Lifecycle>> services() {
|
||||
List<Class<? extends Lifecycle>> services = new ArrayList<Class<? extends Lifecycle>>();
|
||||
for (Plugin plugin : plugins) {
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package net.openesb.standalone.plugins.jackson;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.Version;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.module.SimpleSerializers;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import net.openesb.model.api.Statistic;
|
||||
import net.openesb.model.api.metric.Gauge;
|
||||
import net.openesb.standalone.plugins.Plugin;
|
||||
import net.openesb.standalone.plugins.PluginInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author David BRASSELY (brasseld at gmail.com)
|
||||
* @author OpenESB Community
|
||||
*/
|
||||
public class PluginsModule extends Module {
|
||||
static final Version VERSION = new Version(1, 0, 0, "", "net.open-esb.standalone", "plugins-module");
|
||||
|
||||
private static class PluginInfoSerializer extends StdSerializer<PluginInfo> {
|
||||
private PluginInfoSerializer() {
|
||||
super(PluginInfo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PluginInfo pluginInfo,
|
||||
JsonGenerator json,
|
||||
SerializerProvider provider) throws IOException {
|
||||
json.writeStartObject();
|
||||
try {
|
||||
json.writeObjectField("name", pluginInfo.name());
|
||||
json.writeObjectField("description", pluginInfo.description());
|
||||
json.writeObjectField("version", pluginInfo.version());
|
||||
// json.writeObjectField("site", pluginInfo.site());
|
||||
} catch (RuntimeException e) {
|
||||
json.writeObjectField("error", e.toString());
|
||||
}
|
||||
json.writeEndObject();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
return "plugins-module";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version version() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupModule(Module.SetupContext context) {
|
||||
context.addSerializers(new SimpleSerializers(Arrays.<JsonSerializer<?>>asList(
|
||||
new PluginInfoSerializer()
|
||||
)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package net.openesb.standalone.plugins.rest;
|
||||
|
||||
import org.glassfish.jersey.jackson.JacksonFeature;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author David BRASSELY (brasseld at gmail.com)
|
||||
* @author OpenESB Community
|
||||
*/
|
||||
public class PluginsApplication extends ResourceConfig {
|
||||
|
||||
public PluginsApplication() {
|
||||
super(
|
||||
PluginsResource.class,
|
||||
JacksonFeature.class
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package net.openesb.standalone.plugins.rest;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import net.openesb.standalone.plugins.PluginsService;
|
||||
import net.openesb.standalone.plugins.jackson.PluginsModule;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author David BRASSELY (brasseld at gmail.com)
|
||||
* @author OpenESB Community
|
||||
*/
|
||||
@Path("/")
|
||||
public class PluginsResource {
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper().registerModules(
|
||||
new PluginsModule());
|
||||
|
||||
@Inject
|
||||
private PluginsService pluginsService;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String pluginInfos() throws JsonProcessingException {
|
||||
return mapper.writeValueAsString(pluginsService.pluginInfos());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue