Java adapter


Install the latest version of the OpenFin Desktop Java Adapter.
We provide an OpenFin.Desktop namespace (import com.openfin.desktop.*;) that can be used to connect to the desktop:

final DesktopConnection desktopConnection = new DesktopConnection("Unique UUID");
final RuntimeConfiguration rcg = new RuntimeConfiguration();
final int timeout = 60;
desktopConnection.connect(rcg, new DesktopStateListener() { 
  // your implementation
}, timeout);

The DesktopStateListener will let you react to changes to your connection to the desktop

new DesktopStateListener() {
  public void onReady() {

  public void onClose(String error) {

  public void onError(String reason) {                    

  public void onMessage(String message) {

  public void onOutgoingMessage(String message) {


Inter-Application Bus

Firstly we need to get the instance of the OpenFin desktop connection created earlier.
In this example we want to pass a JSON object (we can also pass just a string) by importing e.g. import org.json.JSONObject;

If all you need is to Publish and Subscribe to messages hosted on the OpenFin desktop, then you can use the following code to dispatch a message on a topic which will be picked up by any Subscribers to the same topic.

JSONObject msg = new JSONObject();
msg.put("name", "Java Demo");
msg.put("text", "Message");

desktopConnection.getInterApplicationBus().publish("ATopic", msg);

To subscribe to messages from other applications you can do the following.

desktopConnection.getInterApplicationBus().subscribe("*", "ATopic", (String sourceUuid, String receivingTopic, Object payload) -> {
  try {
    JSONObject message = (JSONObject) payload;
    String name = message.getString("name");
    System.out.println("Name received: " +  name);
  } catch (Exception e) {
    System.out.println("Error: " +  e.getMessage());

Channel API

OpenFin’s Channel API allows you finer grained control over your messaging. With it we can create channels, and clients of those channels. Each channel can “register” a list of commands/actions that the channel provider will handle.

Firstly we need to get the instance of the OpenFin desktop connection created earlier.

Next, let's create a channel called “MyAppActions” and register a sayHello function.

desktopConnection.getChannel("MyAppActions").create(new AsyncCallback<ChannelProvider>() {
  public void onSuccess(ChannelProvider provider) {
    //provider created, register actions.
    provider.register("sayHello", new ChannelAction() {
      public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {          
        String name = payload.getString("name")
        JSONObject obj = new JSONObject();
        obj.put("message", "Hi " + name);
        return obj;

Then we can create a client of the channel we created above and call the sayHello function.

desktopConnection.getChannel("MyAppActions").connect(new AsyncCallback<ChannelClient>() {

  public void onSuccess(ChannelClient client) {
    //connected to provider, invoke action provided by the provider.
    JSONObject payload = new JSONObject();
    payload.put("name", "John");

    client.dispatch("sayHello", payload, new AckListener() {

      public void onSuccess(Ack ack) {"current value={}", 

        public void onError(Ack ack) {

Embedded View

Create a canvas and place it where the HTML5 application should be embedded.

embedCanvas = new java.awt.Canvas();
panel.add(embedCanvas, BorderLayout.CENTER);

Listen to the canvas resize event, and resize embedded HTML5 application accordingly.

embedCanvas.addComponentListener(new ComponentAdapter() {
  public void componentResized(ComponentEvent event) {
    Dimension newSize = event.getComponent().getSize();
    try {
      if (startupHtml5app != null) {
    } catch (Exception e) {

Launch and connect to OpenFin runtime

this.desktopConnection = new DesktopConnection(appUuid);
DesktopStateListener listener = new DesktopStateListener() {...};
RuntimeConfiguration configuration = new RuntimeConfiguration();

desktopConnection.connect(configuration, listener, 60);

Create HTML5 application

ApplicationOptions options = new ApplicationOptions(startupUuid, startupUuid, openfin_app_url);
WindowOptions mainWindowOptions = new WindowOptions();

DemoUtils.runApplication(options, this.desktopConnection, new AckListener() {...});

Embed HTML5 application into the canvas

startupHtml5app = Application.wrap(this.startupUuid, this.desktopConnection);
Window html5Wnd = startupHtml5app.getWindow();
long parentHWndId = Native.getComponentID(this.embedCanvas);

  this.embedCanvas.getWidth(), this.embedCanvas.getHeight(), 
  new AckListener() {...});


Notifications requires importing the following:

import com.openfin.desktop.notifications.*;
import com.openfin.desktop.notifications.NotificationOptions;

Add an event listener to respond to notification interactions. You will need to pass the desktop connection created earlier:

Notifications notifications = new Notifications(desktopConnection);

  ne ->{
    NotificationActionEvent actionEvent = (NotificationActionEvent) ne;
    NotificationActionResult actionResult = actionEvent.getResult();
    java.lang.System.out.println("actionResult: notificationId: " + 
      actionEvent.getNotificationOptions().getId() + 
      ", user clicked on btn: " + 

Once you have a listener set up you can create a notification:

NotificationOptions opt = new NotificationOptions("Notification from Java", 
  "Write once, run everywhere", "Category");

opt.setIndicator(new NotificationIndicator(NotificationIndicator.TYPE_SUCCESS));
ButtonOptions bo1 = new ButtonOptions("Button 1");
bo1.setOnClick(new NotificationActionResult(new JSONObject().put("btn", "btn1")));
ButtonOptions bo2 = new ButtonOptions("Button 2");
bo2.setOnClick(new NotificationActionResult(new JSONObject().put("btn", "btn2")));
opt.setButtons(bo1, bo2);


To see the different types of notifications we recommend using our notification generator tool which will let you easily experiment with the settings available.


Please include your licenseKey in RuntimeConfiguration.setLicenseKey when launching apps from the Java Adapter. If you are interested in an Enterprise license, please contact us for one.