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.
- 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.
- To create a token:
- Login 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 API Keys 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
- Procedure
- In the
samples directory, select
core >
modularity >
ProcessAndJavaCodeModularity. The following projects are visible:
tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.apptibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.importpackagetibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.sharedtibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.subprocesscall
- First click tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.shared and then click the remaining three projects.
- In Project Explorer, expand the tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.app project. For more information, see Accessing Samples.
- Fully expand the Processes directory and double-click Process.bwp.
- Click Run > Debug Configurations.
- At 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 application module started successfully and application started successfully.
- 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.
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 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 . - 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.
Process
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 .
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 .
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.
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.
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, ensure
tibco.bw.sample.core.modularity.ProcessAndJavaCodeModularity.sharedis imported into the workspace as all other application modules depend on this shared module.