Enabling Managed Events

Openspace gadgets provide support for publishing managed events. If you want your gadget to communicate with other Openspace gadgets, you must enable support for managed events in your gadget.

Note: For more information about managed events see "Administering Managed Events" in TIBCO Openspace User’s Guide.

Procedure

  1. Add the following elements to the project module XML file (ProjectName.gwt.xml):
    <inherits name="com.google.gwt.json.JSON"/>
    <inherits name="com.google.gwt.xml.XML" />
    <inherits name="org.jsonmaker.gwt.Gwt_jsonmaker" />
    <inherits name="com.tibco.bpm.web.client.model.Model" />
  2. Ensure the generator is added to the gwt.xml
    <generate-with class="com.tibco.bpm.web.client.model.pagebus.rebind.ManagedEventGenerator">
    <when-type-assignable class="com.tibco.bpm.web.client.model.pagebus.hub.ManagedEvent"/>
    </generate-with>
  3. Create required ManagedEvent and ManagedEventHandler classes. See the following example classes:
    • com.tibco.bpm.web.client.model.managedevents.TemplateManagedEvent
      com.tibco.bpm.web.client.model.managedevents.TemplateManagedEventHandler
  4. Ensure the PageBus.js is injected using the Scriptinjector. Depending on how you are using GWT, the <script> tag may not be supported in the module gwt.xml file. You may receive an error similar to the one below when compiling:

    The Cross-Site-Iframe linker does not support <script> tags in the gwt.xml files. For your application to run correctly, you must include these tags in your host page directly.

    To do this, remove <script src="PageBus.js" /> from the project module XML file and add the PageBus.js file using another method. The ScriptInjector sample code below shows an example of how this can be done using the com.google.gwt.core.client.ScriptInjector class:

    import com.google.gwt.core.client.ScriptInjector;
    import com.google.gwt.core.client.ScriptInjector.FromUrl;
    protected static final String
    PAGEBUS_JS_LOCATION="http://sampleHost:9090/samplepath/PageBus.js";
    *
    * =====================================================
    * METHOD : loadPageBus
    * =====================================================
    */
    /**
    * The PageBus.js file must be loaded and injected because it cannot be
    * loaded via the module gwt.xml (ProjectName.gwt.xml) script tag:
    * <p/>
    * <code>
    *     &lt;script src="PageBus.js" /&gt;
    * <code/>
    * <p/>
    * The Cross-Site-Iframe linker does not support &lt;script&gt; tags in the gwt.xml files.
    */
    private void loadPageBus()
    {
    FromUrl fromUrl = ScriptInjector.fromUrl(PAGEBUS_JS_LOCATION);
    fromUrl.setCallback(new Callback<Void, Exception>()
    {
    public void onFailure(Exception reason)
    {
    Window.alert("Script load failed for: " + PAGEBUS_JS_LOCATION);
    }
    public void onSuccess(Void result)
    {
    buildLayout();
    // Verify that PageBus.js is injected and create the ManagedEventClient.
    if (isPageBusInjected())
    {
    sampleGadgetManagedEventClient = new SampleGadgetManagedEventClient("test");
    }
    else
    {
    Window.alert("ManagedEventClient cannot load because PageBus.js is not injected.");
    }
    }
    });
    // If setWindow is not called with the correct $wnd returned from the
    // getReferencedWindow() JSNI method below then the PageBus code is
    // not injected on the correct window and the subsequent
    // ManagedEventClient calls will fail with $wnd.OpenAjax is undefined.
    fromUrl.setWindow(getReferencedWindow());
    fromUrl.inject();
    }
    /*
    * =====================================================
    * METHOD : getReferencedWindow
    * =====================================================
    */
    /**
    * Returns the correctly referenced nested frame window that the GWT compiled
    * script runs in.  See the GWT document at:
    * <p/>
    *     https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI
    * <p/>
    *   When accessing the browser's window and document objects from JSNI, you must
    *   reference them as $wnd and $doc, respectively. Your compiled script runs in a
    *   nested frame, and $wnd and $doc are automatically initialized to correctly refer
    *   to the host page's window and document.
    *
    * @return The correctly referenced nested frame window.
    */
    public native JavaScriptObject getReferencedWindow()
    /*-{
    return $wnd;
    }-*/;
    /*
    * =====================================================
    * METHOD : isPageBusInjected
    * =====================================================
    */
    /**
    * Test that the PageBus.js file has been loaded by verifying that
    * the wnd.OpenAjax property is initialized.
    * @return true if $wnd.OpenAjax is not undefined.
    */
    public native boolean isPageBusInjected()
    /*-{
    return $wnd.OpenAjax != undefined;
    }-*/;
  5. Create a HubPolicy.xml file that includes Publish and Subscribe elements matching the event topics used by the application.

    The HubPolicy.xml file is deployed with the application so that the URL to this file can be specified when the gadget is contributed in Openspace. For example, include the HubPolicy.xml in the "public" folder in your project module root path.

    The URI value must be JavaScript encoded as shown below:

    var origUri = "http://<AMXBPMHost>:8080/gadgetserver/gadgets/ifr?view=home&url=http://<gadgetxml_host>:<gadgetxml_port>/sample/testgadget/TestGadget.gadget.xml";
    var encodedUri = encodeURIComponent(origUri);

    Use the value of the encodedUri. Please refer to the HubPolicy.xml file provided in the sample.

    The base URI the Iframe loads must be an exact string match to the value used to set the HubPolicy domain URI (before it is encoded). The query_string may be included in the HubPolicy URI but does not need to match exactly.

    The base URI is the first part of the URI up to the question mark character. The question mark character is a separator between the base URI and the query string. For example:

    http://example_path/?query_string

    where example_path might consist of host, port, program and so on.

    An example of a base URI is shown below.

    http://amxbpmhost:8080/gadgetserver/gadgets/ifr

    The base URI must be an exact string match to the URI set in the HubPolicy (before it is encoded). For example, if amxbpmhost is at IP address: 92.223.243.87, both of the following resolve to the same IP address:

    • http://92.223.243.87:8080/
    • http://amxbpmhost:8080/

      but the string values do not match. If the HubPolicy.xml file domain url is set using http://92.223.243.87:8080/ but the actual Iframe is loaded from http://amxbpmhost:8080/ these do not match and the gadget fails to load correctly.