Commit b4be970d authored by Nicolas Tachker's avatar Nicolas Tachker
Browse files

JORAM-245: Add a REST API for the Joram MBeans.

parent 12d1043f
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>joram-tools-rest-jmx</artifactId>
<packaging>bundle</packaging>
<name>JORAM :: joram :: tools :: mqtt :: jmx</name>
<description>Builds the Joram REST JMX.</description>
<parent>
<groupId>org.ow2.joram</groupId>
<artifactId>joram-tools-rest</artifactId>
<version>5.12.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven.bundle.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Activator>org.objectweb.joram.tools.rest.jmx.Activator</Bundle-Activator>
<Import-Package>
fr.dyade.aaa.common,
javax.jms,
javax.naming,
org.objectweb.util.monolog,
org.objectweb.util.monolog.api,
org.eclipse.jetty.server</Import-Package>
<!-- TODO remove DynamicImport-Package -->
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.joram</groupId>
<artifactId>joram-mom-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2016 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package org.objectweb.joram.tools.rest.jmx;
import java.util.Dictionary;
import java.util.Hashtable;
import org.glassfish.jersey.servlet.ServletContainer;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpService;
import fr.dyade.aaa.common.Debug;
/**
*
*/
public class Activator implements BundleActivator {
public static Logger logger = Debug.getLogger(Activator.class.getName());
private BundleContext context = null;
private HttpService httpService;
public final String servletAlias = "/joram/jmx";
public void start(BundleContext bundleContext) throws Exception {
this.context = bundleContext;
ServiceReference<HttpService> reference = bundleContext.getServiceReference(HttpService.class);
httpService = bundleContext.getService(reference);
ClassLoader myClassLoader = getClass().getClassLoader();
ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(myClassLoader);
// initialize the jmx helper
JmxHelper.getInstance().init(bundleContext);
Dictionary<String, String> jerseyServletParams = new Hashtable<>();
jerseyServletParams.put("javax.ws.rs.Application", JmxJerseyApplication.class.getName());
if (logger.isLoggable(BasicLevel.INFO))
logger.log(BasicLevel.INFO, "start: REGISTERING SERVLETS " + servletAlias);
httpService.registerServlet(servletAlias, new ServletContainer(), jerseyServletParams, null);
} finally {
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
}
}
public void stop(BundleContext bundleContext) throws Exception {
if (httpService != null) {
if (logger.isLoggable(BasicLevel.INFO))
logger.log(BasicLevel.INFO, "stop: UNREGISTERING SERVLETS " + servletAlias);
httpService.unregister(servletAlias);
}
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2016 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package org.objectweb.joram.tools.rest.jmx;
import org.objectweb.util.monolog.api.Logger;
import org.osgi.framework.BundleContext;
import fr.dyade.aaa.common.Debug;
public class JmxHelper {
public static final String BUNDLE_REST_JMX_ROOT = "rest.jmx.root";
public static final String BUNDLE_REST_JMX_PASS = "rest.jmx.password";
public static Logger logger = Debug.getLogger(JmxHelper.class.getName());
private static JmxHelper helper = null;
private String restJmxRoot;
private String restJmxPass;
private JmxHelper() { }
static public JmxHelper getInstance() {
if (helper == null)
helper = new JmxHelper();
return helper;
}
/**
* @return the restJmxRoot
*/
public String getRestJmxRoot() {
return restJmxRoot;
}
/**
* @return the restJmxPass
*/
public String getRestJmxPass() {
return restJmxPass;
}
public boolean authenticationRequired() {
return restJmxRoot != null && !restJmxRoot.isEmpty() &&
restJmxPass != null && !restJmxPass.isEmpty();
}
public void init(BundleContext bundleContext) throws Exception {
restJmxRoot = bundleContext.getProperty(BUNDLE_REST_JMX_ROOT);
restJmxPass = bundleContext.getProperty(BUNDLE_REST_JMX_PASS);
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2016 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package org.objectweb.joram.tools.rest.jmx;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class JmxJerseyApplication extends Application {
static private Set<Class<?>> result = new HashSet<Class<?>>();
@Override
public Set<Class<?>> getClasses() {
result.add(JmxRestService.class);
return result;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment