Job bank EJB Binding Sample

 

Overview

 

 

This sample shows the SCA stateless session bean binding support. The stateless session bean binding is a protocol binding which provides the ability to integrate SCA with EJB based services.

            1) The Reference binding enables SCA components to invoke stateless session beans

            2) The Service binding exposes an SCA service as a stateless session bean for consumption by J2EE applications

 

Flow

 

This sample shows how to invoke a SCA component using JEE programming model and how a component with an EJB reference binding can invoke a stateless EJB which is in JobbankTargetEJBApp.   

The non-SCA, J2EE client packaged within JobbankClientApp invokes the ‘Company’ service which is exposed over the EJB binding.  This Company service is invoked as a normal EJB, then, from the perspective of the client application, without awareness that the client is invoking an SCA service exposed over the remote EJB service binding.  The Company component, in turn, contains a reference to a ResumeBank EJB, which it invokes using the simple SCA programming model.  This reference is configured using the EJB reference binding to point to a Stateless Session bean packaged within the JobbankTargetEJBApp application.  The simple SCA programming model allows the Company component to invoke the ResumeBank EJB service using a simple POJO-like invocation without having to use JEE client APIs.

 

 

Diagram of Jobbank sample

 

Artifacts involved

 

  1. jobbankejb.jar ->This contains SCA component "Company". This component exposes its service as a stateless EJB through ejb binding service and access external EJB through ejb binding reference to post a resume.

 

  1. JobbankTargetEJBApp.ear -- > External EJB which is accessed by the component

 

  1. JobbankClientApp.ear - > J2EE client. JobbankClientApp.ear is a pure J2EE client app. This app shouldn’t be installed onto Websphere through the administrative console. This client runs from the command line.           

 

 

Prerequisites and Setup

1.       This sample application requires that you have the WebSphere Application Server and the SCA Feature Pack installed.

 

Part 1: Inspect and build the EJB Binding sample applications  

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

 

  1. Find out the bootstrap port of the application server. (See the WebSphere Application Server infocenter for more information on how to determine the port of the application server)

 

  1. Open the {WAS_HOME}\samples\SCA\jobbankejb\src\main\resources\META-INF\sca-deployables\default.composite file.  Look for “uri” attribute in <binding.ejb ..> under <reference ..> element. Change the hostname and port number as per your bootstrap host and bootstrap port in uri="corbaname:iiop:localhost:2809/NameServiceServerRoot#ejb/com/app/resumebank/ResumeBankHome" ( Note that 2809 as in the default.composite file is the default for the application server)

 

  1. Open a command window and change to the {WAS_HOME}\samples\SCA\jobbankejb directory.

 

  1. Issue the following command to build the artifacts: {WAS_HOME}\profiles\{PROFILE_NAME}\bin\ws_ant

 

  1. Example command: C:\WebSphere\AppServer\profiles\AppSrv01\bin\ws_ant

 

  1. Verify that the build completes without error and the following atrifacts have been created in {WAS_HOME}\samples\SCA\jobbankejb\target

          JobbankClientApp.ear

                jobbankejb.jar

                JobbankTargetEJBApp.ear

 

 

Part 2: Install and start SCA composite

 

  1. Start the server. 

1.  Start the WebSphere Application Server if it is not already started.

                        __ a. Open a command window and issue the following command

cd <WAS_HOME>\profiles\<PROFILE_NAME>\bin

Example command:

cd C:\WebSphere\AppServer\profiles\AppSrv01\bin

                        __ b. Issue the startServer command

startServer server1

 

2.       Use the Administrative Console to import jobbankejb.jar

__ a. Open a Log into the Administrative Console by navigating to http://localhost:9060/admin in a Web browser.

__ b. From the left navigation panel of the Administrative console, expand Applications then Application Types and select Assets.

__ c. Press the Import button, then browse to <WAS_HOME>\samples\jobbankejb\target\ and select the jobbankejb.jar file. Click Next using all the default settings until you reach the summary page and click Finish.

__d. Click the Save link at the top of the screen.

 

3.       Use the Administrative Console to create the Business-level Applications that will run the SCA composites.

__ a. From the left navigation panel of the Administrative console, expand Applications and select Application Types and then Business-level Applications and click on New.

__ b.Fill in jobbankejb for name and click Apply.

__ c. Click the Save link at the top of the screen.

__ d. Go to Applications and select Applicaton Types and then Business-level Applications. Then click on jobbankejb.

__ e. Under Deployed Assets click on Add and choose Add Asset. Select jobbankejb.jar and click Continue.

__ f. Click Next until the last panel and then click Finish.

__ g. Click the Save link at the top of the screen, and return to Applications and select Application Types and then Business-level Applications. Select the jobbankejb checkbox and click on Start.

 

Part 3: Install target EJB

Use the Administrative Console to install target EJB application

__ a. From the left navigation panel of the Administrative console, expand Applications and then select New Application and select New Enterprise Application.

__ b. On the install panel, specify the Local file system option and enter the Full path or use the browse button to select the JobbankTargetEJBApp.ear file located in the <<WAS_HOME>\samples\jobbankejb\target\ directory. Click Next.

__ c. For the remaining install panels, select the defaults by clicking Next until you reach the final panel.  Click Finish to complete the installation of the sample application.

__ d. The application will appear in the list of applications and its initial status will be stopped” (Status of Red).  Expand Applications then Application Types and select WebSphere enterprise applications.  Check the box next to JobbankTargetEJBApp and press Start.

 

Part 4: Running the sample

 

  1. Open a command window. cd WAS_HOME\bin

 

  1. launchClient.bat WAS_HOME\ samples\jobbankejb\target\JobBankClientApp.ear -CCclasspath=WAS_HOME\profiles\YOUR_PROFILE_NAME\installedApps\YOUR_CELLNAME\JobBankApp.ear\CompanyComponent_Company.jar -CCBootstrapHost=localhost  -CCBootstrapPort=2809

 

where

                                                               i.      WAS_HOME = Websphere home directory

                                                             ii.      YOUR_PROFILE_NAME = your profile name         

                                                            iii.      YOUR_CELLNAME = Your Cell name under "installedApps" under your profile

                                                           iv.      -CCBootstrapHost = hostname

                                                             v.      -CCBootstrapPort=  Bootstrap port for your Websphere instance

                                                           vi.      These settings are needed to bootstrap the WAS J2EE client container.

 

 

  1. You should see the result printed on the console and also in your SystemOut.log

 

       It will look something like:

 

INVOKING SCA COMPONENT THROUGH COMPONENT SERVICE WITH EJB BINDING

Getting company info for Company: ACME Corp

Result from SCA Component. Company type: Software firm

INVOKING COMPONENT SERVICE->COMPONENT->COMPONENT REFERENCE->EXTERNAL EJB

Posting resume: John Doe

Confirmation number: 1559740348