I'm trying to setup a custom launcher to connect to an Apache ACE server, but I can't seem to find any documentation that covers the process. About the only thing I was able to find was that I apparently need to use the Apache ACE Agent, thanks to a thread here. Attempting to use the provided code, in that thread, does not seem to work, however. Upon starting up the launcher, it either doesn't even try to connect to the server, or returns an error that it's attempting to connect to the wrong port (the default rather than the port I tell it to) and cannot find the server.
I've also seen a few posts suggesting that the ace-launcher.jar file is what's used, but nothing about how to use it, and the documentation at the Apache wiki suggests it's a standalone file. Attempting to run it as they show here does not seem to work as it doesn't read the arguments for identification/discovery/etc. when used the way their example shows.
I still can't figure out how to connect to the Apache ACE server via a custom launcher. The Apache ACE server-allinone is fine for my server, but the target.jar doesn't allow me (at least that I've seen) to specify system packages to be exposed to the OSGi framework. Can anyone help me figure out how to setup my launcher to connect to an Apache Ace server?
import java.io.File;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public class Main {
public static void main(String[] args) throws BundleException {
File bundlesDir = new File(new File("").getAbsolutePath() + "/bundles/");
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
config.put(Constants.FRAMEWORK_STORAGE, bundlesDir.getAbsolutePath());
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.w3c.dom.html,..."); // Truncated for readability
Framework framework = frameworkFactory.newFramework(config);
framework.start();
BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<Bundle>();
for (File file : bundlesDir.listFiles()) {
if (file.getAbsolutePath().contains(".jar")) {
try {
installedBundles.add(context.installBundle(file.toURI().toURL().toString()));
} catch (MalformedURLException e) {
e.printStackTrace();
continue;
}
System.out.println(file.getName() + " installed.");
}
}
for (Bundle bundle : installedBundles) {
System.out.println("Starting: " + bundle.getSymbolicName());
bundle.start();
}
}
}
The output message I get when trying to run the agent launcher:
...\test>java -jar org.apache.ace.agent.launcher.felix.jar -v --agent Test --serverurl localhost:9000
Launching OSGi framework
- factory: org.apache.felix.framework.FrameworkFactory
- properties: {agent.logging.level=DEBUG, agent.identification.agentid=Test, verbose=true, agent.discovery.serverurls=localhost:9000}
- providers: [AgentBundleProvider, BundleDirBundleProvider]
- installing: file:/.../test/org.apache.ace.agent.launcher.felix.jar!/org.apache.ace.agent.jar
[DEBUG] 10:32:53 (controller) Config initialized: update: true, fixPkg: true, syncDelay: 5, syncInterval: 60, maxRetries: 1
[DEBUG] 10:32:53 (controller) Scheduling controller to run in 5 seconds...
Startup complete...[DEBUG] 10:32:58 (controller) Controller syncing...
[DEBUG] 10:32:58 (controller) Synchronizing feedback channels: [auditlog]
[WARNING] 10:32:59 (discovery) Blacklisting unavailable serverURL: http://localhost:8080
[WARNING] 10:32:59 (discovery) No valid server URL discovered?!
[WARNING] 10:32:59 (feedbackChannel(auditlog)) No identification or server URL present, cannot send feedback!
[DEBUG] 10:32:59 (controller) Feedback send succesfully for channel: auditlog
[DEBUG] 10:32:59 (controller) Checking for agent updates...
[DEBUG] 10:32:59 (discovery) Ignoring blacklisted serverURL: http://localhost:8080
[WARNING] 10:32:59 (discovery) No valid server URL discovered?!
[WARNING] 10:32:59 (controller) Sync received retry exception from server. Rescheduled in 10 seconds...
[DEBUG] 10:32:59 (controller) Scheduling controller to run in 10 seconds...
Let me try to explain. The "agent" is a bundle that can be deployed in any OSGi container to connect to an ACE server. If you checkout the sourcecode from SVN (or download the sourcecode from the latest release) you can find it in the org.apache.ace.agent project. That bundle can be configured via various system or framework properties.
To make it a bit more convenient for people to use that bundle, we created the org.apache.ace.agent.launcher project. We have two different flavours of that one (see the generated folder after building the workspace). The first is a launcher that embeds a Felix framework and that agent bundle. You can simply run it like this:
That will output its most important options. If you do not want to use Felix, you can use the other artifact, which allows you to launch any framework that is on the classpath. So say you have an Equinox framework in a file called equinox.jar, you can run it like this:
Again, that will output the same options.
Regarding your output, try:
The server URL you were using did not have any protocol as part of the URL!