Sidebar Example


This example will build a simple Java client to communicate with the CALO Sidebar via XML-RPC. The source code for this example is available in the distribution under the example directory.

Web Server Setup

First, we need to setup an embedded web server and configure it to handle return communication from the sidebar. This is done using the Apache XML-RPC WebServer class.

	import org.apache.xmlrpc.webserver.WebServer;

	private static final int CLIENT_PORT = 11490;

	// Setup client webserver
	WebServer webServer = new WebServer(CLIENT_PORT);
	XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();

By default, the client should listen on port 11490. After we have created the webserver, we get a reference to the XML-RPC server and configure the handler mapping.

	// Setup property handler mapping
	PropertyHandlerMapping phm = new PropertyHandlerMapping();
	phm.addHandler("INotificationProxy", NotificationProxyImpl.class);

Note that the PropertyHandlerMapping class maps the XML-RPC interface name to the implementing class. You may want to specify additional handler mappings if you are using additional sidebar plug-ins. Next, we specify some configuration settings for the XML-RPC server and start the web server.

	// Set webserver config
	XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
	// Start webserver

Sending Notifications

After the webserver is running, we can send a notification to the sidebar. The first step is to create an XML-RPC client object and configure the prefix endpoint. Note that by default, the sidebar will be running on localhost at port 11489.

	// Send notification
	private static final String SIDEBAR_PREFIX = "";

	XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
	config.setServerURL(new URL(SIDEBAR_PREFIX));
	XmlRpcClient client = new XmlRpcClient();

Next, we will set all of the notification parameters and execute the AddNotification method.

	private static final int NOTIFY_TEXT_TYPE = 2;
	private static final  int SIDEBAR_MODALITY = 0;

	int type = NOTIFY_TEXT_TYPE;
	String id = Long.toString(System.currentTimeMillis());
	String message = "This is a test notification";
	String summary = "Test notification";
	String uri = "";
	Vector modalities = new Vector();
	boolean persistent = true;
	Object[] params = new Object[] {type, id, message, summary, uri, modalities, persistent};
	client.execute("ISidebarNotification.AddNotification", params);

When the notification is received by the sidebar, it will look like this: