You can use the Service Component Architecture (SCA) programming
model to invoke business services in Java Platform,
Enterprise Edition (Java EE) components.
About this task
The SCA programming model supports Java EE integration.
You can expose Enterprise JavaBeans (EJB)
stateless session beans as SCA services. You can take advantage of
SCA annotations to enable the Java EE components, such as session
beans, message driven beans, or Web components to consume SCA services.
You also can rewire EJB references to SCA services. Thus, you can
enable an existing Java EE component so that it is recognized as an
SCA component and so that the component can participate in an SCA
composite.
Procedure
- Use non-SCA enhanced
Java EE applications as SCA component implementations.
- Use SCA enhanced Java
EE applications as SCA component implementations.
For
this step, create an application.composite file.
Then, determine the Java EE component type that you want to consume
SCA services. Depending on the Java EE component type, use SCA annotations:
If your application uses security, specify security roles
and runAs identity in the Java EE application implementation instead
of in the composite. Authorization policy is enforced by the implementation.
- Rewire EJB references
to SCA references.
- Deploy an SCA composite using a Java EE application as
a component implementation.
You can deploy an SCA composite
that uses an implementation.jee defining a Java EE
application as a component implementation. Deploy the SCA composite
that uses the application as a component implementation along with
the enterprise archive (EAR) file. Add the SCA composite and Java
EE application as composition units of a business-level application.
- Import the EAR file as an asset.
- Import the SCA composite Java archive (JAR) file as
an asset.
- Create an empty business-level application.
- Add the EAR file asset to the business-level application.
- Add the SCA composite asset to the business-level application.
Map the SCA composite to the same target server as the EAR file.
- If you are rewiring EJB references, set the starting
weight of the EAR file to a greater value than the starting weight
of the SCA composite. The SCA composite then starts before the EAR
file.
When deploying an SCA JAR contribution that has a deployable
SCA composite with implementation.jee for one or
more of its SCA components, ensure that the following requirements
are met:
- Deploy the SCA deployable composite and all the Java EE applications
used for the SCA component implementation in the same business-level
application.
- Add all the Java EE applications referenced by the archive attribute
of the implementation.jee directive to the business-level
application before adding the SCA deployable composite.
- Map all the deployed components of an SCA business-level application
to the same target server or cluster.
- When using an SCA enhanced EAR file that requires injection of
values for SCA references, properties, context or component names
in Java EE modules such as stateless session beans, servlets, or JSP
files, the deployed SCA asset must start before the Java EE asset.
If necessary, set the weights of the composition units so that the
deployed SCA asset starts before the Java EE asset.
- If you update Java EE composition units, deploy the SCA composition
unit again to apply the changes in the SCA component that uses Java
EE implementation.
- Start the business-level application.
Results
You now have defined and deployed Java EE components to
take advantage of the SCA programming model. The SCA composite and
the EAR file are deployed and started, and the Java EE application
is able to participate in the SCA domain.
Invoke the EJB services
exposed as SCA services using the SCA programming model.
Example
The product provides the HelloJee sample to show how to
use SCA annotations within Java EE components so that these components
can consume SCA services. If you selected to install Samples during
creation of a profile enabled by the feature pack, the product adds
several SCA sample files to the app_server_root/samples/SCA and app_server_root/installableApps directories.
For details on deploying the HelloJee sample, refer to app_server_root/samples/SCA/HelloJee/documentation/readme.html.
Briefly,
to deploy the HelloJee sample, do the following:
- Import as assets the HelloJeeEar.ear, HelloJeeEnhancedEar.ear, HelloJeeSca.jar files.
You can build these files using the instructions in the readme.html file.
These files are also available in the app_server_root/installableApps directory.
- Create a business-level application named HelloJeeBla.
- Add the HelloJeeEar.ear and HelloJeeEnhancedEar.ear assets
to the business-level application.
- Add the HelloJeeSca.jar asset to the business-level
application. When adding the asset, ensure that it is targeted to
the same server or node as the EAR files added in step 3. If you are
adding the JAR file using the administrative console, ensure that
components HelloJeeEnhancedComponent and HelloJeeComponent are listed
on the Set Java EE composition unit relationships page. Also ensure
that HelloJeeEnhancedComponent associates with the HelloJeeEnhancedEar
composition unit and HelloJeeComponent associates with the HelloJeeEar
composition unit.
- Start the business-level application.
- Run the sample application. Open a Web browser on a URL that accesses
a sample. The following URLs use localhost for host
name and 9080 for port number. Use the host name
and WC_defaulthost port number that is correct for
your installation.
- Access the non-SCA enhanced EJB as is: http://localhost:9080/HelloJeeWeb/JeeEjbClient
- Access the non-SCA enhanced EJB as SCA service: http://localhost:9080/HelloJeeWeb/JeeScaClient
- Access the SCA enhanced EJB as is: http://localhost:9080/HelloJeeEnhancedWeb/JeeEEjbClient
- Access the SCA enhanced EJB service or reference as an SCA service
or reference and demonstrate SCA annotations: http://localhost:9080/HelloJeeEnhancedWeb/JeeEScaClient