This sample showcases the use of JEE applications as SCA component implementation resulting in a SCA component and opening doors for Java EE applications to take advantage of SCA programming model with little or no change to its implementation code. This sample demonstrates stateless session beans being exposed as SCA services, EJB reference being rewired to SCA references and JEE components such as stateless session beans and servlets to access SCA artifacts like SCA property and SCA reference through use of annotations.
The sample has three installable binaries:
HelloJeeEar.ear : Contains an EJB Bean named HelloJeeSBean and two servlets named JeeEjbClient to lookup and
invoke HelloJeeSBean as a regular Java EE client and JeeScaClient to lookup and invoke the same HelloJeeSBean as
a SCA service. This Java EE application and its modules do not contain any SCA artifacts like SCA annotations or
application composite files.
HelloJeeEnhancedEar.ear : Contains an EJB Bean named HelloJeeEnhancedSBean and two servlets named JeeEEjbClient
to lookup and invoke HelloJeeEnhancedSBean as a regular Java EE client and JeeEScaClient to lookup and invoke the same
HelloJeeEnhancedSBean as a SCA service. Additionally, JeeEScaClient uses @Reference annotation to locate and invoke
a SCA service, a @Property annotation to obtain value from SCA domain, invokes operations on HelloJeeEnhancedSBean
that invokes EJB reference (using a @EJB annotation) and another EJB reference that is overridden by an equivalent
SCA reference of same QName and offering the same operation.
HelloJeeSca.jar : Contains a SCA service named HelloJeeScaService that is referred from JeeEScaClient and
is used to override the EJB reference in HelloJeeEnhancedSBean.
There are no notable design limitations specific to this sample. For a list of JEE integration scenarios supported by SCA refer to the info center documentation.
Compile and build the installable artifacts using the provided ANT build script.
Issue the following command to build the artifacts: <WAS_HOME>\profiles\<PROFILE_NAME>\bin\ws_ant
Example command: C:\WebSphere\AppServer\profiles\AppSrv01\bin\ws_ant
Verify that the build completes without error and the following atrifacts have been created in <SCA_SAMPLE_HOME>\HelloJee\target
Automated install: To quickly and easily install this sample and bypass the manual steps following, you can use the automated install. Run the following command from the Hello JEE sample directory:
<WAS_HOME>\profiles\<PROFILE_NAME>\bin\ws_ant install
<WAS_HOME>\profiles\<PROFILE_NAME>\bin\ws_ant start
Manual install
Install and start the HelloJee Sample application through the command line using the wsadmin BLA commands.
First open a command window and issue the following command
<WAS_HOME>\profiles\<PROFILE_NAME>\bin\wsadmin
Example command:
C:\WebSphere\AppServer\profiles\AppSrv01\bin\wsadmin
Once wsadmin starts, issue the following commands:
$AdminTask createEmptyBLA {-name HelloJeeBla}
$AdminTask importAsset {-source <SCA_SAMPLE_HOME>\HelloJee\target\HelloJeeEar.ear -storageType FULL}
$AdminTask importAsset {-source <SCA_SAMPLE_HOME>\HelloJee\target\HelloJeeEnhancedEar.ear -storageType FULL}
$AdminTask importAsset {-source <SCA_SAMPLE_HOME>\HelloJee\target\HelloJeeSca.jar -storageType FULL}
$AdminTask addCompUnit {-blaID HelloJeeBla -cuSourceID HelloJeeEar.ear }
$AdminConfig save
$AdminTask addCompUnit {-blaID HelloJeeBla -cuSourceID HelloJeeEnhancedEar.ear }
$AdminConfig save
$AdminTask addCompUnit {-blaID HelloJeeBla -cuSourceID HelloJeeSca.jar }
$AdminConfig save
$AdminTask startBLA {-blaID HelloJeeBla}
The sample ear application contains various servlets, showcasing the availability of EJB services in SCA domain as SCA services and use of Reference and Property annotation, each deployed under a different contextRoot. Use the links listed below to run the respective tests.
Results: The returned string identifies the fully qualified package name of the method that processed the service operation to identify where the request ended up.
Specific to your environment:
Run the non-SCA enhanced JEE sample to invoke EJB in a regular JEE way: http://localhost:9080/HelloJeeWeb/JeeEjbClient
Result: You should see a response page that displays the following information
WebSphere SCA-JEE HelloJee Sample
JEE application (non-SCA-Enhanced)
Hello from :sca.jee.HelloJeeSBean.getSBeanString():
Run the non-SCA enhanced JEE sample to invoke EJB as a SCA service: http://localhost:9080/HelloJeeWeb/JeeScaClient
Result: You should see a response page similar to 1.
Run the SCA enhanced JEE sample to invoke EJB in a regular JEE way: http://localhost:9080/HelloJeeEnhancedWeb/JeeEEjbClient
Result: You should see a response page that displays the following information
WebSphere SCA-JEE HelloJee Sample
JEE application with SCA annotations (SCA-Enhanced)
Hello from :sca.jee.HelloJeeEnhancedSBean.getSBeanString():
Run the SCA enhanced JEE sample: http://localhost:9080/HelloJeeEnhancedWeb/JeeEScaClient
Result: You should see a response page displaying the following information:
WebSphere SCA-JEE HelloJee Sample
JEE application with SCA annotations (SCA-Enhanced)
Invoking HelloJeeEnhancedSBean as SCA service returned :
Hello from :sca.jee.HelloJeeEnhancedSBean.getSBeanString():
Invoking EJB reference from HelloJeeEnhancedSBean returned :
:sca.jee.HelloJeeEnhancedSBean:Hello from :sca.jee.HelloJeeReferencedBean.getSBeanString()::
Invoking EJB reference overridden with a SCA reference from HelloJeeEnhancedSBean returned :
:sca.jee.HelloJeeEnhancedSBean:Hello from :sca.jee.impl.HelloJeeScaServiceImpl.getSBeanString()::
Injected property in web module has
IBMWEB
From injected context in web module SCA service returned:
Hello from :sca.jee.impl.HelloJeeScaServiceImpl.getScaServiceString():
Stop and uninstall the HelloJee sample application through the command line using the wsadmin BLA commands.
First open a command window and issue the following command
<WAS_HOME>\profiles\<PROFILE_NAME>\bin\wsadmin
Example command:
C:\WebSphere\AppServer\profiles\AppSrv01\bin\wsadmin
Once wsadmin starts, issue the following commands:
$AdminTask stopBLA {-blaID HelloJeeBla}
$AdminTask deleteCompUnit {-blaID HelloJeeBla -cuID HelloJeeScaServiceComposite }
$AdminTask deleteCompUnit {-blaID HelloJeeBla -cuID HelloJeeEnhancedEar }
$AdminTask deleteCompUnit {-blaID HelloJeeBla -cuID HelloJeeEar }
$AdminTask deleteAsset {-assetID HelloJeeEar.ear }
$AdminTask deleteAsset {-assetID HelloJeeEnhancedEar.ear }
$AdminTask deleteAsset {-assetID HelloJeeSca.jar }
$AdminTask deleteBLA {-blaID HelloJeeBla}
$AdminConfig save
You can run the different parts of the sample by visiting the following URLs: