Using Modularity with the Java Palette

Three application modules and one shared module demonstrate calling from a Java Invoke activity and an Invoke activity through a Call Process.

Prerequisites

  1. For the Java invoke to work, create a new application on https://apps.twitter.com/ and generate Access Token, Access Token Secret, Consumer Key, Consumer Secret for the app created, and use it in the parameters for SearchTwitter activity.
  2. To create a token:
    1. Login to https://apps.twitter.com/ with your Twitter account.
    2. Click Create New App.
    3. Provide Name and Description and create your Twitter application. Your application is successfully created.
    4. Go to the API Keys tab and click Create my access token. Your application access token is successfully generated.
    5. Click Test OAuth. The OAuth Settings page is generated with the following tokens:
      • Consumer key
      • Consumer secret
      • Access token
      • Access token secret

Procedure

  1. In the samples directory, select core > modularity > ProcessAndJavaCodeModularity. The following projects are visible:
    • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.app
    • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.importpackage
    • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared
    • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.subprocesscall
  2. First click on tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared and then click on the remaining three projects.
  3. In Project Explorer, expand the tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.app project. For more information, see Accessing Samples.
  4. Set the default ApplicationProfile to match the OS you are running on. For more information, see Setting the Default Application Profile.
  5. Fully expand the Processes directory and double-click Process.bwp.
  6. Click Run > Debug Configurations.
  7. At the left hand tree of Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
  8. Click the Applications tab and then click the Deselect All button if you have multiple applications. Select the check box next to tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.app.application.
  9. Click Debug. This runs the sample in Debug mode.
    The console window shows the log messages such as application module started successfully and application started successfully.
  10. Run tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.importpackage.application and tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.subprocesscall.application in a similar way, one after the other.

Result

You see the following files generated in the C:\tmp\ProcessAndJavaCodeModularity folder after running all the projects one after the other.
  • AppModule-RequiredModules-Output.log generated by Scenario 1 described in Understanding the Configuration section.
  • AppModule-ImportPackage-Output.log generated by Scenario 2 described in Understanding the Configuration section.
  • AppModule-SubProcessCall-Output.log generated by Scenario 3 described in Understanding the Configuration section.

These files contains a collection of relevant Tweets matching a specified query. In this case, it is "Lady Gaga".

Understanding the Configuration

The sample has three Application Modules and one Shared Module:

  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.app: This is an application module that contains the TIBCO ActiveMatrix BusinessWorks Processes. It uses the Java invoke in the shared module tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared. The application module refers to the shared module using the Require-Bundle Manifest header. The sample Java Invoke activity uses the Java invoke to connect to Twitter to search for the string "Lady Gaga". Twitter returns a payload of tweets matching the search string, which the Write To File activity then writes to a file in a temporary directory.
  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.importpackage: This is similar to the tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.app module, except here the application module uses Imported Packages instead of Required Modules in Module Descriptors > Dependencies.
  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.subprocesscall: This is an application module that calls the web service hosted in the shared module.
  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared: This is a shared module that contains code to make a REST call to Twitter to search for a specified search term. Since this is a shared module it cannot be executed by itself. However, it can be called from an application module such as tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.app, tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.importpackage, and tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.subprocesscall. This functionality is exposed by the shared module both as a Java class and a web service, which can be invoked by an Invoke activity.

Scenario 1

Modules Executed

  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared
  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.app

This scenario demonstrates calling Java invoke (in a Shared Module) from a Java Invoke activity in an Application module. The dependency on the Java package in the Shared Module is modeled using Required Modules in Module Descriptors > Dependencies.

Scenario 2

Modules Executed

  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared
  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.importpackage

This scenario shows how to call the Java invoke (in a shared module) from a Java Invoke activity in an application module. The dependency on the Java package in the shared module is modeled using Import-Package in Module Descriptors > Dependencies.

Scenario 3

Modules Executed

  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared
  • tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.subprocesscall

This scenario shows how to call the Java invoke (in a shared module) from an Invoke activity in the application module through a Call Process. There is no Java package or bundle dependency on the shared module.

The following sub process is in the shared module:

TwitterSearch SubProcess: This subprocess is invoked from tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.subprocesscall. In this subprocess, there are two JavaInvoke Activities - OpenTwitterConnection and SearchTwitter. The source code for these activities is located under src directory under com.example.TwitterConnection package in the same project.

OpenTwitterConnection activity creates a TwitterConnection object which is then passed to SearchTwitter activity. SearchTwitter activity requires the following 5 input parameters:

  • SearchString
  • AccessToken
  • AccessTokenSecret
  • ConsumerKey
  • ConsumerSecret

SearchString signifies the string used by the user to search tweets. In this project, the SearchString is "Lady Gaga". This SearchString is passed from the main process in tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.subprocesscall.

AccessToken, AccessTokenSecret, ConsumerKey, and ConsumerSecret are required for authentication to the Twitter Account.

The steps to generate these are described in the Prerequisites section. You can change the values of these module properties from Module Descriptors > Module Properties.

Note: The Java invoke uses Twitter API v1.1 which requires the request to be authenticated using OAuth.



The process for Scenario 1 and Scenario 2 is very similar to the subprocess of Scenario 3, except that Scenario 1 and 2 have a Timer activity as a process starter instead of a service.

Note: If you open Application Modules especially subprocesscall application module before the shared module, then you may encounter errors such as Import Configuration Error, Process Reference configuration Error, Application configuration Error, and so on.
  • If you receive the following error message:

    "401:Authentication credentials (https://dev.twitter.com/docs/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync."

    make sure you have generated Access Token, Access Token Secret, Consumer Key, Consumer Secret as per the steps specified in the Prerequisites section

  • If you see any problem markers in the project, make sure tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared is imported into the workspace as all other application modules depend on this shared module.