1 / 42

Development and Deployment Roles

Development and Deployment Roles. Venugopal Pakanati. What is EJB technology ? What is an EJ bean ? Types of Beans Entity Bean Session Bean. EJB Architecture :. EJB Server. EJB Container. Locate, Create, Remove instances of EJB. Home Interface. EJB Client. EJB.

gari
Download Presentation

Development and Deployment Roles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Development and Deployment Roles Venugopal Pakanati

  2. What is EJB technology ? • What is an EJ bean ? • Types of Beans • Entity Bean • Session Bean

  3. EJB Architecture : EJB Server EJB Container Locate, Create, Remove instances of EJB Home Interface EJB Client EJB Databases Remote Interface Invoke business methods of EJB

  4. 5 Roles in the application development and deployment life cycle 1. Enterprise Java Bean providers 2. Application Assemblers 3. Deployers 4. System Adminstrators 5. Application Server Vendors

  5. Development and Deployment Scenario Application Assembler EJB Provider Deployer Application Server Vendor System Administrator

  6. 1. The Enterprise Java Bean Provider • referred to as an ‘application domain expert’. • needs to be an expert in the business logic. • needs to be able to express business logic using Java code. • does not need to be an expert in system-level programming • do not need to understand the details of the target environment

  7. The enterprise bean provider produces --- a JAR containing : • (i) The bean’s home interface • (ii) The bean’s remote interface • (iii) The bean’s implementation class • (iv) The bean’s primary key class, in case of an entity bean • (v) A partially-complete deployment descriptor

  8. Example: Banking Account Entity Bean Session Bean members: accountID customerName customerType accountBalance Bean Name: Account Bean Name: AccountManager Home Interface: AccountHome Home Interface: AccountManagerHome HI methods: create( ); HI methods: create( ); findbyPrimaryKey( ); Remote Interface: Account Remote Interface: AccountManager RI methods: withdraw( ); RI methods: createAccount( ); deposit( ); withdraw( ); getCustomerType( ); deposit( ); cancel( ); Implementation class: AccountEJBImplementation class: AccountManagerEJB Security Roles: UnmediatedAccess (Web, ATM) ----- deposit( ), withdraw( ) Teller ----- deposit( ), withdraw( ) Manager ----- All methods Of session bean

  9. (i) The Bean’s Home Interface (a) Home Interface for the Entity Bean (b) Home Interface for the Session Bean

  10. (a) Home interface for the entity bean : package wrox.some_isv ; import javax.ejb.* ; import java.rmi.RemoteException ; public interface AccountHome extends EJBHome { public Account create (int accountID, String customerName, String customerType, double initialBalance) throws CreateException, RemoteException ; public Account findByPrimaryKey (Integer accountID) throws FinderException, RemoteException ; }

  11. (b) Home Interface for the Session Bean : package wrox.some_isv ; import javax.ejb.* ; import java.rmi.RemoteException ; public interface AccountManagerHome extends EJBHome { AccountManager create ( ) throws CreateException, RemoteException ; }

  12. (ii) The Bean’s Remote Interface (a) Remote Interface for the Entity Bean (b) Remote Interface for the Session Bean

  13. (a) Remote Interface for the Entity Bean : package wrox.some_isv ; import javax.ejb.* ; import java.rmi.RemoteException ; public interface Account extends EJBObject { void withdraw (double amount) throws InsufficientFundsException, RemoteException ; void deposit (double amount) throws RemoteException ; String getCustomerType( ) throws RemoteException ; }

  14. (b) Remote Interface for the Session Bean : package wrox.some_isv ; import javax.ejb.* ; import java.rmi.RemoteException ; public interface AccountManager extends EJBObject { void createAccount (int accountID, String customerName, String customerType, double initialBalance) throws NoAccountCreatedException, RemoteException ; void withdraw (int accountID, double amount) throws InsufficientFundsException, NoSuchAccountException, RemoteException ; void deposit (int accountID, double amount) throws NoSuchAccountException, RemoteException ; public void cancel (int accountID) throws RemoteException ; }

  15. (iii) Bean’s Implementation Class : Session Bean implementation class : package wrox.some_isv; import javax.ejb.*; import javax.naming.*; import java.rmi.RemoteException; public class AccountManagerEJB implements SessionBean { public SessionContext ctx; public void createAccount(int accountID, String customerName, String customerType, double initialBalance) throws NoAccountCreatedException { try { AccountHome accountHome = getAccountHome(); accountHome.create(accountID, customerName, customerType, initialBalance); } catch (CreateException ce) { throw new NoAccountCreatedException(ce.getMessage()); } catch (RemoteException re) { throw new EJBException(re); } }

  16. public void withdraw(int accountID, double amount) throws InsufficientFundsException, NoSuchAccountException { try { Account account = getAccount(accountID); if ((amount > 250) && account.getCustomerType().equals(CustomerTypes.INDIVIDUAL) && ctx.isCallerInRole("ATM")) { throw new SecurityException(); } account.withdraw(amount); } catch (RemoteException re) { throw new EJBException(re); } }

  17. public void deposit(int accountID, double amount) throws NoSuchAccountException { try { Account account = getAccount(accountID); account.deposit(amount); } catch (RemoteException re) { throw new EJBException(re); } } public void cancel(int accountID) { try { Account account = getAccount(accountID); account.remove(); } catch (NoSuchAccountException nsae) { } catch (Exception e) { throw new EJBException(e); } }

  18. private Account getAccount(int accountID) throws NoSuchAccountException { try { AccountHome home = getAccountHome(); return home.findByPrimaryKey(new Integer(accountID)); } catch (RemoteException re) { throw new EJBException(re); } catch (FinderException fe) { throw new NoSuchAccountException(); } } private AccountHome getAccountHome() { try { InitialContext initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/GenericAccount"); AccountHome home = (AccountHome) javax.rmi.PortableRemoteObject .narrow(objref, AccountHome.class); return home; } catch (NamingException ne) { throw new EJBException(ne); } }

  19. public void ejbCreate() {} public void ejbActivate() {} public void ejbPassivate() {} public void ejbRemove() {} } }

  20. Entity Bean implementation class : package wrox.some_isv; import javax.ejb.*; import javax.naming.*; public class AccountEJB implements EntityBean { public Integer accountID; public String customerName; public String customerType; public double accountBalance; public void withdraw(double amount) throws InsufficientFundsException { if (accountBalance - amount < 0) { throw new InsufficientFundsException(); } accountBalance -= amount; } public void deposit(double amount) { accountBalance += amount; } public String getCustomerType() { return customerType; }

  21. public Integer ejbCreate(int accountID, String customerName, String customerType, double initialBalance) throws CreateException { if (!customerType.equals(CustomerTypes.CORPORATION) &&!customerType.equals(CustomerTypes.INDIVIDUAL)) { throw new CreateException("Unknown customer type."); } this.accountID = new Integer(accountID); this.customerName = customerName; this.customerType = customerType; this.accountBalance = initialBalance; return this.accountID; } public void ejbActivate() {} public void ejbLoad() {} public void ejbPassivate() {} public void ejbRemove() {} }

  22. (v) Deployment Descriptor : • 2 types of information contained within a deployment descriptor : • structural information of the EJBs • (provided by the Bean Developer) • Application Assembly information • (provided by the Application Assembler)

  23. At this stage, the Deployment Descriptor contains the following • information for each bean : • Bean’s type: session or entity • Bean’s name • Bean’s implementation class • Bean’s home interface • Bean’s remote interface • Whether an entity bean is re-entrant or not • Whether a session bean is stateful or stateless • Whether or not a session bean manages its own transactions • Whether an entity bean uses BMP or CMP • Bean’s primary key class • Any references in the code to other EJBs • Any references in the code to security roles

  24. Indirection : • to avoid dependencies on a particular security implementation, • a particular database etc. • is the use of a reference ‘placeholder’ in your Java code or • deployment descriptor, rather than a reference to an actual entity in • the implementation environment • 3 types of references : • references to other EJBs • references to resources • references to security roles • At the deployment stage, the deployer creates a map between these • virtual references and the real resources (like database connections)

  25. 2. The Application Assembler • just needs to understand the home and remote interfaces, • and the business logic • need not understand the implementation of any EJBs • combines EJBs into a deployable application by • (i) completing the deployment descriptor • (ii) adding other types of application components • (to test the functionality of EJBs)

  26. (i) Completing the deployment descriptor : • Application Assembler • may define one or more security roles • may define method permissions • must link any security role references declared by an EJB to a • security role that they have defined

  27. Final version of our application’s deployment descriptor : <?xml version="1.0" ?> <ejb-jar> // provided by Bean Developer <enterprise-beans> <session> <ejb-name>AccountManager</ejb-name> <home>wrox.some_isv.AccountManagerHome</home> <remote>wrox.some_isv.AccountManager</remote> <ejb-class>wrox.some_isv.AccountManagerEJB</ejb-class> <session-type>Stateless</session-type>

  28. <ejb-ref> <ejb-ref-type>Entity</ejb-ref-type> <ejb-link>Account</ejb-link> <home>wrox.some_isv.AccountHome</home> <remote>wrox.some_isv.Account</remote> </ejb-ref> <security-role-ref> <description>This role refers to automated customer withdrawals from the account; no bank intermediary is involved.</description> <role-name>ATM</role-name> <role-link>UnmediatedAccess</role-link> </security-role-ref> </session>

  29. <entity> <ejb-name>Account</ejb-name> <home>wrox.some_isv.AccountHome</home> <remote>wrox.some_isv.Account</remote> <ejb-class>wrox.some_isv.AccountEJB</ejb-class> <persistence-type>Container</persistence-type> <reentrant>False</reentrant> <cmp-field> <field-name>customerType</field-name> </cmp-field> <cmp-field> <field-name>accountID</field-name> </cmp-field> <cmp-field> <field-name>accountBalance</field-name> </cmp-field>

  30. <cmp-field> <field-name>customerName</field-name> </cmp-field> <primkey-field>accountID</primkey-field> </entity> </enterprise-beans>

  31. // provided by Application Assembler <assembly-descriptor> <security-role> <description>This role is performed by any account access in which a bank employee is not involved, such as an internet transaction or ATM withdrawal.</description> <role-name>UnmediatedAccess</role-name> </security-role> <security-role> <description>This role is peformed by any customer-service representative who does not have account-manager status. They will be able to handle deposits and withdrawals, but not account management.</description> <role-name>Teller</role-name> </security-role>

  32. <security-role> <description>This role is performed by professionals who are allowed to manage an account (open, close).</description> <role-name>Manager</role-name> </security-role> <method-permission> <role-name>Manager</role-name> <method> <ejb-name>Account</ejb-name> <method-name>*</method-name> </method> <method> <ejb-name>AccountManager</ejb-name> <method-name>*</method-name> </method> </method-permission>

  33. <method-permission> <role-name>Teller</role-name> <role-name>UnmediatedAccess</role-name> <method> <ejb-name>Account</ejb-name> <method-name>withdraw</method-name> </method> <method> <ejb-name>Account</ejb-name> <method-name>deposit</method-name> </method> <method> <ejb-name>Account</ejb-name> <method-name>getCustomerType</method-name> </method>

  34. <method> <ejb-name>Account</ejb-name> <method-name>findByPrimaryKey</method-name> </method> <method> <ejb-name>AccountManager</ejb-name> <method-name>withdraw</method-name> </method> <method> <ejb-name>AccountManager</ejb-name> <method-name>deposit</method-name> </method> </method-permission> </assembly-descriptor> </ejb-jar>

  35. (ii) adding other types of application components : test client: Let the security role of this client be “ATM” package wrox.some_isv; import java.rmi.RemoteException; import javax.ejb.*; import javax.naming.*; import javax.rmi.PortableRemoteObject; public class TestClient { public static void main(String[] args) { try { InitialContext initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/AccountAccess"); AccountManagerHome home = (AccountManagerHome) PortableRemoteObject.narrow(objref, AccountManagerHome.class);

  36. AccountManager accountManager = home.create(); System.out.println("withdrawing small amount from individual account"); accountManager.withdraw(1, 100.0); System.out.println("withdrawing large amount from corporate account"); accountManager.withdraw(2, 1000.0); System.out.println("withdrawing large amount from individual account"); accountManager.withdraw(1, 1000.0); } catch (Exception e) { e.printStackTrace(); } } }

  37. 3. Deployer • maps the logical references that the bean provider uses onto actual • resources or identities • need not be a domain expert • need to be an expert in the environment in which the application • will execute

  38. Mapping the logical references : (i) map the logical security roles to actual users or groups (ii) map logical database accesses to an actual database (iii) map all the beans and references into the JNDI namespace

  39. 4. The System Adminstrator • responsible for configuring the application server, EJB container, • and the environment in which they execute --- including the • database, network, and security systems • responsible for the ‘well-being’ of the EJBs that are executing • in the container • must monitor logs for system problems, security problems, etc.

  40. 5. Application Server / Container Vendor • a role that we, as application developers, are unlikely to play

  41. Choosing an Application Server : • Do you need an ORB-based product to communicate with non-Java • clients or for vendor interoperability ? • What object/relational mapping capabilities do you require ? • What kind of development and deployment tools are supported by • a vendor’s application server ? • What version of EJB specification does the application server • support ? • What platform(s) does the application server run on ?

  42. Thank You !

More Related