diff --git a/pom.xml b/pom.xml
index 4bc670b..d5e3e4c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
co.openfin
openfin-desktop-java-example
- 7.1.1
+ 9.0.1
jar
openfin-desktop-java-example
@@ -58,12 +58,7 @@
co.openfin
openfin-desktop-java-adapter
- 8.0.11-SNAPSHOT
-
-
- co.openfin
- openfin-snap-dock
- 1.0.0.1
+ 9.2.0
tablelayout
diff --git a/release/channel.bat b/release/channel.bat
index ee13c74..492c1d2 100644
--- a/release/channel.bat
+++ b/release/channel.bat
@@ -5,5 +5,5 @@ REM usage: channel.bat [ provider | client ]
set mode=%1
IF "%~1" == "" set mode=provider
echo Channel type set to: %mode%
-java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.ChannelExample %mode%
+java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.ChannelExample %mode%
diff --git a/release/docking.bat b/release/docking.bat
deleted file mode 100644
index 6d6bec8..0000000
--- a/release/docking.bat
+++ /dev/null
@@ -1,7 +0,0 @@
-REM batch to run Docking example of OpenFin and Java windows with Layout service.
-REM layout.html is a simple example of OpenFin window that uses Layout service.
-REM For this example to work, layout.html needs to be hosted by a web server and its URL needs to be configured with -Dcom.openfin.demo.layout.url
-
-cd /D "%~dp0"
-gi
-java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.layout.url=http://localhost:8008/layout.html com.openfin.desktop.demo.LayoutServiceDemo
diff --git a/release/embed.bat b/release/embed.bat
index 8fae182..6533229 100644
--- a/release/embed.bat
+++ b/release/embed.bat
@@ -2,4 +2,4 @@
set url=%1
IF "%~1" == "" set url=https://openfin.co
echo Embedded url set to: %url%
-java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.embed.URL=%URL% -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.WindowEmbedDemo
+java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.embed.URL=%URL% -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.WindowEmbedDemo
diff --git a/release/fdc3.bat b/release/fdc3.bat
deleted file mode 100644
index 17628cc..0000000
--- a/release/fdc3.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.FDC3Example
-
diff --git a/release/junit.bat b/release/junit.bat
index a63ad3a..b79d81f 100644
--- a/release/junit.bat
+++ b/release/junit.bat
@@ -6,4 +6,4 @@ set RuntimeVersion="stable"
set RuntimeVersion="%1"
)
-java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.test.runtime.version=%RuntimeVersion% org.junit.runner.JUnitCore com.openfin.desktop.AllTests
+java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.2.0.jar;lib/openfin-desktop-java-example-9.2.1-tests.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.test.runtime.version=%RuntimeVersion% org.junit.runner.JUnitCore com.openfin.desktop.AllTests
diff --git a/release/lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar b/release/lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar
deleted file mode 100644
index ddaa903..0000000
Binary files a/release/lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar and /dev/null differ
diff --git a/release/lib/openfin-desktop-java-adapter-8.0.8.jar b/release/lib/openfin-desktop-java-adapter-8.0.8.jar
deleted file mode 100644
index d50704b..0000000
Binary files a/release/lib/openfin-desktop-java-adapter-8.0.8.jar and /dev/null differ
diff --git a/release/lib/openfin-desktop-java-adapter-9.2.0.jar b/release/lib/openfin-desktop-java-adapter-9.2.0.jar
new file mode 100644
index 0000000..8e5fff9
Binary files /dev/null and b/release/lib/openfin-desktop-java-adapter-9.2.0.jar differ
diff --git a/release/lib/openfin-desktop-java-example-7.1.1-tests.jar b/release/lib/openfin-desktop-java-example-7.1.1-tests.jar
deleted file mode 100644
index 157b85e..0000000
Binary files a/release/lib/openfin-desktop-java-example-7.1.1-tests.jar and /dev/null differ
diff --git a/release/lib/openfin-desktop-java-example-7.1.1.jar b/release/lib/openfin-desktop-java-example-7.1.1.jar
deleted file mode 100644
index e3451d1..0000000
Binary files a/release/lib/openfin-desktop-java-example-7.1.1.jar and /dev/null differ
diff --git a/release/lib/openfin-desktop-java-example-9.0.1.jar b/release/lib/openfin-desktop-java-example-9.0.1.jar
new file mode 100644
index 0000000..e4c2bae
Binary files /dev/null and b/release/lib/openfin-desktop-java-example-9.0.1.jar differ
diff --git a/release/lib/openfin-desktop-java-example-9.2.1-tests.jar b/release/lib/openfin-desktop-java-example-9.2.1-tests.jar
new file mode 100644
index 0000000..2611d69
Binary files /dev/null and b/release/lib/openfin-desktop-java-example-9.2.1-tests.jar differ
diff --git a/release/lib/openfin-desktop-java-example-9.2.2.jar b/release/lib/openfin-desktop-java-example-9.2.2.jar
new file mode 100644
index 0000000..dea5aac
Binary files /dev/null and b/release/lib/openfin-desktop-java-example-9.2.2.jar differ
diff --git a/release/lib/openfin-snap-dock-1.0.0.1.jar b/release/lib/openfin-snap-dock-1.0.0.1.jar
deleted file mode 100644
index 89e1c0f..0000000
Binary files a/release/lib/openfin-snap-dock-1.0.0.1.jar and /dev/null differ
diff --git a/release/profile.bat b/release/profile.bat
new file mode 100644
index 0000000..9e1cf11
--- /dev/null
+++ b/release/profile.bat
@@ -0,0 +1,2 @@
+java -Xmx100m -Xms100m -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.2.3-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1-tests.jar;lib/openfin-desktop-java-example-9.2.2.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable -Dcom.openfin.demo.licenseKey=123456 com.openfin.desktop.demo.MemoryProfile
+
diff --git a/release/run.bat b/release/run.bat
index 1b04451..adb4460 100644
--- a/release/run.bat
+++ b/release/run.bat
@@ -1,2 +1,2 @@
-java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.OpenFinDesktopDemo
+java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1-tests.jar;lib/openfin-desktop-java-example-9.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable -Dcom.openfin.demo.licenseKey=123456 com.openfin.desktop.demo.OpenFinDesktopDemo
diff --git a/src/main/java/com/openfin/desktop/demo/ChannelExample.java b/src/main/java/com/openfin/desktop/demo/ChannelExample.java
index 3078a34..0eba6b6 100644
--- a/src/main/java/com/openfin/desktop/demo/ChannelExample.java
+++ b/src/main/java/com/openfin/desktop/demo/ChannelExample.java
@@ -47,52 +47,114 @@ public ChannelExample() {
* Create a provider that supports "getValue", "increment" and "incrementBy n" actions
*/
public void createChannelProvider() {
- desktopConnection.getChannel(CHANNEL_NAME).addChannelListener(new ChannelListener() {
- @Override
- public void onChannelConnect(ConnectionEvent connectionEvent) {
- logger.info(String.format("provider receives channel connect event from %s ", connectionEvent.getUuid()));
- }
- @Override
- public void onChannelDisconnect(ConnectionEvent connectionEvent) {
- logger.info(String.format("provider receives channel disconnect event from %s ", connectionEvent.getUuid()));
- }
- });
- desktopConnection.getChannel(CHANNEL_NAME).create(new AsyncCallback() {
- @Override
- public void onSuccess(ChannelProvider provider) {
- //provider created, register actions.
- AtomicInteger x = new AtomicInteger(0);
-
- provider.register("getValue", new ChannelAction() {
- @Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
- logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString()));
- JSONObject obj = new JSONObject();
- obj.put("value", x.get());
- return obj;
- }
- });
- provider.register("increment", new ChannelAction() {
- @Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
- logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString()));
- JSONObject obj = new JSONObject();
- obj.put("value", x.incrementAndGet());
- provider.publish("event", obj, null);
- return obj;
- }
- });
- provider.register("incrementBy", new ChannelAction() {
- @Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
- logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString()));
- int delta = payload.getInt("delta");
- JSONObject obj = new JSONObject();
- obj.put("value", x.addAndGet(delta));
- return obj;
+
+ // Create the channel provider.
+ desktopConnection.getChannel(CHANNEL_NAME).createAsync().thenAccept(provider -> {
+ provider.addProviderListener(new ChannelProviderListener() {
+
+ // Create the onChannelConnect event handler.
+ @Override
+ public void onClientConnect(ChannelClientConnectEvent connectionEvent) throws Exception {
+
+ // Add a line to the log file to identify the UUID of the caller.
+ logger.info(String.format("provider receives client connect event from %s ", connectionEvent.getUuid()));
+
+ // Extract the JSON payload.
+ JSONObject payload = (JSONObject) connectionEvent.getPayload();
+
+ // If the "name" element of the payload says the client is invalid, reject the request.
+ if (payload != null) {
+ String name = payload.optString("name");
+ if ("Invalid Client".equals(name)) {
+ throw new Exception("request rejected");
+ }
}
- });
- }
+ }
+
+ // Create the onChannelDisconnect event handler.
+ @Override
+ public void onClientDisconnect(ChannelClientConnectEvent connectionEvent) {
+
+ // Add a line to the log file identifying the UUID of the caller.
+ logger.info(String.format("provider receives channel disconnect event from %s ", connectionEvent.getUuid()));
+ }
+ });
+
+ // The provider was created. Now to register the actions.
+ // ------------------------------------------------------
+
+ // This variable is used as the "value" element for the getValue, increment, and incrementBy actions.
+ AtomicInteger localInteger = new AtomicInteger(0);
+
+ // Register the "getValue" action.
+ // This action will return the value of the localInteger variable.
+ provider.register("getValue", new ChannelAction() {
+
+ // This is the logic for the "getValue" action.
+ @Override
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
+
+ // Write a string to the logfile that shows the requested action and payload.
+ logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString()));
+
+ // Create a JSON object to return to the channel client.
+ JSONObject obj = new JSONObject();
+
+ // Set the "value" JSON element to the value of the localInteger variable.
+ obj.put("value", localInteger.get());
+
+ // Return the JSON object to the channel client.
+ return obj;
+ }
+ });
+
+ // Register the "increment" action.
+ // This action will increment the value of the localInteger variable by one.
+ provider.register("increment", new ChannelAction() {
+
+ // This is the logic for the "increment" action.
+ @Override
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
+
+ // Write a string to the logfile that identifies the action and payload.
+ logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString()));
+
+ // Create a JSON object to return to the channel client.
+ JSONObject obj = new JSONObject();
+
+ // Increment localInteger and set the "value" JSON element to the new value of localInteger.
+ obj.put("value", localInteger.incrementAndGet());
+ provider.publish("event", obj, null);
+
+ // Return the JSON object to the channel client.
+ return obj;
+ }
+ });
+
+ // Register the "incrementBy" action.
+ // This action will increment the value of the localInteger variable by a specified amount.
+ provider.register("incrementBy", new ChannelAction() {
+
+ // This is the logic for the "incrementBy" action.
+ @Override
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
+
+ // Write a string to the logfile that identifies the action and payload.
+ logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString()));
+
+ // Extract the increment amount (delta) from the payload JSON object.
+ int delta = ((JSONObject)payload).getInt("delta");
+
+ // Create a new JSON object to return to the channel client.
+ JSONObject obj = new JSONObject();
+
+ // Increase localInteger by the delta amount and set the "value" JSON element to the new value of localInteger.
+ obj.put("value", localInteger.addAndGet(delta));
+
+ // Return the new JSON object to the channel client.
+ return obj;
+ }
+ });
});
}
@@ -100,64 +162,68 @@ public JSONObject invoke(String action, JSONObject payload, JSONObject senderIde
* Create a channel client that invokes "getValue", "increment" and "incrementBy n" actions
*/
public void createChannelClient() {
- desktopConnection.getChannel(CHANNEL_NAME).connect(new AsyncCallback() {
- @Override
- public void onSuccess(ChannelClient client) {
- // register a channel event
- client.register("event", new ChannelAction() {
- @Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
- logger.info("channel event {}", action);
- return null;
- }
- });
-
- //connected to provider, invoke actions provided by the provider.
- //get current value
- client.dispatch("getValue", null, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- logger.info("current value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value"));
-
- //got current value, do increment
- client.dispatch("increment", null, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- logger.info("after invoking increment, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value"));
-
- //let's do increatmentBy 10
- JSONObject payload = new JSONObject();
- payload.put("delta", 10);
- client.dispatch("incrementBy", payload, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- logger.info("after invoking incrementBy, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value"));
-
- try {
- desktopConnection.disconnect();
- }
- catch (DesktopException e) {
- e.printStackTrace();
- }
- }
+ JSONObject payload = new JSONObject();
+ payload.put("name", "java example");
+ desktopConnection.getChannel(CHANNEL_NAME).connectAsync(false, payload).thenAccept(client -> {
+ client.addChannelListener(new ChannelListener() {
+ @Override
+ public void onChannelConnect(ConnectionEvent connectionEvent) {
+ }
+ @Override
+ public void onChannelDisconnect(ConnectionEvent connectionEvent) {
+ logger.info("channel disconnected {}", connectionEvent.getChannelId());
+ }
+ });
+ client.register("event", new ChannelAction() {
+ @Override
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
+ logger.info("channel event {}", action);
+ return null;
+ }
+ });
+
+ client.dispatch("getValue", null, new AckListener() {
+ @Override
+ public void onSuccess(Ack ack) {
+ logger.info("current value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value"));
+
+ //got current value, do increment
+ client.dispatch("increment", null, new AckListener() {
+ @Override
+ public void onSuccess(Ack ack) {
+ logger.info("after invoking increment, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value"));
- @Override
- public void onError(Ack ack) {
+ //let's do increatmentBy 10
+ JSONObject payload = new JSONObject();
+ payload.put("delta", 10);
+ client.dispatch("incrementBy", payload, new AckListener() {
+ @Override
+ public void onSuccess(Ack ack) {
+ logger.info("after invoking incrementBy, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value"));
+
+ try {
+ desktopConnection.disconnect();
+ } catch (DesktopException e) {
+ e.printStackTrace();
}
- });
- }
+ }
- @Override
- public void onError(Ack ack) {
- }
- });
- }
+ @Override
+ public void onError(Ack ack) {
+ }
+ });
+ }
- @Override
- public void onError(Ack ack) {
- }
- });
- }
+ @Override
+ public void onError(Ack ack) {
+ }
+ });
+ }
+
+ @Override
+ public void onError(Ack ack) {
+ }
+ });
});
}
@@ -207,4 +273,4 @@ public static void main(String[] args) {
java.lang.System.exit(0);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/openfin/desktop/demo/DockingDemo2.java b/src/main/java/com/openfin/desktop/demo/DockingDemo2.java
deleted file mode 100644
index cf6589c..0000000
--- a/src/main/java/com/openfin/desktop/demo/DockingDemo2.java
+++ /dev/null
@@ -1,289 +0,0 @@
-package com.openfin.desktop.demo;
-
-import com.openfin.desktop.*;
-import com.openfin.desktop.win32.ExternalWindowObserver;
-import info.clearthought.layout.TableLayout;
-import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-/**
- * This app works with OpenFinDockingDemo as another dockable Java window
- *
- * Created by wche on 3/9/2016.
- */
-public class DockingDemo2 extends JPanel implements ActionListener, WindowListener {
- private final static Logger logger = LoggerFactory.getLogger(DockingDemo2.class.getName());
-
- protected String javaParentAppUuid = "Java Parent App"; // Its value must match OpenFinDockingDemo. Please see OpenFinDockingDemo for comments
-
- protected String appUuid = "AnotherJavaDocking"; // UUID for desktopConnection
- protected String javaWindowName = "Another Java Dock Window";
-
- protected DesktopConnection desktopConnection;
- protected ExternalWindowObserver externalWindowObserver;
-
- private static JFrame jFrame;
- protected JButton undockButton;
- protected JTextField dockStatus; // show Ready to dock message
-
- public DockingDemo2() {
- try {
- this.desktopConnection = new DesktopConnection(appUuid);
- startOpenFinRuntime();
- } catch (DesktopException desktopError) {
- desktopError.printStackTrace();
- }
- setLayout(new BorderLayout());
- add(layoutCenterPanel(), BorderLayout.CENTER);
- add(layoutLeftPanel(), BorderLayout.WEST);
- setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
- }
-
- private JPanel layoutLeftPanel() {
- JPanel panel = new JPanel();
- double size[][] = {{410}, {120, 30, TableLayout.FILL}};
- panel.setLayout(new TableLayout(size));
- panel.add(layoutActionButtonPanel(), "0,0,0,0");
- panel.add(layoutDockStatus(), "0,1,0,1");
- return panel;
- }
-
- private JTextField layoutDockStatus() {
- this.dockStatus = new JTextField();
- return this.dockStatus;
- }
-
- private JPanel layoutActionButtonPanel() {
- JPanel buttonPanel = new JPanel();
- JPanel topPanel = new JPanel();
- double size[][] = {{10, 190, 20, 190, 10}, {25, 10, 25, 10}};
- topPanel.setLayout(new TableLayout(size));
- topPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), "Desktop"));
- undockButton = new JButton("Undock");
- undockButton.setActionCommand("undock-window");
- undockButton.setEnabled(false);
- topPanel.add(undockButton, "1,0,1,0");
- undockButton.addActionListener(this);
- buttonPanel.add(topPanel, "0,0");
- return buttonPanel;
- }
-
- private JPanel layoutCenterPanel() {
- JPanel panel = new JPanel();
- double size[][] = {{TableLayout.FILL}, {150, 150, TableLayout.FILL}};
- panel.setLayout(new TableLayout(size));
-
- return panel;
- }
-
- private void undockFromOtherWindows() {
- try {
- // send message to Docking Manager to undock me
- JSONObject msg = new JSONObject();
- msg.put("applicationUuid", javaParentAppUuid);
- msg.put("windowName", javaWindowName);
- desktopConnection.getInterApplicationBus().publish("undock-window", msg);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- undockButton.setEnabled(false);
- }
-
- private void startOpenFinRuntime() {
- try {
- DesktopStateListener listener = new DesktopStateListener() {
- @Override
- public void onReady() {
- onRuntimeReady();
- }
-
- @Override
- public void onClose(String error) {
- }
- @Override
- public void onError(String reason) {
- logger.error("Connection failed: " + reason);
- java.lang.System.exit(0);
- }
- @Override
- public void onMessage(String message) {
- }
- @Override
- public void onOutgoingMessage(String message) {
- }
- };
- desktopConnection.setAdditionalRuntimeArguments(" --v=1"); // enable additional logging from Runtime
-
- String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version");
- if (desktopVersion == null) {
- desktopVersion = "stable";
- }
- desktopConnection.connectToVersion(desktopVersion, listener, 60); // 5.44.10.26 has fix for cross-app docking, which is required for windowsInShameGroupMoveTogether
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void onRuntimeReady() {
- try {
- this.desktopConnection.getInterApplicationBus().subscribe("*", "window-docked", (uuid, topic, data) -> {
- JSONObject event = (JSONObject) data;
- String appUuid = event.getString("applicationUuid");
- String windowName = event.getString("windowName");
- if (javaParentAppUuid.equals(appUuid) && javaWindowName.equals(windowName)) {
- updateUndockButton(true);
- }
- });
- this.desktopConnection.getInterApplicationBus().subscribe("*", "window-undocked", (uuid, topic, data) -> {
- JSONObject event = (JSONObject) data;
- String appUuid = event.getString("applicationUuid");
- String windowName = event.getString("windowName");
- if (javaParentAppUuid.equals(appUuid) && javaWindowName.equals(windowName)) {
- updateUndockButton(false);
- }
- });
- registerJavaWindow();
- Application javaParentApp = Application.wrap(javaParentAppUuid, desktopConnection);
- javaParentApp.addEventListener("closed", actionEvent -> { shutdown(); }, null);
- } catch (Exception e) {
- logger.error("Error creating DockingManager", e);
- }
- }
-
- private void registerJavaWindow() {
- try {
- externalWindowObserver = new ExternalWindowObserver(desktopConnection.getPort(), javaParentAppUuid, javaWindowName, jFrame,
- new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- try {
- if (ack.isSuccessful()) {
- JSONObject request = new JSONObject();
- request.put("applicationUuid", javaParentAppUuid);
- request.put("windowName", javaWindowName);
- desktopConnection.getInterApplicationBus().publish("register-docking-window", request);
- }
- } catch (Exception ex) {
- logger.error("Error registering window", ex);
- }
- }
- @Override
- public void onError(Ack ack) {
- logger.error("Error registering java window ", ack.getReason());
- }
- });
- } catch (Exception e) {
- logger.error("Error registering external window", e);
- }
- }
-
- public void actionPerformed(java.awt.event.ActionEvent e) {
- if ("undock-window".equals(e.getActionCommand())) {
- undockFromOtherWindows();
- }
- }
- private void updateUndockButton(boolean enabled) {
- this.undockButton.setEnabled(enabled);
- if (enabled) {
- this.dockStatus.setText("Docked. Click Unlock button to undock");
- } else {
- this.dockStatus.setText("");
- }
- }
-
- private static void createAndShowGUI() {
- //Create and set up the window.
- jFrame = new JFrame("Another Java Docking Demo");
- jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- //Create and set up the content pane.
- DockingDemo2 newContentPane = new DockingDemo2();
- newContentPane.setOpaque(true); //content panes must be opaque
- jFrame.setContentPane(newContentPane);
- jFrame.addWindowListener(newContentPane);
-
- //Display the window.
- jFrame.pack();
- jFrame.setSize(470, 300);
- jFrame.setLocation(600, 400);
-// jFrame.setLocationRelativeTo(null);
- jFrame.setResizable(false);
- jFrame.setVisible(true);
- }
-
- private void shutdown() {
- logger.debug("shutting down");
- if (externalWindowObserver != null) {
- logger.debug("Closing");
- try {
- JSONObject request = new JSONObject();
- request.put("applicationUuid", javaParentAppUuid);
- request.put("windowName", javaWindowName);
- desktopConnection.getInterApplicationBus().publish("unregister-docking-window", request);
- Thread.sleep(2000); // give time to flush messages to Runtime
- externalWindowObserver.dispose();
- desktopConnection.disconnect();
- Thread.sleep(1000); // give time to flush messages to Runtime
- } catch (Exception ex) {
- logger.error("Error existing", ex);
- }
- }
- }
-
- /**
- *
- * @param args
- */
- public static void main(String[] args) {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
-
- @Override
- public void windowOpened(WindowEvent e) {
-
- }
-
- @Override
- public void windowClosing(WindowEvent e) {
- shutdown();
- }
-
- @Override
- public void windowClosed(WindowEvent e) {
-
- }
-
- @Override
- public void windowIconified(WindowEvent e) {
-
- }
-
- @Override
- public void windowDeiconified(WindowEvent e) {
-
- }
-
- @Override
- public void windowActivated(WindowEvent e) {
-
- }
-
- @Override
- public void windowDeactivated(WindowEvent e) {
-
- }
-}
-
-
diff --git a/src/main/java/com/openfin/desktop/demo/FDC3Example.java b/src/main/java/com/openfin/desktop/demo/FDC3Example.java
deleted file mode 100644
index 9f10972..0000000
--- a/src/main/java/com/openfin/desktop/demo/FDC3Example.java
+++ /dev/null
@@ -1,361 +0,0 @@
-package com.openfin.desktop.demo;
-
-import com.openfin.desktop.*;
-import com.openfin.desktop.fdc3.*;
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.IOException;
-import java.lang.System;
-import java.util.List;
-import java.util.UUID;
-
-public class FDC3Example implements DesktopStateListener {
-
- private final static String javaConnectUuid = "JavaFDC3Demo";
-
- private DesktopConnection desktopConnection;
- private JFrame mainWindow;
- private JButton btnLaunchRed;
- private JButton btnTickerToRed;
- private JButton btnFindIntent;
- private JButton btnFindContextIntent;
- private JButton btnBroadcast;
- private JButton btnJoinRed;
- private JButton btnIntentListener;
-
- private JTextArea output; // show output of API
- private String ticker = "AAPL";
-
- private FDC3Client fdc3Client;
-
- private JSONArray serviceConfig = new JSONArray();
-
- FDC3Example() {
- try {
- this.createMainWindow();
- this.launchOpenfin();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- void createMainWindow() {
- this.mainWindow = new JFrame("FDC3 Demo");
- this.mainWindow.setResizable(false);
- this.mainWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- this.mainWindow.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent we) {
- try {
-// application.close();
- Thread.sleep(1000);
- java.lang.System.exit(0);
- }
- catch (Exception de) {
- de.printStackTrace();
- }
- }
- });
-
- JPanel contentPnl = new JPanel(new BorderLayout(10, 10));
- contentPnl.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- JPanel pnl = new JPanel();
- pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
-
- this.btnLaunchRed = new JButton("Start Charts: Red");
- this.btnLaunchRed.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- startReds();
- }
- });
- this.btnLaunchRed.setEnabled(false);
- pnl.add(btnLaunchRed);
-
- this.btnTickerToRed = new JButton("Send ticker to Red");
- this.btnTickerToRed.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- sendTickerToReds();
- }
- });
- this.btnTickerToRed.setEnabled(false);
- pnl.add(btnTickerToRed);
-
- this.btnFindIntent = new JButton("Find intent of ViewChart");
- this.btnFindIntent.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- findIntent();
- }
- });
- this.btnFindIntent.setEnabled(false);
- pnl.add(btnFindIntent);
-
- this.btnFindContextIntent = new JButton("Find intent of fdc3.instrument context");
- this.btnFindContextIntent.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- findContextIntent();
- }
- });
- this.btnFindContextIntent.setEnabled(false);
- pnl.add(btnFindContextIntent);
-
- this.btnBroadcast = new JButton("Broadcast to default channel");
- this.btnBroadcast.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- broadcast();
- }
- });
- this.btnBroadcast.setEnabled(false);
- pnl.add(btnBroadcast);
-
- this.btnJoinRed = new JButton("Join Red channel");
- this.btnJoinRed.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- joinRed();
- }
- });
- this.btnJoinRed.setEnabled(false);
- pnl.add(btnJoinRed);
-
- this.btnIntentListener = new JButton("Register an intent listener");
- this.btnIntentListener.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- addIntentListener();
- }
- });
- this.btnIntentListener.setEnabled(false);
- pnl.add(btnIntentListener);
-
- pnl.add(layoutOutputPanel());
-
- contentPnl.add(pnl, BorderLayout.CENTER);
-
- this.mainWindow.getContentPane().add(contentPnl);
- this.mainWindow.setLocationRelativeTo(null);
- this.mainWindow.setSize(400, 400);
- this.mainWindow.setVisible(true);
- }
-
- protected JScrollPane layoutOutputPanel() {
- output = new JTextArea(100, 40);
- output.setEditable(false);
- output.setAutoscrolls(true);
- output.setLineWrap(true);
- output.setMinimumSize(new Dimension(40, 100));
- output.setPreferredSize(new Dimension(40, 100));
- JScrollPane statusPane = new JScrollPane(output);
- statusPane.setVerticalScrollBarPolicy(
- JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
- statusPane.setPreferredSize(new Dimension(500, 650));
- return statusPane;
- }
-
- void launchOpenfin() throws DesktopException, DesktopIOException, IOException, InterruptedException {
- RuntimeConfiguration config = new RuntimeConfiguration();
- config.setRuntimeVersion("alpha");
-// config.setRuntimeVersion("10.66.41.18");
- config.setAdditionalRuntimeArguments("--v=1 ");
-// serviceConfig = new JSONArray();
-// JSONObject layout = new JSONObject();
-// layout.put("name", "fdc3");
-// serviceConfig.put(0, layout);
-// config.addConfigurationItem("services", serviceConfig);
-
- this.desktopConnection = new DesktopConnection(javaConnectUuid);
- this.desktopConnection.connect(config, this, 60);
- }
-
- @Override
- public void onReady() {
- this.fdc3Client = FDC3Client.getInstance(this.desktopConnection);
- this.fdc3Client.connect(new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- btnLaunchRed.setEnabled(true);
- btnTickerToRed.setEnabled(true);
- btnFindIntent.setEnabled(true);
- btnFindContextIntent.setEnabled(true);
- btnBroadcast.setEnabled(true);
- btnJoinRed.setEnabled(true);
- btnIntentListener.setEnabled(true);
- addContextListener();
- output.setText(String.format("Connected to FDC3 service"));
- }
- @Override
- public void onError(Ack ack) {
- output.setText(String.format("Failed to Connect to FDC3 service"));
- }
- });
- }
-
- private void startReds() {
- fdc3Client.open("fdc3-charts-red", null, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- output.setText(String.format("FDC3 started %b", ack.isSuccessful()));
- }
- @Override
- public void onError(Ack ack) {
- output.setText(String.format("FDC3 started failed %s", ack.getReason()));
- }
- });
- }
-
- private void sendTickerToReds() {
- String ticker = getTicker();
- Context context = new Context("fdc3.instrument", ticker);
- JSONObject id = new JSONObject();
- id.put("ticker", ticker.toLowerCase());
- context.setId(id);
- fdc3Client.raiseIntent("ViewChart", context, "fdc3-charts-red", new AsyncCallback() {
- @Override
- public void onSuccess(IntentResolution result) {
- output.setText(String.format("IntentResolution source=%s, version=%s", result.getSource(), result.getVersion()));
- }
- });
- }
-
- private void findIntent() {
- fdc3Client.findIntent("ViewChart", null, new AsyncCallback() {
- @Override
- public void onSuccess(AppIntent result) {
- output.setText(result.toString());
-
- }
- });
- }
-
- private void findContextIntent() {
- String ticker = getTicker();
- Context context = new Context("fdc3.instrument", ticker);
-
- fdc3Client.findIntentsByContext(context, new AsyncCallback>() {
-
- @Override
- public void onSuccess(List result) {
- for (int i=0; i() {
- @Override
- public void onSuccess(Channel channel) {
- if (channel != null) {
- channel.join(new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- if (ack.isSuccessful()) {
- output.setText(String.format("Joined red channel"));
- } else {
- output.setText(String.format("Failed to join red channel %s", ack.getReason()));
- }
- }
- @Override
- public void onError(Ack ack) {
- output.setText(String.format("Failed to join red channel %s", ack.getReason()));
- }
- });
- }
- }
- });
- }
-
- private void addIntentListener() {
- fdc3Client.addIntentListener("ViewChartByJava", new IntentListener() {
- @Override
- public JSONObject onIntent(Context context) {
- output.setText(String.format("Received Intent: %s", context.toString()));
- context.put("comment", "Java rules");
- return context;
- }
- }, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- if (ack.isSuccessful()) {
- output.setText("Registered intent listener");
- } else {
- output.setText(String.format("Failed to register intent listener %s", ack.getReason()));
- }
- }
-
- @Override
- public void onError(Ack ack) {
- output.setText(String.format("Failed to register intent listener %s", ack.getReason()));
- }
- });
- }
-
- private void addContextListener() {
- fdc3Client.addContextListener(new ContextListener() {
- @Override
- public JSONObject onContext(Context result) {
- output.setText(String.format("Received context: %s", result.toString()));
- return null;
- }
- }, null);
- }
-
- private String getTicker() {
- this.ticker = this.ticker.equals("AAPL") ? "MSFT" : "AAPL";
- return this.ticker;
- }
-
- @Override
- public void onClose(String error) {
-
- }
-
- @Override
- public void onError(String reason) {
- }
-
- @Override
- public void onMessage(String message) {
- }
-
- @Override
- public void onOutgoingMessage(String message) {
- }
-
- public static void main(String[] args) {
- new FDC3Example();
- }
-
-}
diff --git a/src/main/java/com/openfin/desktop/demo/JNLPExample.java b/src/main/java/com/openfin/desktop/demo/JNLPExample.java
index ce8a612..646a244 100644
--- a/src/main/java/com/openfin/desktop/demo/JNLPExample.java
+++ b/src/main/java/com/openfin/desktop/demo/JNLPExample.java
@@ -63,7 +63,9 @@ public JNLPExample() throws DesktopException {
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
- desktopConnection.connectToVersion("stable", listener, 100000);
+ RuntimeConfiguration cfg = new RuntimeConfiguration();
+ cfg.setRuntimeVersion("stable");
+ desktopConnection.connect(cfg, listener, 30);
} catch (Exception ex) {
ex.printStackTrace();
}
diff --git a/src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java b/src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java
index 38161b1..32e7bee 100644
--- a/src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java
+++ b/src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java
@@ -184,7 +184,7 @@ public void onSuccess(ChannelClient client) {
client.register("event", new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
System.out.printf("channel event " + action);
return null;
}
diff --git a/src/main/java/com/openfin/desktop/demo/LauncherBusDemo.java b/src/main/java/com/openfin/desktop/demo/LauncherBusDemo.java
index fbbf36d..58d2cf3 100644
--- a/src/main/java/com/openfin/desktop/demo/LauncherBusDemo.java
+++ b/src/main/java/com/openfin/desktop/demo/LauncherBusDemo.java
@@ -9,8 +9,6 @@
import com.openfin.desktop.*;
import com.openfin.desktop.Window;
import com.openfin.desktop.channel.*;
-import com.openfin.desktop.channel.NotificationListener;
-import com.openfin.desktop.channel.NotificationOptions;
import com.openfin.desktop.win32.ExternalWindowObserver;
import com.sun.jna.Native;
import info.clearthought.layout.TableLayout;
@@ -30,10 +28,8 @@ public class LauncherBusDemo extends JFrame {
private DesktopConnection desktopConnection;
private InterApplicationBus interApplicationBus;
- private NotificationClient notificationClient;
private JButton btnOFApp1, btnOFApp2;
private JButton btnTabOFApp1;
- private JButton btnNotification, btnToggleNotification; // button to create notifications
private JButton btnUndock; // button to undock this Java window
private JButton btnOFSendApp1, btnOFSendApp2; // send messages to OpenFin app via Inter App Bus
private JButton btnGenerateWorkSpace, btnRestoreWorkSpace;
@@ -104,26 +100,6 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
}
});
- btnNotification = new JButton();
- btnNotification.setText("Notification");
- btnNotification.setEnabled(false);
- btnNotification.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent e) {
- createNotification();
- }
- });
-
- btnToggleNotification = new JButton();
- btnToggleNotification.setText("Toggle Notification CENTER");
- btnToggleNotification.setEnabled(false);
- btnToggleNotification.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent e) {
- toggleNotificationCenter();
- }
- });
-
btnGenerateWorkSpace = new JButton();
btnGenerateWorkSpace.setText("Generate WorkSpace");
btnGenerateWorkSpace.setEnabled(false);
@@ -157,8 +133,6 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
topPanel.add(btnOFApp2, "1,4,1,4");
topPanel.add(btnOFSendApp1, "1,6,1,6");
topPanel.add(btnOFSendApp2, "1,8,1,8");
- topPanel.add(btnNotification, "1,10,1,10");
- topPanel.add(btnToggleNotification, "1,12,1,12");
topPanel.add(btnGenerateWorkSpace, "1,14,1,14");
topPanel.add(btnRestoreWorkSpace, "1,16,1,16");
topPanel.add(btnUndock, "1,18,1,18");
@@ -242,7 +216,6 @@ public void onReady() {
configAppEventListener();
createEmbddedApp();
createLayoutClient();
- createNotificationClient();
}
@Override
@@ -468,47 +441,6 @@ public void onError(Ack ack) {
}
});
}
- private void createNotificationClient() {
- this.notificationClient = new NotificationClient(this.desktopConnection, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- btnNotification.setEnabled(true);
- btnToggleNotification.setEnabled(true);
- LauncherBusDemo.this.notificationClient.addNotificationListener(new NotificationListener() {
- @Override
- public void onClick(NotificationOptions options) {
- logger.info(String.format("Notification clicked %s", options.getId()));
- }
- @Override
- public void onButtonClick(NotificationOptions options) {
- logger.info(String.format("Notification button clicked %s button index %d", options.getId(),
- options.getButtonIndex()));
- }
- @Override
- public void onClose(NotificationOptions options) {
- logger.info(String.format("Notification closed %s", options.getId()));
- }
- });
- }
- @Override
- public void onError(Ack ack) {
-
- }
- });
- }
- private void createNotification() {
- NotificationOptions options = new NotificationOptions();
- options.setId(UUID.randomUUID().toString());
- options.setBody("Hello From Java app");
- options.setTitle("Java Demo");
- options.setIcon("https://openfin.co/favicon.ico");
- options.addButton(null, "button1");
- options.addButton(null, "button2");
- this.notificationClient.create(options, null);
- }
- private void toggleNotificationCenter() {
- this.notificationClient.toggleNotificationCenter(null);
- }
private void generateWorkSpace() {
this.layoutClient.generateWorkspace(new AsyncCallback() {
diff --git a/src/main/java/com/openfin/desktop/demo/LayoutFrame.java b/src/main/java/com/openfin/desktop/demo/LayoutFrame.java
index 1a0f096..93cc75f 100644
--- a/src/main/java/com/openfin/desktop/demo/LayoutFrame.java
+++ b/src/main/java/com/openfin/desktop/demo/LayoutFrame.java
@@ -130,7 +130,7 @@ public void actionPerformed(ActionEvent e) {
client.register("event", new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
System.out.printf("channel event " + action);
return null;
}
diff --git a/src/main/java/com/openfin/desktop/demo/MemoryProfile.java b/src/main/java/com/openfin/desktop/demo/MemoryProfile.java
new file mode 100644
index 0000000..0b22811
--- /dev/null
+++ b/src/main/java/com/openfin/desktop/demo/MemoryProfile.java
@@ -0,0 +1,96 @@
+package com.openfin.desktop.demo;
+
+import com.openfin.desktop.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+/**
+ * This class can be used to profile memory usage of Java Adapter for communicating with Runtime. The initial version
+ * just keeps calling getMachineId API. It can easily extended to test other APIs.
+ *
+ * VisualVM, available from https://visualvm.github.io/, can be used to monitor memory usgage while this code is running
+ */
+
+public class MemoryProfile {
+ private final static Logger logger = LoggerFactory.getLogger(MemoryProfile.class.getName());
+
+ public static void main(String[] args) {
+ RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration();
+ String connectionUuid = MemoryProfile.class.getName();
+ String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version");
+ if (desktopVersion == null) {
+ desktopVersion = "stable";
+ }
+ runtimeConfiguration.setRuntimeVersion(desktopVersion);
+ try {
+ final DesktopConnection desktopConnection = new DesktopConnection(connectionUuid);
+ DesktopStateListener listener = new DesktopStateListener() {
+ @Override
+ public void onReady() {
+ launchThread(desktopConnection);
+ }
+ @Override
+ public void onClose(String error) {
+
+ }
+ @Override
+ public void onError(String reason) {
+ logger.error(String.format("onError %s", reason));
+ }
+
+ @Override
+ public void onMessage(String message) {
+ }
+ @Override
+ public void onOutgoingMessage(String message) {
+ }
+ };
+ desktopConnection.connect(runtimeConfiguration, listener, 50);
+ } catch (Exception e) {
+ logger.error("", e);
+ }
+ }
+
+ private static void launchThread(DesktopConnection desktopConnection) {
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ OpenFinRuntime openfinSystem = new OpenFinRuntime(desktopConnection);
+ AtomicInteger callCount = new AtomicInteger();
+ AtomicBoolean shouldRun = new AtomicBoolean(true);
+ while (shouldRun.get()) {
+ try {
+ CountDownLatch latch = new CountDownLatch(1);
+ openfinSystem.getMachineId(new AckListener() {
+ @Override
+ public void onSuccess(Ack ack) {
+ if (ack.isSuccessful()) {
+ logger.info(String.format("API call count %d", callCount.incrementAndGet()));
+ latch.countDown();
+ } else {
+ logger.error(String.format("API failed %s", ack.getReason()));
+ shouldRun.set(false);
+ }
+ }
+ @Override
+ public void onError(Ack ack) {
+ logger.error(String.format("API failed %s", ack.getReason()));
+ shouldRun.set(false);
+ }
+ });
+ latch.await(1, TimeUnit.SECONDS);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ };
+ t.start();
+ }
+}
diff --git a/src/main/java/com/openfin/desktop/demo/NoGui.java b/src/main/java/com/openfin/desktop/demo/NoGui.java
index 9b9d625..3076fff 100644
--- a/src/main/java/com/openfin/desktop/demo/NoGui.java
+++ b/src/main/java/com/openfin/desktop/demo/NoGui.java
@@ -76,7 +76,9 @@ public void onOutgoingMessage(String message) {
System.out.println("Main.onOutgoingMessage");
}
};
- desktopConnection.connectToVersion("6.49.12.17", listener, 5000);
+ RuntimeConfiguration cfg = new RuntimeConfiguration();
+ cfg.setRuntimeVersion("stable");
+ desktopConnection.connect(cfg, listener, 50);
try {
// keep Runtime running for 10 seconds
diff --git a/src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java b/src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java
index 9d40d6f..30d5c3f 100644
--- a/src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java
+++ b/src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java
@@ -157,8 +157,8 @@ private JPanel createCreateNotificationPanel() {
JTextField tfBody = new JTextField("Body");
JTextField tfCategory = new JTextField("Category");
JTextField tfIcon = new JTextField("https://openfin.co/favicon-32x32.png");
- JTextField tfIndicatorText = new JTextField("");
- JTextField tfExpiresInSecs = new JTextField("5");
+ JTextField tfIndicatorText = new JTextField("Hello From Java");
+ JTextField tfExpiresInSecs = new JTextField("60");
JComboBox cbSticky = new JComboBox<>();
cbSticky.addItem(NotificationOptions.STICKY_STICKY);
@@ -168,6 +168,7 @@ private JPanel createCreateNotificationPanel() {
cbIndicator.addItem(NotificationIndicator.TYPE_FAILURE);
cbIndicator.addItem(NotificationIndicator.TYPE_WARNING);
cbIndicator.addItem(NotificationIndicator.TYPE_SUCCESS);
+ cbIndicator.setSelectedIndex(2);
JPanel pnlCenter = new JPanel(new GridBagLayout());
GridBagConstraints gbConst = new GridBagConstraints();
diff --git a/src/main/java/com/openfin/desktop/demo/OpenFinDesktopDemo.java b/src/main/java/com/openfin/desktop/demo/OpenFinDesktopDemo.java
index 42f1d50..d849a82 100644
--- a/src/main/java/com/openfin/desktop/demo/OpenFinDesktopDemo.java
+++ b/src/main/java/com/openfin/desktop/demo/OpenFinDesktopDemo.java
@@ -22,6 +22,8 @@
import java.util.ArrayList;
import java.util.HashMap;
+import jdk.nashorn.internal.scripts.JO;
+import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -140,13 +142,50 @@ private void initDesktopConnection() throws DesktopException {
}
this.runtimeConfiguration.setAdditionalRuntimeArguments("--v=1 "); // enable additional logging
this.runtimeConfiguration.setDevToolsPort(9090);
- this.runtimeConfiguration.setLicenseKey("my-license-key");
+
+ JSONObject startupApp = new JSONObject();
+ startupApp.put("uuid", "DEMO-JAVA");
+ startupApp.put("name", "DEMO-JAVA");
+ startupApp.put("url", "https://cdn.openfin.co/process-manager/index.html");
+ startupApp.put("autoShow", true);
+
+ String licenseKey = java.lang.System.getProperty("com.openfin.demo.licenseKey");
+ if (licenseKey != null) {
+ this.runtimeConfiguration.setLicenseKey(licenseKey);
+ }
JSONObject myconfig = new JSONObject();
- myconfig.put("key1", "value1");
- myconfig.put("PI", 3.14);
+// this.runtimeConfiguration.setManifestLocation("https://cdn.openfin.co/process-manager/app.json");
+// myconfig.put("key1", "value1");
+// myconfig.put("PI", 3.14);
this.runtimeConfiguration.addConfigurationItem("myconfig", myconfig);
}
+ private void addCustomConfig(JSONObject startupApp) {
+ JSONObject defaultDomainSettings = new JSONObject();
+ JSONArray rules = new JSONArray();
+ JSONObject rule1 = new JSONObject();
+ JSONArray matchList = new JSONArray();
+ matchList.put("*/*.example.com");
+ rule1.put("match", matchList);
+ JSONObject options = new JSONObject();
+ JSONObject downloadSettings = new JSONObject();
+ JSONArray downloadSettingsRules = new JSONArray();
+ JSONObject downloadSettingsRule1 = new JSONObject();
+ JSONArray matchList1 = new JSONArray();
+ matchList1.put("*://*/*.png");
+ matchList1.put("*://*/*.jpg");
+ downloadSettingsRule1.put("match", matchList1);
+ downloadSettingsRule1.put("behavior", "no-prompt");
+ downloadSettingsRules.put(downloadSettingsRule1);
+ downloadSettings.put("rules", downloadSettingsRules);
+ options.put("downloadSettings", downloadSettings);
+ rule1.put("options", options);
+ rules.put(rule1);
+ defaultDomainSettings.put("rules", rules);
+ startupApp.put("defaultDomainSettings", defaultDomainSettings);
+ this.runtimeConfiguration.setStartupApp(startupApp);
+ }
+
private JPanel layoutLeftPanel() {
JPanel panel = new JPanel();
double size[][] = {{TableLayout.FILL}, {160, 30, TableLayout.FILL}};
diff --git a/src/main/java/com/openfin/desktop/demo/OpenFinDockingDemo.java b/src/main/java/com/openfin/desktop/demo/OpenFinDockingDemo.java
deleted file mode 100644
index 57da058..0000000
--- a/src/main/java/com/openfin/desktop/demo/OpenFinDockingDemo.java
+++ /dev/null
@@ -1,516 +0,0 @@
-package com.openfin.desktop.demo;
-
-import com.openfin.desktop.DockingManager;
-import com.openfin.desktop.*;
-import info.clearthought.layout.TableLayout;
-import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.io.*;
-import java.lang.System;
-import java.util.Arrays;
-
-/**
- * Example of snap&dock Java window with OpenFin html5 window
- *
- * Move windows close to each other so they snap, and release mouse to dock 2 windows.
- *
- * This example use snap and dock library at https://github.com/openfin/java-snap-and-dock.
- *
- * Steps to implement snap&dock in this example
- *
- * 1. Launch OpenFin Runtime, as in startOpenFinRuntime
- * 2. Create an instance of DockingManager
- * 2. Launch a HTML5 app and register with DockingManager as in launchHTMLApps
- * 3. Register Java window as in DockingManager registerJavaWindow
- *
- * All windows can receive notification when it is docked by subscribing to 'window-docked' topic. It can also request to be undocked
- * by sending a message to Docking Manager. Please refer to document of Snap&Dock library for more into
- *
- * Created by wche on 2/28/15.
- *
- */
-public class OpenFinDockingDemo extends JPanel implements ActionListener, WindowListener {
- private final static Logger logger = LoggerFactory.getLogger(OpenFinDockingDemo.class.getName());
-
- private static JFrame jFrame;
- protected JButton launch;
- protected JButton close;
-
- protected JButton undockButton;
-
- // For a Java window to be dockable, it must be registered with Runtime as a child window of a HTML5 app. We are going to create
- // a hidden HTML5 app, with javaParentAppUuid as UUID, as the parent app of all Java windows
- protected String javaParentAppUuid = "Java Parent App";
-
- protected String appUuid = "JavaDocking"; // UUID for desktopConnection
- protected String javaWindowName = "Java Dock Window";
- protected String openfin_app_url = "https://cdn.openfin.co/examples/junit/SimpleDockingExample.html"; // source is in release/SimpleDockingExample.html
-
- protected DesktopConnection desktopConnection;
- protected DockingManager dockingManager;
- protected JTextField dockStatus; // show Ready to dock message
- protected JTextArea status;
-
- public OpenFinDockingDemo() {
- try {
- this.desktopConnection = new DesktopConnection(appUuid);
- } catch (DesktopException desktopError) {
- desktopError.printStackTrace();
- }
- setLayout(new BorderLayout());
- add(layoutCenterPanel(), BorderLayout.CENTER);
- add(layoutLeftPanel(), BorderLayout.WEST);
- setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
- setMainButtonsEnabled(false);
- setAppButtonsEnabled(false);
- }
-
- private JPanel layoutLeftPanel() {
- JPanel panel = new JPanel();
- double size[][] = {{410}, {120, 30, TableLayout.FILL}};
- panel.setLayout(new TableLayout(size));
- panel.add(layoutActionButtonPanel(), "0,0,0,0");
- panel.add(layoutDockStatus(), "0,1,0,1");
- panel.add(layoutStatusPanel(), "0, 2, 0, 2");
- return panel;
- }
-
- private JTextField layoutDockStatus() {
- this.dockStatus = new JTextField();
- this.dockStatus.setForeground(Color.RED);
- return this.dockStatus;
- }
-
- private JPanel layoutActionButtonPanel() {
- JPanel buttonPanel = new JPanel();
-
- JPanel topPanel = new JPanel();
- double size[][] = {{10, 190, 20, 190, 10}, {25, 10, 25, 10}};
- topPanel.setLayout(new TableLayout(size));
- topPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), "Desktop"));
-
- launch = new JButton("Launch OpenFin");
- launch.setActionCommand("start");
- close = new JButton("Shutdown OpenFin");
- close.setActionCommand("close");
- topPanel.add(launch, "1,0,1,0");
- topPanel.add(close, "3,0,3,0");
-
- undockButton = new JButton("Undock");
- undockButton.setActionCommand("undock-window");
- undockButton.setEnabled(false);
- topPanel.add(undockButton, "1,2,1,2");
-
- close.addActionListener(this);
- launch.addActionListener(this);
- undockButton.addActionListener(this);
-
- buttonPanel.add(topPanel, "0,0");
- return buttonPanel;
- }
-
- private JPanel layoutCenterPanel() {
- JPanel panel = new JPanel();
- double size[][] = {{TableLayout.FILL}, {150, 150, TableLayout.FILL}};
- panel.setLayout(new TableLayout(size));
-
- return panel;
- }
-
- protected JPanel layoutStatusPanel() {
- //Simple status console
- status = new JTextArea();
- status.setEditable(false);
- status.setAutoscrolls(true);
- status.setLineWrap(true);
- JScrollPane statusPane = new JScrollPane(status);
- statusPane.setVerticalScrollBarPolicy(
- JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
- statusPane.getViewport().setOpaque(false);
- statusPane.setOpaque(false);
- statusPane.setBorder(BorderFactory.createEmptyBorder(5,15,15,15));
-
-
-
- JPanel panel = new JPanel();
- panel.setLayout(new BorderLayout());
- panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), "Status"));
- panel.add(statusPane, BorderLayout.CENTER);
-
- return panel;
- }
-
- @Override
- public void windowOpened(WindowEvent e) {
- }
-
- @Override
- public void windowClosing(WindowEvent e) {
- closeDesktop();
- }
-
- @Override
- public void windowClosed(WindowEvent e) {
- }
-
- @Override
- public void windowIconified(WindowEvent e) {
- }
-
- @Override
- public void windowDeiconified(WindowEvent e) {
- }
-
- @Override
- public void windowActivated(WindowEvent e) {
- }
-
- @Override
- public void windowDeactivated(WindowEvent e) {
- }
-
- private void updateMessagePanel(final String msg) {
- if (SwingUtilities.isEventDispatchThread()) {
- String t = "";
- if (status.getText().length() > 0) {
- t = status.getText();
- }
- StringBuilder b = new StringBuilder();
- b.append(msg).append("\n").append(t);
- status.setText(b.toString());
- status.setCaretPosition(0);
- } else {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- updateMessagePanel(msg);
- }
- });
- }
- }
-
-
- private void closeDesktop() {
- if (desktopConnection != null && desktopConnection.isConnected()) {
- try {
- Application javaParentApp = Application.wrap(javaParentAppUuid, desktopConnection);
- javaParentApp.close();
- dockingManager.dispose();
- Thread.sleep(2000);
- desktopConnection.exit();
- desktopConnection = null;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- try {
- Thread.sleep(2000);
- System.exit(0);
- } catch (InterruptedException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
-
- private void undockFromOtherWindows() {
- try {
- // send message to Docking Manager to undock me
- JSONObject msg = new JSONObject();
- msg.put("applicationUuid", javaParentAppUuid);
- msg.put("windowName", javaWindowName);
- desktopConnection.getInterApplicationBus().publish("undock-window", msg);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- undockButton.setEnabled(false);
- }
-
- /**
- *
- * Start OpenFin Runtime
- *
- */
- private void startOpenFinRuntime() {
- try {
- DesktopStateListener listener = new DesktopStateListener() {
- @Override
- public void onReady() {
- onRuntimeReady();
- }
-
- @Override
- public void onClose(String error) {
- updateMessagePanel(String.format("Connection closed %s", error));
- }
- @Override
- public void onError(String reason) {
- updateMessagePanel("Connection failed: " + reason);
- }
- @Override
- public void onMessage(String message) {
- }
- @Override
- public void onOutgoingMessage(String message) {
- }
- };
- RuntimeConfiguration configuration = new RuntimeConfiguration();
- configuration.setDevToolsPort(9090);
- configuration.setAdditionalRuntimeArguments(" --v=1 "); // enable additional logging from Runtime
- String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version");
- if (desktopVersion == null) {
- desktopVersion = "stable";
- }
- configuration.setRuntimeVersion(desktopVersion);
- desktopConnection.connect(configuration, listener, 60);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void onRuntimeReady() {
- try {
- updateMessagePanel("Connection authorized.");
- setMainButtonsEnabled(true);
- this.dockingManager = new DockingManager(this.desktopConnection, this.javaParentAppUuid);
- this.desktopConnection.getInterApplicationBus().subscribe("*", "window-docked", (uuid, topic, data) -> {
- JSONObject event = (JSONObject) data;
- String appUuid = event.getString("applicationUuid");
- String windowName = event.getString("windowName");
- updateMessagePanel(String.format("Window docked %s %s", appUuid, windowName));
- if (javaParentAppUuid.equals(appUuid) && javaWindowName.equals(windowName)) {
- updateUndockButton(true);
- }
- });
- this.desktopConnection.getInterApplicationBus().subscribe("*", "window-undocked", (uuid, topic, data) -> {
- JSONObject event = (JSONObject) data;
- String appUuid = event.getString("applicationUuid");
- String windowName = event.getString("windowName");
- updateMessagePanel(String.format("Window undocked %s %s", appUuid, windowName));
- if (javaParentAppUuid.equals(appUuid) && javaWindowName.equals(windowName)) {
- updateUndockButton(false);
- }
- });
- registerJavaWindow();
- launchHTMLApps();
- launchAnotherJavaApp();
- } catch (Exception e) {
- logger.error("Error creating DockingManager", e);
- }
- }
-
- public void actionPerformed(java.awt.event.ActionEvent e) {
- if ("start".equals(e.getActionCommand())) {
- startOpenFinRuntime();
- } else if ("close".equals(e.getActionCommand())) {
- closeDesktop();
- } else if ("undock-window".equals(e.getActionCommand())) {
- undockFromOtherWindows();
- }
- }
-
-
- private void setMainButtonsEnabled(boolean enabled) {
- launch.setEnabled(!enabled);
- close.setEnabled(enabled);
- }
-
- private void setAppButtonsEnabled(boolean enabled) {
- }
-
- /**
- * Register Java window with OpenFin Runtime
- *
- */
- private void registerJavaWindow() {
- try {
- // Java window needs to be assigned a HTML5 app as parent app in order for Runtime to control it.
- // now we are creating a HTML5 app aith autoShow = false so it is hidden.
- ApplicationOptions options = new ApplicationOptions(javaParentAppUuid, javaParentAppUuid, openfin_app_url);
- options.setApplicationIcon("http://openfin.github.io/snap-and-dock/openfin.ico");
- WindowOptions mainWindowOptions = new WindowOptions();
- mainWindowOptions.setAutoShow(false);
- mainWindowOptions.setDefaultHeight(50);
- mainWindowOptions.setDefaultLeft(50);
- mainWindowOptions.setDefaultTop(50);
- mainWindowOptions.setDefaultWidth(50);
- mainWindowOptions.setShowTaskbarIcon(false);
- mainWindowOptions.setSaveWindowState(false); // set to false so all windows start at same initial positions for each run
- options.setMainWindowOptions(mainWindowOptions);
- launchHTMLApp(options, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- Application app = (Application) ack.getSource();
- logger.debug("Registering java window");
- dockingManager.registerJavaWindow(javaWindowName, jFrame,
- new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- if (ack.isSuccessful()) {
- undockButton.setEnabled(false);
- }
- }
- @Override
- public void onError(Ack ack) {
- logger.error("Error registering Java window " + ack.getReason());
- }
- });
- }
- @Override
- public void onError(Ack ack) {
- logger.error("Error launching " + javaParentAppUuid);
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- *
- * Launching HTML5 apps and register docking manager
- *
- */
- private void launchHTMLApps() {
- // launch 5 instances of same example app
- int width = 300, height=200;
- int gap = 50; // gap between windows at initial positions
- for (int i = 0; i < 2; i++) {
- try {
- String uuid = String.format("docking-html-%d", i);
- ApplicationOptions options = new ApplicationOptions(uuid, uuid, openfin_app_url);
- options.setApplicationIcon("http://openfin.github.io/snap-and-dock/openfin.ico");
- WindowOptions mainWindowOptions = new WindowOptions();
- mainWindowOptions.setAutoShow(true);
- mainWindowOptions.setDefaultHeight(height);
- mainWindowOptions.setDefaultLeft(10 + i * (width + gap));
- mainWindowOptions.setDefaultTop(50);
- mainWindowOptions.setDefaultWidth(width);
- mainWindowOptions.setShowTaskbarIcon(true);
- mainWindowOptions.setSaveWindowState(false); // set to false so all windows start at same initial positions for each run
- options.setMainWindowOptions(mainWindowOptions);
- launchHTMLApp(options, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- logger.debug(String.format("Successful launching %s", options.getUUID()));
- Application app = (Application) ack.getSource();
- dockingManager.registerWindow(app.getWindow());
- }
- @Override
- public void onError(Ack ack) {
- logger.error(String.format("Error launching %s %s", options.getUUID(), ack.getReason()));
- }
- });
- } catch (Exception e) {
- logger.error("Error launching app", e);
- }
- }
- }
-
- private void launchHTMLApp(ApplicationOptions options, AckListener ackListener) throws Exception {
- logger.debug(String.format("Launching %s", options.getUUID()));
- DemoUtils.runApplication(options, this.desktopConnection, ackListener);
- }
-
-
- private void launchAnotherJavaApp() {
- Thread launchThread = new Thread() {
- public void run() {
- logger.debug(String.format("Launching docking.bat %s", DockingDemo2.class.getName()));
- String[] command = {"docking.bat", DockingDemo2.class.getName()};
- ProcessBuilder probuilder = new ProcessBuilder( command );
- //You can set up your work directory
- probuilder.directory(new File("."));
- try {
-// Process process = probuilder.start();
-// //Read out dir output
-// InputStream is = process.getInputStream();
-// InputStreamReader isr = new InputStreamReader(is);
-// BufferedReader br = new BufferedReader(isr);
-// String line;
-// while ((line = br.readLine()) != null) {
-// logger.debug(String.format("Java App output: %s", line));
-// }
-// int exitValue = process.waitFor();
-// logger.debug(String.format("Java app exit code %d", exitValue));
-
- Process process = Runtime.getRuntime().exec("cmd");
- OutputStream stdin = process.getOutputStream();
- InputStream stderr = process.getErrorStream();
- InputStream stdout = process.getInputStream();
- String line = "start docking.bat " + DockingDemo2.class.getName() + "\n";
- stdin.write(line.getBytes());
- stdin.flush();
- stdin.close();
- // clean up if any output in stdout
- BufferedReader brCleanUp =
- new BufferedReader(new InputStreamReader(stdout));
- while ((line = brCleanUp.readLine()) != null) {
- logger.debug("[Stdout] " + line);
- }
- brCleanUp.close();
- // clean up if any output in stderr
- brCleanUp =
- new BufferedReader(new InputStreamReader(stderr));
- while ((line = brCleanUp.readLine()) != null) {
- logger.info("[Stderr] " + line);
- }
- brCleanUp.close();
- } catch (Exception ex) {
- logger.error("Error launch java app", ex);
- }
- }
- };
- launchThread.start();
- }
-
- private void updateUndockButton(boolean enabled) {
- this.undockButton.setEnabled(enabled);
- if (enabled) {
- this.dockStatus.setText("Docked. Click Unlock button to undock");
- } else {
- this.dockStatus.setText("");
- }
- }
-
-
- private static void createAndShowGUI() {
- //Create and set up the window.
- jFrame = new JFrame("Java Docking Demo");
- jFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
-
- //Create and set up the content pane.
- OpenFinDockingDemo newContentPane = new OpenFinDockingDemo();
- newContentPane.setOpaque(true); //content panes must be opaque
- jFrame.setContentPane(newContentPane);
- jFrame.addWindowListener(newContentPane);
-
- //Display the window.
- jFrame.pack();
- jFrame.setSize(470, 300);
- jFrame.setLocation(100, 400);
-// jFrame.setLocationRelativeTo(null);
- jFrame.setResizable(false);
- jFrame.setVisible(true);
- }
-
-
- /**
- *
- * @param args
- */
- public static void main(String[] args) {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
-
-}
diff --git a/src/main/java/com/openfin/desktop/demo/Signer.java b/src/main/java/com/openfin/desktop/demo/Signer.java
index 22a611b..4c3bd42 100644
--- a/src/main/java/com/openfin/desktop/demo/Signer.java
+++ b/src/main/java/com/openfin/desktop/demo/Signer.java
@@ -1,2 +1,98 @@
-package com.openfin.desktop.demo;public class Signer {
+package com.openfin.desktop.demo;
+
+import java.io.InputStream;
+import java.security.CodeSigner;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+public class Signer {
+ private final String filename;
+
+ public Signer(String filename) {
+ this.filename = filename;
+ }
+
+ public void verify() throws Exception {
+ JarFile jar = new JarFile(this.filename, true);
+
+ Enumeration entries = jar.entries();
+ while (entries.hasMoreElements()) {
+ JarEntry entry = entries.nextElement();
+ byte[] buffer = new byte[8192];
+ InputStream is = jar.getInputStream(entry);
+ while ((is.read(buffer, 0, buffer.length)) != -1) {
+ // We just read. This will throw a SecurityException
+ // if a signature/digest check fails.
+ }
+ is.close();
+ }
+
+ if (!checkSign(jar)) {
+ throw new SecurityException("not signed");
+ }
+
+ }
+
+ private boolean checkSign(JarFile jar) throws Exception {
+ InputStream jis = jar.getInputStream(jar.getEntry("META-INF/MANIFEST.MF"));
+ Manifest man = new Manifest(jis);
+ jis.close();
+
+ HashSet signed = new HashSet<>();
+ for(Map.Entry entry: man.getEntries().entrySet()) {
+ for(Object attrkey: entry.getValue().keySet()) {
+ if (attrkey instanceof Attributes.Name && attrkey.toString().contains("-Digest")) {
+ signed.add(entry.getKey());
+ }
+ }
+ }
+ System.out.printf("Number of Digest from manifest %d \n", signed.size());
+
+ Set entries = new HashSet<>();
+ for(Enumeration entry = jar.entries(); entry.hasMoreElements(); ) {
+ JarEntry je = entry.nextElement();
+ String fileName = je.getName().toUpperCase();
+ if (!je.isDirectory()
+ && !fileName.endsWith(".MF")
+ && !fileName.endsWith(".SF")
+ && !fileName.endsWith(".DSA")
+ && !fileName.endsWith(".EC")
+ && !fileName.endsWith(".RSA")
+ ) {
+ CodeSigner[] signers = je.getCodeSigners();
+ if (signers != null && signers.length == 1) {
+ CodeSigner signer = signers[0];
+ if (signer.getSignerCertPath().getCertificates().size() != 4) {
+ throw new SecurityException(String.format("invalid cert chain %s", je.getName()));
+ }
+ X509Certificate cert = (X509Certificate) signer.getSignerCertPath().getCertificates().get(0);
+ if (!cert.getSubjectDN().toString().contains("OpenFin Inc.")) {
+ throw new SecurityException(String.format("invalid signed %s", je.getName()));
+ }
+ entries.add(je.getName());
+ } else {
+ throw new SecurityException(String.format("missing cert %s", je.getName()));
+ }
+ }
+ }
+ System.out.printf("Number of signed entries %d \n", entries.size());
+
+ Set unsigned = new HashSet<>(entries);
+ unsigned.removeAll(signed);
+ return unsigned.size() == 0;
+ }
+
+ public static void main(String[] args) throws Exception {
+ Signer signer = new Signer(args[0]);
+ signer.verify();
+ }
+
}
diff --git a/src/test/java/com/openfin/desktop/AllTests.java b/src/test/java/com/openfin/desktop/AllTests.java
index 68f0374..cc84773 100644
--- a/src/test/java/com/openfin/desktop/AllTests.java
+++ b/src/test/java/com/openfin/desktop/AllTests.java
@@ -10,6 +10,6 @@
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({ ApplicationTest.class, OpenFinRuntimeTest.class, WindowTest.class, SystemTest.class, InterApplicationBusTest.class, ChannelTest.class, RuntimeConfigTest.class})
+@Suite.SuiteClasses({ ApplicationTest.class, OpenFinRuntimeTest.class, WindowTest.class, SystemTest.class, InterApplicationBusTest.class, ChannelTest.class, RuntimeConfigTest.class, InteropTest.class, SnapshotTest.class})
public class AllTests {
}
diff --git a/src/test/java/com/openfin/desktop/ApplicationTest.java b/src/test/java/com/openfin/desktop/ApplicationTest.java
index 26b0243..4eedf85 100644
--- a/src/test/java/com/openfin/desktop/ApplicationTest.java
+++ b/src/test/java/com/openfin/desktop/ApplicationTest.java
@@ -155,110 +155,6 @@ public void createChildWindow() throws Exception {
TestUtils.closeApplication(application);
}
- @Test
- public void crossAppDockAndUndock() throws Exception {
- Application application1 = TestUtils.runApplication(TestUtils.getAppOptions(null), desktopConnection);
- Application application2 = TestUtils.runApplication(TestUtils.getAppOptions(null), desktopConnection);
-
- WindowBounds beforeMoveBounds = TestUtils.getBounds(application2.getWindow());
- CountDownLatch joinLatch = new CountDownLatch(1);
- application2.getWindow().joinGroup(application1.getWindow(), new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- if (ack.isSuccessful()) {
- joinLatch.countDown();
- }
- }
- @Override
- public void onError(Ack ack) {
- logger.error(String.format("onError %s", ack.getReason()));
- }
- });
- joinLatch.await(3, TimeUnit.SECONDS);
- assertEquals(joinLatch.getCount(), 0);
-
- // get group info for a window
- CountDownLatch groupInfoLatch = new CountDownLatch(2);
- application1.getWindow().getGroup(result -> {
- for (Window window : result) {
- if (window.getUuid().equals(application1.getWindow().getUuid()) && window.getName().equals(application1.getWindow().getName())) {
- groupInfoLatch.countDown();
- } else if (window.getUuid().equals(application2.getWindow().getUuid()) && window.getName().equals(application2.getWindow().getName())) {
- groupInfoLatch.countDown();
- }
- }
- }, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- }
- @Override
- public void onError(Ack ack) {
- logger.error(String.format("onError %s", ack.getReason()));
- }
- });
- groupInfoLatch.await(3, TimeUnit.SECONDS);
- assertEquals(groupInfoLatch.getCount(), 0);
-
- // get group info for an application
- CountDownLatch appGroupInfoLatch = new CountDownLatch(2);
- application1.getGroups(result -> {
- for (List list: result) {
- for (Window window : list) {
- if (window.getUuid().equals(application1.getWindow().getUuid()) && window.getName().equals(application1.getWindow().getName())) {
- appGroupInfoLatch.countDown();
- } else if (window.getUuid().equals(application2.getWindow().getUuid()) && window.getName().equals(application2.getWindow().getName())) {
- appGroupInfoLatch.countDown();
- }
- }
- }
- }, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- }
- @Override
- public void onError(Ack ack) {
- logger.error(String.format("onError %s", ack.getReason()));
- }
- }
- );
- appGroupInfoLatch.await(3, TimeUnit.SECONDS);
- assertEquals(appGroupInfoLatch.getCount(), 0);
-
- int leftBy = 20, topBy = 30;
- TestUtils.moveWindowBy(application1.getWindow(), leftBy, topBy);
- // child window sohuld move with main window since they are docked
- WindowBounds afterMoveBounds = TestUtils.getBounds(application2.getWindow());
- int topAfterDockMove = afterMoveBounds.getTop(), leftAfterDockMove = afterMoveBounds.getLeft();
- assertEquals(afterMoveBounds.getTop() - beforeMoveBounds.getTop(), topBy);
- assertEquals(afterMoveBounds.getLeft() - beforeMoveBounds.getLeft(), leftBy);
-
- // undock by leaving the group
- CountDownLatch undockLatch = new CountDownLatch(1);
- application2.getWindow().leaveGroup(new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- if (ack.isSuccessful()) {
- undockLatch.countDown();
- }
- }
-
- @Override
- public void onError(Ack ack) {
- logger.error(String.format("onError %s", ack.getReason()));
- }
- });
- undockLatch.await(5, TimeUnit.SECONDS);
- assertEquals(undockLatch.getCount(), 0);
- TestUtils.moveWindowBy(application1.getWindow(), leftBy, topBy);
- // child window should not move afer leaving group
- afterMoveBounds = TestUtils.getBounds(application2.getWindow());
- assertEquals(afterMoveBounds.getLeft().intValue(), leftAfterDockMove);
- assertEquals(afterMoveBounds.getTop().intValue(), topAfterDockMove);
-
- TestUtils.closeApplication(application1);
- TestUtils.closeApplication(application2);
- }
-
@Test
public void addEventListener() throws Exception {
ApplicationOptions options = TestUtils.getAppOptions(null);
diff --git a/src/test/java/com/openfin/desktop/ChannelTest.java b/src/test/java/com/openfin/desktop/ChannelTest.java
index 22cb8a5..e8009de 100644
--- a/src/test/java/com/openfin/desktop/ChannelTest.java
+++ b/src/test/java/com/openfin/desktop/ChannelTest.java
@@ -2,34 +2,21 @@
import static org.junit.Assert.assertEquals;
+import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
+import com.openfin.desktop.channel.*;
import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.openfin.desktop.channel.ChannelAction;
-import com.openfin.desktop.channel.ChannelClient;
-import com.openfin.desktop.channel.ChannelListener;
-import com.openfin.desktop.channel.ChannelProvider;
-import com.openfin.desktop.channel.ConnectionEvent;
-import com.openfin.desktop.channel.Middleware;
-
/**
- * JUnit tests for com.openfin.desktop.InterApplicationBus class
- *
- * Test cases in this class need to have access to an OpenFin HTML5 app to
- * verify sub/pub workflow. Sources for the app can be found in release
- * directory: PubSubExample.html. It is hosted by OpenFin at
- * https://cdn.openfin.co/examples/junit/PubSubExample.html
+ * JUnit tests for OpenFin Channel API
*
* Created by wche on 1/27/16.
*
@@ -54,15 +41,25 @@ public static void teardown() throws Exception {
@Test
public void createChannelProvider() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
- desktopConnection.getChannel("createChannelProviderTest").create(new AsyncCallback() {
+ desktopConnection.getChannel("createChannelProvider").create(new AsyncCallback() {
@Override
public void onSuccess(ChannelProvider provider) {
latch.countDown();
}
});
-
latch.await(10, TimeUnit.SECONDS);
+ assertEquals(0, latch.getCount());
+ }
+ @Test
+ public void createChannelProviderAsync() throws Exception {
+ CountDownLatch latch = new CountDownLatch(1);
+ desktopConnection.getChannel("createChannelProviderAsync").createAsync().thenAccept(provider -> {
+ if (Objects.nonNull(provider)) {
+ latch.countDown();
+ }
+ });
+ latch.await(10, TimeUnit.SECONDS);
assertEquals(0, latch.getCount());
}
@@ -81,13 +78,24 @@ public void onSuccess(ChannelClient result) {
});
}
});
-
latch.await(10, TimeUnit.SECONDS);
-
assertEquals(0, latch.getCount());
}
-
- @Ignore
+ @Test
+ public void createChannelClientAsync() throws Exception {
+ CountDownLatch latch = new CountDownLatch(1);
+ final String channelName = "createChannelClientAsync";
+ desktopConnection.getChannel(channelName).createAsync().thenAccept(provider -> {
+ desktopConnection.getChannel(channelName).connectAsync().thenAccept(client -> {
+ if (Objects.nonNull(client)) {
+ latch.countDown();
+ }
+ });
+ });
+ latch.await(10, TimeUnit.SECONDS);
+ assertEquals(0, latch.getCount());
+ }
+
@Test
public void multipleChannelClients() throws Exception {
CountDownLatch latch1 = new CountDownLatch(1);
@@ -98,11 +106,9 @@ public void multipleChannelClients() throws Exception {
desktopConnection.getChannel(channelName).create(new AsyncCallback() {
@Override
public void onSuccess(ChannelProvider provider) {
-
provider.register(providerActionName, new ChannelAction() {
-
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
return null;
}
});
@@ -112,10 +118,9 @@ public JSONObject invoke(String action, JSONObject payload, JSONObject senderIde
@Override
public void onSuccess(ChannelClient client) {
client.dispatch(providerActionName, new JSONObject(), null);
-
client.register(clientActionName, new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
latch1.countDown();
return null;
}
@@ -128,12 +133,11 @@ public JSONObject invoke(String action, JSONObject payload, JSONObject senderIde
public void onSuccess(ChannelClient client) {
client.register(clientActionName, new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
latch2.countDown();
return null;
}
});
-
provider.publish(clientActionName, new JSONObject(), null);
}
});
@@ -156,8 +160,8 @@ public void registerAction() throws Exception {
public void onSuccess(ChannelProvider provider) {
provider.register("currentTime", new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
- return payload.put("currentTime", java.lang.System.currentTimeMillis());
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
+ return ((JSONObject)payload).put("currentTime", java.lang.System.currentTimeMillis());
}
});
latch.countDown();
@@ -182,9 +186,9 @@ public void invokeProviderAction() throws Exception {
public void onSuccess(ChannelProvider provider) {
provider.register(actionName, new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
- int currentValue = payload.getInt("value");
- return payload.put("value", currentValue + 1);
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
+ int currentValue = ((JSONObject)payload).getInt("value");
+ return ((JSONObject)payload).put("value", currentValue + 1);
}
});
@@ -230,7 +234,7 @@ public void invokeClientAction() throws Exception {
public void onSuccess(ChannelProvider provider) {
provider.register(providerActionName, new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
provider.dispatch(senderIdentity, clientActionName, new JSONObject(), null);
return null;
}
@@ -241,7 +245,7 @@ public JSONObject invoke(String action, JSONObject payload, JSONObject senderIde
public void onSuccess(ChannelClient client) {
client.register(clientActionName, new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
latch.countDown();
return null;
}
@@ -274,8 +278,8 @@ public void onSuccess(ChannelClient client) {
client.register(actionName, new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
- if (actionName.equals(action) && actionMessage.equals(payload.getString("message"))) {
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
+ if (actionName.equals(action) && actionMessage.equals(((JSONObject)payload).getString("message"))) {
latch.countDown();
}
return null;
@@ -298,35 +302,32 @@ public JSONObject invoke(String action, JSONObject payload, JSONObject senderIde
@Test
public void connectionListener() throws Exception {
final String channelName = "connectionListenerTest";
- CountDownLatch latch = new CountDownLatch(2);
-
- desktopConnection.getChannel(channelName).create(new AsyncCallback() {
- @Override
- public void onSuccess(ChannelProvider provider) {
- desktopConnection.getChannel(channelName).addChannelListener(new ChannelListener() {
+ CountDownLatch latch = new CountDownLatch(3);
+ desktopConnection.getChannel(channelName).createAsync().thenAccept(provider -> {
+ provider.addProviderListener(new ChannelProviderListener() {
+ @Override
+ public void onClientConnect(ChannelClientConnectEvent connectionEvent) throws Exception {
+ latch.countDown();
+ }
+ @Override
+ public void onClientDisconnect(ChannelClientConnectEvent connectionEvent) {
+ latch.countDown();
+ }
+ });
+
+ desktopConnection.getChannel(channelName).connectAsync().thenAccept(client -> {
+ client.disconnect(new AckListener() {
@Override
- public void onChannelConnect(ConnectionEvent connectionEvent) {
+ public void onSuccess(Ack ack) {
latch.countDown();
}
-
@Override
- public void onChannelDisconnect(ConnectionEvent connectionEvent) {
- latch.countDown();
+ public void onError(Ack ack) {
}
});
-
- desktopConnection.getChannel(channelName).connect(new AsyncCallback() {
- @Override
- public void onSuccess(ChannelClient client) {
- client.disconnect(null);
- }
-
- });
- }
+ });
});
-
latch.await(10, TimeUnit.SECONDS);
-
assertEquals(0, latch.getCount());
}
@@ -345,19 +346,19 @@ public void onSuccess(ChannelProvider provider) {
provider.setBeforeAction(new Middleware() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderId) {
+ public Object invoke(String action, Object payload, JSONObject senderId) {
if (actionName.equals(action)) {
- int value = payload.getInt("value");
- payload.put("value", value + middlewareIncrement);
+ int value = ((JSONObject)payload).getInt("value");
+ ((JSONObject)payload).put("value", value + middlewareIncrement);
}
return payload;
}});
provider.register(actionName, new ChannelAction() {
@Override
- public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) {
- int currentValue = payload.getInt("value");
- return payload.put("value", currentValue + 1);
+ public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) {
+ int currentValue = ((JSONObject)payload).getInt("value");
+ return ((JSONObject) payload).put("value", currentValue + 1);
}
});
@@ -391,4 +392,38 @@ public void onError(Ack ack) {
assertEquals(initValue + 3, resultValue.get());
}
+ @Test
+ public void rejectConnection() throws Exception {
+ final String channelName = "rejectConnectionTest";
+ final String payloadValue = "reject me";
+ final String rejectReason = "not allowed";
+
+ CountDownLatch latch = new CountDownLatch(1);
+
+ desktopConnection.getChannel(channelName).createAsync().thenAccept(provider -> {
+ provider.addProviderListener(new ChannelProviderListener() {
+ @Override
+ public void onClientConnect(ChannelClientConnectEvent connectionEvent) throws Exception {
+ String payload = (String) connectionEvent.getPayload();
+ if (payloadValue.equals(payload)) {
+ throw new Exception(rejectReason);
+ }
+ }
+ @Override
+ public void onClientDisconnect(ChannelClientConnectEvent connectionEvent) {
+ }
+ });
+
+ desktopConnection.getChannel(channelName).connectAsync(payloadValue).thenAccept(client -> {
+ }).exceptionally(ex -> {
+ if (ex.getMessage().contains(rejectReason)) {
+ latch.countDown();
+ }
+ return null;
+ });
+ });
+
+ latch.await(10, TimeUnit.SECONDS);
+ assertEquals(0, latch.getCount());
+ }
}
diff --git a/src/test/java/com/openfin/desktop/InterApplicationBusTest.java b/src/test/java/com/openfin/desktop/InterApplicationBusTest.java
index 26f7807..38f4bf1 100644
--- a/src/test/java/com/openfin/desktop/InterApplicationBusTest.java
+++ b/src/test/java/com/openfin/desktop/InterApplicationBusTest.java
@@ -275,50 +275,6 @@ public void unsubscribed(String uuid, String topic) {
TestUtils.closeApplication(application);
}
- @Ignore
- @Test
- public void wildCardTopic() throws Exception {
-
- CountDownLatch latch = new CountDownLatch(1);
- BusListener busListener = (sourceUuid, receivingTopic, payload) -> {
- logger.debug(String.format("Receiving %s", payload.toString()));
- // PubSubExample.html sends the following
- // fin.desktop.InterApplicationBus.publish('check-in', {name: 'Pub/Sub example app'});
- if (receivingTopic.equals("check-in")) {
- latch.countDown();
- }
- };
- subscribeToTopic("*", "*", busListener);
-
- ApplicationOptions options = TestUtils.getAppOptions(openfin_app_url);
- Application application = TestUtils.createApplication(options, desktopConnection);
- TestUtils.runApplication(application, true);
-
- latch.await(5, TimeUnit.SECONDS);
- assertEquals(latch.getCount(), 0);
- }
-
- @Ignore
- @Test
- public void wildCardTopicSelf() throws Exception {
-
- CountDownLatch latch = new CountDownLatch(1);
- BusListener busListener = (sourceUuid, receivingTopic, payload) -> {
- logger.debug(String.format("Receiving %s", payload.toString()));
- if (receivingTopic.equals("wildcard-self")) {
- latch.countDown();
- }
- };
- subscribeToTopic("*", "*", busListener);
-
- JSONObject msg = new JSONObject();
- msg.put("name", "wildCardTopicSelf");
- desktopConnection.getInterApplicationBus().publish("wildcard-self", msg);
-
- latch.await(5, TimeUnit.SECONDS);
- assertEquals(latch.getCount(), 0);
- }
-
@Ignore
@Test
public void topicWithSpecialCharacters() throws Exception {
diff --git a/src/test/java/com/openfin/desktop/InteropTest.java b/src/test/java/com/openfin/desktop/InteropTest.java
new file mode 100644
index 0000000..7b412c3
--- /dev/null
+++ b/src/test/java/com/openfin/desktop/InteropTest.java
@@ -0,0 +1,203 @@
+package com.openfin.desktop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.openfin.desktop.interop.Intent;
+import com.openfin.desktop.interop.InteropClient;
+import org.json.JSONObject;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.openfin.desktop.interop.Context;
+import com.openfin.desktop.interop.ContextGroupInfo;
+
+public class InteropTest {
+ private static Logger logger = LoggerFactory.getLogger(InteropTest.class.getName());
+
+ private static final String DESKTOP_UUID = InteropTest.class.getName();
+ private static final String BROKER_NANE = "AdapterInteropTest"; // created by javascript side
+ private static DesktopConnection desktopConnection;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ logger.debug("starting");
+ RuntimeConfiguration cfg = new RuntimeConfiguration();
+ cfg.setManifestLocation("https://testing-assets.openfin.co/adapters/interop/app.json");
+// cfg.setManifestLocation("http://localhost:5555/app.json");
+ desktopConnection = TestUtils.setupConnection(DESKTOP_UUID, cfg);
+ Thread.sleep(3000); // give time for the js app to start up and configure everything properly
+ }
+
+ @AfterClass
+ public static void teardown() throws Exception {
+ TestUtils.teardownDesktopConnection(desktopConnection);
+ }
+
+ @Test
+ public void clientGetContextGroupInfo() throws Exception {
+ CompletionStage getContextFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.getContextGroups();
+ });
+
+ ContextGroupInfo[] contextGroupInfo = getContextFuture.toCompletableFuture().get(10, TimeUnit.SECONDS);
+ assertNotNull(contextGroupInfo);
+ assertTrue(contextGroupInfo.length > 0);
+ assertNotNull(contextGroupInfo[0].getDisplayMetadata().getColor());
+ }
+
+ @Test
+ public void clientGetInfoForContextGroup() throws Exception {
+ CompletionStage getContextFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.getInfoForContextGroup("red");
+ });
+
+ ContextGroupInfo contextGroupInfo = getContextFuture.toCompletableFuture().get(10, TimeUnit.SECONDS);
+ assertNotNull(contextGroupInfo);
+ assertNotNull(contextGroupInfo.getDisplayMetadata().getColor());
+ }
+
+ @Test
+ public void clientGetAllClientsInContextGroup() throws Exception {
+ CompletionStage getContextFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.joinContextGroup("red").thenCompose(v->{
+ return client.getAllClientsInContextGroup("red");
+ });
+ });
+
+ ClientIdentity[] clientIdentity = getContextFuture.toCompletableFuture().get(10, TimeUnit.SECONDS);
+ assertNotNull(clientIdentity);
+ assertTrue(clientIdentity.length > 0);
+ assertNotNull(clientIdentity[0].getEndpointId());
+ }
+
+ @Test
+ public void clientJoinThenRemoveFromContextGroup() throws Exception {
+ AtomicInteger clientCntAfterJoin = new AtomicInteger(0);
+ AtomicInteger clientCntAfterRemove = new AtomicInteger(0);
+ CompletionStage> testFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.joinContextGroup("green").thenCompose(v->{
+ return client.getAllClientsInContextGroup("green");
+ }).thenAccept(clients->{
+ logger.info(String.format("clientJoinThenRemoveFromContextGroup after join %d", clients.length));
+ clientCntAfterJoin.set(clients.length);
+ }).thenCompose(v->{
+ return client.removeFromContextGroup();
+ }).thenCompose(v->{
+ return client.getAllClientsInContextGroup("green");
+ }).thenAccept(clients->{
+ logger.info(String.format("clientJoinThenRemoveFromContextGroup after remove %d", clients.length));
+ clientCntAfterRemove.set(clients.length);
+ });
+ });
+
+ testFuture.toCompletableFuture().get(10, TimeUnit.SECONDS);
+ assertEquals(clientCntAfterJoin.get(), clientCntAfterRemove.incrementAndGet());
+ }
+
+ @Test
+ public void clientSetContext() throws Exception {
+ final Context context = getRandomContext();
+ CompletionStage setContextFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.getContextGroups().thenCompose(groups->{
+ return client.joinContextGroup("red").thenCompose(v->{
+ return client.setContext(context);
+ });
+ });
+ });
+
+ setContextFuture.toCompletableFuture().get(10, TimeUnit.SECONDS);
+ }
+
+ @Test
+ public void clientAddContextListener() throws Exception {
+ final Context context = getRandomContext();
+
+ CompletableFuture listenerInvokedFuture = new CompletableFuture<>();
+
+ desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.addContextListener(ctx->{
+ String ticker = ctx.getId().optString("ticker", "");
+ StringBuilder sb = new StringBuilder(context.getId().getString("ticker"));
+ if (ticker.equals(sb.append("1").toString())) {
+ listenerInvokedFuture.complete(ctx);
+ }
+ }).thenApply(v->{
+ return client;
+ });
+ }).thenCompose(client->{
+ return client.joinContextGroup("red").thenCompose(v->{
+ return client.setContext(context);
+ });
+ });
+
+ Context ctx = listenerInvokedFuture.toCompletableFuture().get(10, TimeUnit.SECONDS);
+ assertNotNull(ctx);
+ }
+
+ @Test
+ public void clientFireIntent() throws Exception {
+ final Context context = getRandomContext();
+ Intent intent = new Intent();
+ intent.setName("JavaIntent");
+ intent.setContext(context);
+ CompletionStage fireIntentFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.fireIntent(intent);
+ });
+ desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.registerIntentListener("JavaIntent", intentReceived->{
+ String ticker = intentReceived.getContext().getId().optString("ticker", "");
+ StringBuilder sb = new StringBuilder(context.getId().getString("ticker"));
+ }).thenCompose(v -> {
+ return client.fireIntent(intent);
+ });
+ });
+
+
+ fireIntentFuture.toCompletableFuture().get(10, TimeUnit.SECONDS);
+ }
+
+ @Test
+ public void clientFireAndRegisterIntentListener() throws Exception {
+ final Context context = getRandomContext();
+
+ CompletableFuture listenerInvokedFuture = new CompletableFuture<>();
+ desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{
+ return client.registerIntentListener("JavaIntent", intentReceived->{
+ String ticker = intentReceived.getContext().getId().optString("ticker", "");
+ StringBuilder sb = new StringBuilder(context.getId().getString("ticker"));
+ if (ticker.equals(sb.append("1").toString())) {
+ listenerInvokedFuture.complete(intentReceived);
+ }
+ }).thenCompose(v -> {
+ Intent intent = new Intent();
+ intent.setName("JsTestIntent");
+ intent.setContext(context);
+ return client.fireIntent(intent);
+ });
+ });
+
+ Intent intent = listenerInvokedFuture.toCompletableFuture().get(60, TimeUnit.SECONDS);
+ assertNotNull(intent);
+ }
+
+ private Context getRandomContext() {
+ Long randomTicker = Math.round(Math.random() * 100);
+ final Context context = new Context();
+ JSONObject id = new JSONObject();
+ id.put("ticker", String.format("%d", randomTicker));
+ context.setId(id);
+ context.setType("java");
+ context.setName("java");
+ return context;
+ }
+}
diff --git a/src/test/java/com/openfin/desktop/NotificationTest.java b/src/test/java/com/openfin/desktop/NotificationTest.java
index 44f5765..eeb0fbf 100644
--- a/src/test/java/com/openfin/desktop/NotificationTest.java
+++ b/src/test/java/com/openfin/desktop/NotificationTest.java
@@ -47,128 +47,4 @@ public static void teardown() throws Exception {
TestUtils.teardownDesktopConnection(desktopConnection);
}
- @Test
- public void notificationEventListenersWork() throws Exception {
- CountDownLatch onShowLatch = new CountDownLatch(1);
- CountDownLatch onCloseLatch = new CountDownLatch(1);
-
- NotificationOptions options = new NotificationOptions(notification_url);
- options.setTimeout(1000);
- options.setMessageText("Unit test for notification");
- new Notification(options, new NotificationListener() {
- @Override
- public void onClick(Ack ack) {
- logger.debug("onClick for notification");
- }
-
- @Override
- public void onClose(Ack ack) {
- logger.debug("onClose for notification");
- onCloseLatch.countDown();
- }
-
- @Override
- public void onDismiss(Ack ack) {
- logger.debug("onDismiss for notification");
- onCloseLatch.countDown();
- }
-
- @Override
- public void onError(Ack ack) {
- logger.error("onError for notification");
- }
-
- @Override
- public void onMessage(Ack ack) {
- logger.debug("onMessage for notification");
- }
-
- @Override
- public void onShow(Ack ack) {
- logger.debug("onShow for notification");
- onShowLatch.countDown();
- }
- }, desktopConnection, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- }
- @Override
- public void onError(Ack ack) {
- logger.error(ack.getReason());
- fail("onError");
- }
- });
-
- onShowLatch.await(5, TimeUnit.SECONDS);
- onCloseLatch.await(5, TimeUnit.SECONDS);
- assertEquals(onShowLatch.getCount(), 0);
- assertEquals(onCloseLatch.getCount(), 0);
- }
-
- @Test
- public void sendMessage() throws Exception {
- CountDownLatch latch = new CountDownLatch(1);
- NotificationOptions options = new NotificationOptions(notification_url);
- options.setMessage(new JSONObject("{message: \"JSONMessage\"}"));
- //options.setMessageText("Notification Text");
- options.setTimeout(1000);
-
- NotificationListener nListener = new NotificationListener() {
-
- @Override
- public void onClick(Ack ack) {
- }
-
- @Override
- public void onClose(Ack ack) {
- }
-
- @Override
- public void onDismiss(Ack ack) {
- }
-
- @Override
- public void onError(Ack ack) {
- logger.error("onError for notification");
- }
-
- @Override
- public void onMessage(Ack ack) {
- logger.info("onMessage");
- latch.countDown();
- }
-
- @Override
- public void onShow(Ack ack) {
- }
- };
-
- AckListener ackListener = new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- }
-
- @Override
- public void onError(Ack ack) {
- logger.error(ack.getReason());
- }
- };
-
- Notification n = new Notification(options, nListener, desktopConnection, ackListener);
- n.sendMessage(new JSONObject("{message: \"JSONMessage2\"}"), new AckListener() {
-
- @Override
- public void onSuccess(Ack ack) {
- latch.countDown();
- }
-
- @Override
- public void onError(Ack ack) {
- logger.error("onError for sendMessage");
- }
- });
- latch.await(10, TimeUnit.SECONDS);
- assertEquals(0, latch.getCount());
-
- }
}
diff --git a/src/test/java/com/openfin/desktop/OpenFinRuntimeTest.java b/src/test/java/com/openfin/desktop/OpenFinRuntimeTest.java
index c9b593a..a741f7a 100644
--- a/src/test/java/com/openfin/desktop/OpenFinRuntimeTest.java
+++ b/src/test/java/com/openfin/desktop/OpenFinRuntimeTest.java
@@ -12,6 +12,7 @@
import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,7 +49,7 @@ public static void teardown() throws Exception {
public void getDeviceId() throws Exception {
logger.debug("start getDeviceId");
CountDownLatch latch = new CountDownLatch(1);
- runtime.getDeviceId(new AckListener() {
+ runtime.getMachineId(new AckListener() {
@Override
public void onSuccess(Ack ack) {
if (ack.isSuccessful()) {
@@ -398,6 +399,8 @@ public void onError(Ack ack) {
}
}
+ // this test does not work anymore with Secure By Default in place
+ @Ignore
@Test
public void startAndTerminateExternalProcess() throws Exception {
CountDownLatch startLatch = new CountDownLatch(1);
diff --git a/src/test/java/com/openfin/desktop/SnapshotTest.java b/src/test/java/com/openfin/desktop/SnapshotTest.java
new file mode 100644
index 0000000..d3513e1
--- /dev/null
+++ b/src/test/java/com/openfin/desktop/SnapshotTest.java
@@ -0,0 +1,120 @@
+package com.openfin.desktop;
+
+import com.openfin.desktop.snapshot.SnapshotSourceProvider;
+import org.json.JSONObject;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+
+public class SnapshotTest implements SnapshotSourceProvider {
+
+ private static Logger logger = LoggerFactory.getLogger(SnapshotTest.class.getName());
+
+ private static final String DESKTOP_UUID = SnapshotTest.class.getName();
+ private static DesktopConnection desktopConnection;
+ private static OpenFinRuntime runtime;
+ private static final JSONObject SNAPSHOT_CONTENT = new JSONObject("{width: 123}");
+
+ private JSONObject randomSnapshot;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ logger.debug("starting");
+ desktopConnection = TestUtils.setupConnection(DESKTOP_UUID);
+ if (desktopConnection != null) {
+ runtime = new OpenFinRuntime(desktopConnection);
+ }
+ }
+
+ @AfterClass
+ public static void teardown() throws Exception {
+ TestUtils.teardownDesktopConnection(desktopConnection);
+ }
+
+ @Test
+ public void initProviderThenCreateClient() throws Exception {
+ CountDownLatch latch = new CountDownLatch(2);
+ final String appUuid = "initProviderThenCreateClient";
+ desktopConnection.getSnapshotSource().initSnapshotSourceProviderAsync(appUuid, this).thenAccept(provider -> {
+ logger.debug("Snapshot provider created");
+ latch.countDown();
+ });
+ desktopConnection.getSnapshotSource().createSnapshotSourceClientAsync(appUuid).thenAccept(client -> {
+ logger.debug("Snapshot client created");
+ latch.countDown();
+ });
+
+ latch.await(5, TimeUnit.SECONDS);
+
+ assertEquals("initProviderThenCreateClient timeout", latch.getCount(), 0);
+ }
+
+ @Test
+ public void initProviderThenCreateClientThenGetSnapshot() throws Exception {
+ CountDownLatch latch = new CountDownLatch(2);
+ final String appUuid = "initProviderThenCreateClientThenGetSnapshot";
+ desktopConnection.getSnapshotSource().initSnapshotSourceProviderAsync(appUuid, this).thenAccept(provider -> {
+ logger.debug("Snapshot provider created");
+ latch.countDown();
+ });
+
+ desktopConnection.getSnapshotSource().createSnapshotSourceClientAsync(appUuid).thenAccept(client -> {
+ client.getSnapshotAsync().thenAccept(snapshot -> {
+ if (SNAPSHOT_CONTENT.toString().equals(snapshot.toString())) {
+ latch.countDown();
+ }
+ });
+ });
+
+ latch.await(5, TimeUnit.SECONDS);
+
+ assertEquals("initProviderThenCreateClientThenGetSnapshot timeout", latch.getCount(), 0);
+ }
+
+ @Test
+ public void initProviderThenCreateClientThenApplySnapshot() throws Exception {
+ CountDownLatch latch = new CountDownLatch(2);
+ final JSONObject random = new JSONObject(String.format("{value: %f}", Math.random()));
+ final String appUuid = "initProviderThenCreateClientThenApplySnapshot";
+ desktopConnection.getSnapshotSource().initSnapshotSourceProviderAsync(appUuid, this).thenAccept(provider -> {
+ latch.countDown();
+ });
+
+ desktopConnection.getSnapshotSource().createSnapshotSourceClientAsync(appUuid).thenAccept(client -> {
+ client.applySnapshotAsync(random).thenAccept(ack -> {
+ client.getSnapshotAsync().thenAccept(snapshot -> {
+ if (random.toString().equals(snapshot.toString())) {
+ latch.countDown();
+ }
+ });
+
+ });
+ });
+
+ latch.await(5, TimeUnit.SECONDS);
+
+ assertEquals("initProviderThenCreateClientThenGetSnapshot timeout", latch.getCount(), 0);
+ }
+
+ @Override
+ public JSONObject getSnapshot() {
+ if (this.randomSnapshot != null) {
+ return this.randomSnapshot;
+ } else {
+ return SNAPSHOT_CONTENT;
+ }
+ }
+
+ @Override
+ public void applySnapshot(JSONObject snapshot) {
+ this.randomSnapshot = snapshot;
+ }
+}
diff --git a/src/test/java/com/openfin/desktop/SystemTest.java b/src/test/java/com/openfin/desktop/SystemTest.java
index 66015cd..135e02d 100644
--- a/src/test/java/com/openfin/desktop/SystemTest.java
+++ b/src/test/java/com/openfin/desktop/SystemTest.java
@@ -50,7 +50,7 @@ public static void teardown() throws Exception {
@Test
public void getDeviceId() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
- runtime.getDeviceId(new AckListener() {
+ runtime.getMachineId(new AckListener() {
@Override
public void onSuccess(Ack ack) {
if (ack.isSuccessful()) {
@@ -393,6 +393,8 @@ public void onError(Ack ack) {
}
}
+ // this test does not work anymore with Secure By Default in place
+ @Ignore
@Test
public void startAndTerminateExternalProcess() throws Exception {
CountDownLatch startLatch = new CountDownLatch(1);
@@ -463,7 +465,6 @@ public void onError(Ack ack) {
assertEquals("getEnvironmentVariables timeout", latch.getCount(), 0);
}
- @Ignore
@Test
public void deleteCacheOnRestart() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
@@ -513,34 +514,6 @@ public void restartRuntime() throws Exception {
assertEquals(version1, version2);
}
- @Test
- public void customRdmAssetUrls() throws Exception {
- TestUtils.teardownDesktopConnection(desktopConnection);
- String rdmUrl = "https://rdm.openfin.co/services";
- String assetsUrl = "https://cdn.openfin.co/release";
- desktopConnection = TestUtils.setupConnection(DESKTOP_UUID, rdmUrl, assetsUrl);
- runtime = new OpenFinRuntime(desktopConnection);
- CountDownLatch latch = new CountDownLatch(1);
- runtime.getConfig(null, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- if (ack.isSuccessful()) {
- JSONObject data = (JSONObject) ack.getData();
- if (rdmUrl.equals(data.getString("rdmUrl")) && assetsUrl.equals(data.getString("assetsUrl"))) {
- latch.countDown();
- }
- }
- }
- @Override
- public void onError(Ack ack) {
- logger.error(ack.getReason());
- }
- });
- latch.await(5, TimeUnit.SECONDS);
- assertEquals("getConfig timeout", latch.getCount(), 0);
-
- }
-
@Test
public void getRuntimeInfo() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
diff --git a/src/test/java/com/openfin/desktop/TestUtils.java b/src/test/java/com/openfin/desktop/TestUtils.java
index ec12490..a60b4c8 100644
--- a/src/test/java/com/openfin/desktop/TestUtils.java
+++ b/src/test/java/com/openfin/desktop/TestUtils.java
@@ -38,9 +38,6 @@ public class TestUtils {
logger.debug(String.format("Runtime version %s", runtimeVersion));
}
- public static DesktopConnection setupConnection(String connectionUuid) throws Exception {
- return setupConnection(connectionUuid, null, null);
- }
public static DesktopConnection setupConnection(String connectionUuid, RuntimeConfiguration configuration) throws Exception {
logger.debug("starting from Runtime configuration");
CountDownLatch connectedLatch = new CountDownLatch(1);
@@ -99,7 +96,7 @@ public void onOutgoingMessage(String message) {
return desktopConnection;
}
- public static DesktopConnection setupConnection(String connectionUuid, String rdmUrl, String assetsUrl) throws Exception {
+ public static DesktopConnection setupConnection(String connectionUuid) throws Exception {
logger.debug("starting");
CountDownLatch connectedLatch = new CountDownLatch(1);
disconnectedLatch = new CountDownLatch(1);
@@ -113,13 +110,12 @@ public static DesktopConnection setupConnection(String connectionUuid, String rd
DesktopConnection desktopConnection = new DesktopConnection(connectionUuid);
RuntimeConfiguration configuration = new RuntimeConfiguration();
configuration.setRuntimeVersion(runtimeVersion);
+ configuration.setMaxMessageSize(738320);
String args = java.lang.System.getProperty("com.openfin.test.runtime.additionalRuntimeArguments");
if (args != null) {
configuration.setAdditionalRuntimeArguments(args);
}
configuration.setDevToolsPort(9090);
- configuration.setRdmURL(rdmUrl);
- configuration.setRuntimeAssetURL(assetsUrl);
configuration.setLicenseKey("JavaAdapterJUnitTests");
desktopConnection.connect(configuration, new DesktopStateListener() {
@Override
@@ -303,15 +299,7 @@ public void eventReceived(ActionEvent actionEvent) {
};
addEventListener(application, "closed", listener);
- application.close(new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- }
- @Override
- public void onError(Ack ack) {
- logger.error(ack.getReason());
- }
- });
+ application.close();
stoppedLatch.await(5, TimeUnit.SECONDS);
assertEquals("Close application timeout " + application.getUuid(), stoppedLatch.getCount(), 0);
}
diff --git a/src/test/java/com/openfin/desktop/WindowPositionTest.java b/src/test/java/com/openfin/desktop/WindowPositionTest.java
index 4bfcee0..f26143e 100644
--- a/src/test/java/com/openfin/desktop/WindowPositionTest.java
+++ b/src/test/java/com/openfin/desktop/WindowPositionTest.java
@@ -59,10 +59,9 @@ public static void teardown() throws Exception {
TestUtils.teardownDesktopConnection(desktopConnection);
}
- @Ignore("for now")
@Test
public void saveWindowStateWithRuntimeRestart() throws Exception {
- int repeat = 30;
+ int repeat = 3;
String value = java.lang.System.getProperty("com.openfin.desktop.WindowPositionTest.repeat");
if (value != null) {
repeat = Integer.parseInt(value);
diff --git a/src/test/java/com/openfin/desktop/WindowTest.java b/src/test/java/com/openfin/desktop/WindowTest.java
index c7b2d09..6e65f60 100644
--- a/src/test/java/com/openfin/desktop/WindowTest.java
+++ b/src/test/java/com/openfin/desktop/WindowTest.java
@@ -213,85 +213,6 @@ public void onError(Ack ack) {
TestUtils.closeApplication(application);
}
- @Test
- public void dockAndUndock() throws Exception {
- String childName = "docking test";
- Application application = TestUtils.runApplication(TestUtils.getAppOptions(null), desktopConnection);
- Window mainWindow = application.getWindow();
- WindowOptions childOptions = TestUtils.getWindowOptions(childName, guest_url);
- Window childWindow = TestUtils.createChildWindow(application, childOptions, desktopConnection);
- WindowBounds beforeMoveBounds = TestUtils.getBounds(childWindow);
- CountDownLatch joinLatch = new CountDownLatch(1);
- childWindow.joinGroup(mainWindow, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- if (ack.isSuccessful()) {
- joinLatch.countDown();
- }
- }
- @Override
- public void onError(Ack ack) {
- logger.error(String.format("onError %s", ack.getReason()));
- }
- });
- joinLatch.await(3, TimeUnit.SECONDS);
- assertEquals(joinLatch.getCount(), 0);
-
- CountDownLatch groupInfoLatch = new CountDownLatch(2);
- mainWindow.getGroup(result -> {
- for (Window window : result) {
- if (window.getUuid().equals(mainWindow.getUuid()) && window.getName().equals(mainWindow.getName())) {
- groupInfoLatch.countDown();
- }
- else if (window.getUuid().equals(childWindow.getUuid()) && window.getName().equals(childWindow.getName())) {
- groupInfoLatch.countDown();
- }
- }
- }, new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- }
- @Override
- public void onError(Ack ack) {
- }
- });
- groupInfoLatch.await(3, TimeUnit.SECONDS);
- assertEquals(groupInfoLatch.getCount(), 0);
-
- int leftBy = 20, topBy = 30;
- TestUtils.moveWindowBy(mainWindow, leftBy, topBy);
- // child window sohuld move with main window since they are docked
- WindowBounds afterMoveBounds = TestUtils.getBounds(childWindow);
- int topAfterDockMove = afterMoveBounds.getTop(), leftAfterDockMove = afterMoveBounds.getLeft();
- assertEquals(afterMoveBounds.getTop() - beforeMoveBounds.getTop(), topBy);
- assertEquals(afterMoveBounds.getLeft() - beforeMoveBounds.getLeft(), leftBy);
-
- // undock by leaving the group
- CountDownLatch undockLatch = new CountDownLatch(1);
- childWindow.leaveGroup(new AckListener() {
- @Override
- public void onSuccess(Ack ack) {
- if (ack.isSuccessful()) {
- undockLatch.countDown();
- }
- }
- @Override
- public void onError(Ack ack) {
- logger.error(String.format("onError %s", ack.getReason()));
- }
- });
- undockLatch.await(5, TimeUnit.SECONDS);
- assertEquals(undockLatch.getCount(), 0);
- TestUtils.moveWindowBy(mainWindow, leftBy, topBy);
- // child window should not move afer leaving group
- afterMoveBounds = TestUtils.getBounds(childWindow);
- assertEquals(afterMoveBounds.getLeft().intValue(), leftAfterDockMove);
- assertEquals(afterMoveBounds.getTop().intValue(), topAfterDockMove);
-
- TestUtils.closeApplication(application);
- }
-
-
@Test
public void animateMove() throws Exception {
ApplicationOptions options = TestUtils.getAppOptions(null);
@@ -721,7 +642,6 @@ public void onError(Ack ack) {
TestUtils.closeApplication(application);
}
- @Ignore
@Test
public void getSetZoomLevel() throws Exception {
double level = -1.5;