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.
In the File Explorer view, the folder contains the following compressed files:
Application Modules
- tibco_bw_sample_core_modularity_processandjavcodemodularity_app.zip
- tibco_bw_sample_core_modularity_processandjavcodemodularity_importpackage.zip
- tibco_bw_sample_core_modularity_processandjavcodemodularity_subprocesscall.zip
Shared Module
- tibco_bw_sample_core_modularity_processandjavcodemodularity_shared.zip
The three scenarios below demonstrate calling Java invoke (in a Shared Module) from a Java Invoke activity in an Application module using Required Modules, Import-Package, Call Process.
- For the Java invoke to work, create an 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.
- To create a token:
- Log in to https://apps.twitter.com/ with your Twitter account.
- Click Create New App.
- Provide Name and Description and create your Twitter application. Your application is successfully created.
- Go to the Keys and Access Tokens tab and click Create my access token. Your application access token is successfully generated.
- Click
Test OAuth. The OAuth Settings page is generated with the following tokens:
- Consumer key
- Consumer secret
- Access token
- Access token secret
Scenario 1
- Procedure
- In the
samples directory in the
File Explorer view, expand
core >
modularity >
ProcessAndJavaCodeModularity.
You should see the following projects:
- Double-click tibco_bw_sample_core_modularity_processandjavacodemodularity_shared.zip to expand it in the Project Explorer.
- Double-click tibco_bw_sample_core_modularity_processandjavacodemodularity_app.zip to expand it in the Project Explorer.
- In Project Explorer, expand the tibco_bw_sample_core_modularity_processandjavacodemodularity_app project. See Accessing Samples for more information.
- Fully expand the Processes directory and double-click ModularJavaCode.bwp to open it in the Process Editor pane.
- Click .
- In the left-hand tree of Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
- Click the Applications tab and then click the Deselect All button if you have multiple applications. Select the checkbox next to tibco_bw_sample_core_modularity_processandjavacodemodularity_app_application.
- Click
Debug. This runs the sample in Debug mode.
The console window shows the log messages such as Started BW Application [tibco_bw_sample_core_modularity_processandjavcodemodularity_app_application:1.0]
User Query=Lady Gaga.
In finally
14:16:50.792 INFO [bwEngThread:In-Memory Process Worker-1] c.t.b.p.g.L.t.Log - **********************Output from Appmodule-Required Modules + Shared module***************************
The log contains a collection of relevant Tweets matching a specified query. In this case, the query is "Lady Gaga"
Scenario 2
- Procedure
- Double-click tibco_bw_sample_core_modularity_processandjavacodemodularity_importpackage.zip to expand it in the Project Explorer.
- In Project Explorer, expand the tibco_bw_sample_core_modularity_processandjavacodemodularity_importpackage project. See Accessing Samples for more information.
- Fully expand the Processes directory and double-click ModularJavaCodeImportPkg.bwp to open it in the Process Editor pane.
- Click .
- In the left-hand tree of the Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
- Click the Applications tab and then click the Deselect All button if you have multiple applications. Select the checkbox next to tibco_bw_sample_core_modularity_processandjavacodemodularity_importpackage_application.
- Click Debug. This runs the sample in Debug mode.
Scenario 3
- Procedure
- Double-click tibco_bw_sample_core_modularity_processandjavacodemodularity_subprocesscall.zip to expand it in the Project Explorer.
- In Project Explorer, expand the tibco_bw_sample_core_modularity_processandjavacodemodularity_subprocesscall project. See Accessing Samples for more information.
- Fully expand the Processes directory and double-click ModularJavaCodeSubProc.bwp to open it in the Process Editor pane.
- Click .
- In the left-hand tree of Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
- Click the Applications tab and then click the Deselect All button if you have multiple applications. Select the checkbox next to tibco_bw_sample_core_modularity_processandjavacodemodularity_subprocesscall_application.
- Click
Debug. This runs the sample in Debug mode.
You should see the following in the Console log: Started BW Application [tibco_bw_sample_core_modularity_processandjavcodemodularity_subprocesscall_application:1.0]
Output from Appmodule-SubProcess Call + Shared module
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 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 is then displayed in a Log Activity.
- 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
- 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 run 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.
The following subprocess 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 that is then passed to SearchTwitter activity. SearchTwitter activity requires the following five 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 above. You can change the values of these module properties from Module Descriptors > Module Properties.
The process for Scenario 1 and Scenario two is very similar to the subprocess of Scenario 3, except that Scenario 1 and two have a Timer activity as a process starter instead of a service.
Troubleshooting
- 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.