Hello JEE Sample

Table of Contents

Overview

Affiliates Icon

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.

Architectural Diagram

Architectural Diagram

Prerequisites

  • This sample application requires that you have the WebSphere Application Server installed.
  • NOTE: This document will reference the location that these samples have been extracted to as <SCA_SAMPLE_HOME>.

Limitations

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.

Build

Build Icon

Compile and build the installable artifacts using the provided ANT build script.

  1. Open a command window and change to the <SCA_SAMPLE_HOME>\HelloJee directory.
  2. 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

  3. Verify that the build completes without error and the following atrifacts have been created in <SCA_SAMPLE_HOME>\HelloJee\target

    • HelloJeeEar.ear
    • HelloJeeEnhancedEar.ear
    • HelloJeeSca.jar

Install

Install Icon

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

NOTE: If the default port number for SOAP is not 8880 for your application server profile, please update the SOAP port number value in <SCA_SAMPLE_HOME>\common\manage-app.xml to match your profile.

Manual install

  1. Start WebSphere Application Server.
  2. Install the HelloJee Sample application from the Administrative Console.
    1. From the left navigation panel of the Administrative console, expand Applications, expand Application Types and select Assets.
    2. For each installable binary,
    3. select Import, specify the Local file system option and enter the Full path or use the browse button to select the binary and select next.
    4. select next and then select finish to import the installable binary.
    5. From the left navigation panel of the Administrative console, expand Applications, expand Application Types and select Business-level Applications.
    6. select new, type in the string "HelloJeeBla" (without double-quotes) into the Name field and select Apply.
    7. In the Deployed Assets panel, select Add and choose Add Asset from the drop down list. Choose HelloJeeEar.ear, select continue, select next, select next, select next and select finish. If the deployment completes without any errors, click save to save the session at this time.
    8. In the Business-level applications panel, select HelloJeeBla. Then in the Deployed Assets panel, select Add and choose Add Asset from the drop down list. Choose HelloJeeEnhancedEar.ear, select continue, select next, select next, select next and select finish. If the deployment completes without any errors, click save to save the session at this time.
    9. In the Business-level applications panel, select HelloJeeBla. Then in the Deployed Assets panel, select Add and choose Add Asset from the drop down list. Choose HelloJeeSca.jar, select continue, select next, make sure the composition unit is targeted to the same server/node as the EARs added earlier, select next, select next, ensure that two components(HelloJeeEnhancedComponent and HelloJeeComponent) are listed and are associated to HelloJeeEnhancedEar and HelloJeeEar respectively, then select next, select finish. If deployment succeeds, save session by clicking on save.
    10. From the left navigation panel of the Administrative console, expand Applications, expand Application Types and select Business-level Applications.
    11. Select HelloJeeBla and select Start. The BLA will have a solid green arrow in its status if the start is successful.
    12. If you had chosen this method, then directly jump to the Running section.
  3. Install and start the HelloJee Sample application through the command line using the wsadmin BLA commands.

    Note: Change the name of the BLA to suit your preference and location of the binaries to suit your environment.
    1. 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
    2. 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}
      Note: If more than one composition unit uses a EAR asset then use this alternative command:
      $AdminTask addCompUnit {-blaID HelloJeeBla -cuSourceID HelloJeeSca.jar -JeeImplementation [[HelloJeeEnhancedComponent HelloJeeEnhancedEar.ear HelloJeeEnhancedEar][HelloJeeComponent HelloJeeEar.ear HelloJeeEar]] }

Running

Run Icon

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:

  • host: Hostname where the server is located (For example, we assume it is localhost)
  • port: Port for WebSphere application server host (For example, we assume it is 9080)
  1. 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(): 
                
  2. 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.

  3. 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():
                
  4. 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():
    		

Uninstall

Uninstall Icon
  1. Stop and uninstall the HelloJee sample application through the command line using the wsadmin BLA commands.

    Note: You can optionally choose to perform these steps through the administration console.
    1. 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
    2. 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

User's Guide

You can run the different parts of the sample by visiting the following URLs:

  1. Access the non-SCA enhanced EJB as is: http://localhost:9080/HelloJeeWeb/JeeEjbClient
  2. Access the non-SCA enhanced EJB as SCA service: http://localhost:9080/HelloJeeWeb/JeeScaClient
  3. Access the SCA enhanced EJB as is: "http://localhost:9080/HelloJeeEnhancedWeb/JeeEEjbClient"
  4. Access the SCA enhanced EJB service/reference as SCA service/reference and demonstrate SCA annotations : "http://localhost:9080/HelloJeeEnhancedWeb/JeeEScaClient"