Enterprise Java Beans Job Task Analysis
Please review this Job Task Analysis and provide input by adding your comments to this wiki. Please also complete the short survey at: Enterprise Java Beans Survey
Implement business logic as Java technology classes.
Task: Plan the development of a business service or model
- Design classes to contain business logic.
- Select which classes with require synchronous or asynchronous processing.
- Analyze which classes will require stateful behavior and which can use stateless.
- Assess the need of EJB technology (instead of POJOs) (what are the compelling features).
- Select the correct profile (Web vs Full) based on the required functionality.
Implement synchronous processing
Task: Create a Stateful Session Bean
- Create a class that is marked as a stateful session bean.
- Determine whether local or remote clients, or both, will access the session bean.
- If remote clients will access the session bean, expose a remote view through a remote business interface.
- If local clients will access the session bean, expose a local view through a local business interface or a no-interface view.
- Add one or more business method(s).
Task: Create a Stateless Session Bean
- Create a class that is marked as a stateless session bean.
- Determine whether local or remote clients, or both, will access the session bean.
- If remote clients will access the session bean, expose a remote view through a remote business interface.
- If local clients will access the session bean, expose a local view through a local business interface or a no-interface view.
- Add one or more business method(s).
Task: Create a Singleton Session Bean
- Create a class that is marked as a singleton.
- Determine whether local or remote clients, or both, will access the singleton.
- Based on the types of clients that will access the singleton, create the appropriate view.
- Decide whether the singleton's concurrency access will be managed by the container or by the singleton bean.
- If the singleton's concurrency is managed by the container, decide whether the business methods of the singleton require shared or exclusive concurrency access, and annotate the class or methods.
- Decide whether the singleton needs to be initialized at application startup, and if so add the appropriate annotations.
- Decide whether the business methods that need exclusive concurrency access need more or less time before an access timeout is thrown, and add the appropriate annotations.
Task: Create a Session Bean client
- Decide whether the session bean the client is accessing is local or remote.
- Decide the environment in which the client will run.
- If the environment supports dependency injection, use annotations to inject a session bean.
- If the environment doesn't support dependency injection, use context and JNDI lookup code to obtain a reference to a session bean.
- Write code that invokes the session bean's business methods.
Implement Enterprise Bean Interceptors
Task: Create interceptors for an EJB
- Predict the order in which enterprise bean interceptors are invoked for a given enterprise bean and its interceptor(s).
- Determine whether the enterprise bean requires class- or method-level interceptors.
- Determine whether the enterprise bean will use an internal interceptor.
- Create interceptors in an enterprise bean:
- declare a method-level interceptor if needed.
- declare a class-level interceptor if needed.
- include an interceptor method if needed.
- Create the interceptor classes required by the enterprise bean, if needed.
Implement asynchronous processing
Task: Modify a Session bean to be asynchronous
- Identify session bean methods that could benefit from asynchronous execution
- Add the Asynchronous annotation to session bean methods
- Use the java.util.Concurrent return type and the javax.ejb.AsyncResult<V> class to return information to the caller of an asynchronous method
Task: Create a Message Driven Bean
- Determine what type of message the message-driven bean will process.
- Create a class that is marked as a message-driven bean.
- Determine whether the message-driven bean will implement the listener interface for the message type.
- Determine whether the message-driven bean requires access to the message-driven context, and if so add the appropriate annotations to inject the context.
- Add an onMessage method that contains the business logic of the message-driven bean.
Task: Create a Client that Sends a Message to a JMS Queue
- Determine the environment in which the client will run.
- If the environment supports dependency injection, use annotations to inject the JMS connection factory and queue.
- If the environment does not support dependency injection, use context and JNDI lookup code to obtain references to the JMS connection factory and queue.
- Create code that creates a message using the JMS connection factory and queue.
- Create code that sends the message.
Controlling Transactions in Enterprise Beans
Task: Add Transaction Demarkation Information to an Enterprise Bean
- Determine whether the enterprise bean will use container-managed transaction demarkation or if the bean will manage its own transactions.
- If the enterprise bean will use container-managed transaction demarkation:
- Determine the appropriate transaction attributes of an enterprise bean's business methods.
- Determine whether the enterprise bean requires class- or method-level transaction attributes.
- If the enterprise bean is a stateful session bean, determine if the session bean should receive transaction notification messages. If so:
- Implement the SessionSynchronizationInterface in the enterprise bean class.
- Add the session synchronization methods to the enterprise bean class.
- Add transaction attribute annotations to the enterprise bean class or methods.
- Determine whether the business methods need to explicitly cause a transaction rollback, and if so, invoke the setRollbackOnly method.
- If the enterprise bean will use bean-managed transaction demarkation:
- Determine whether the enterprise bean will use JTA transactions.
- If the enterprise bean uses JTA transactions:
- Implement the UserTransaction interface in the enterprise bean class.
- Call commit and rollback in the enterprise bean's business methods.
Exposing Session Beans as Web Services
Task: Expose a Session Bean as a JAX-WS Web Service
- Create a Stateless Session Bean that:
- exposes a web-service endpoint. (overlap with Web Services Developer)
- has one or more web methods. (overlap with Web Services Developer)
Task: Expose a Session Bean as a JAX-RS Resource
- Create a Session Bean that:
- represents a JAX-RS resource. (overlap with Web Services Developer/Web Developer)
- responds to HTTP GET and POST requests. (overlap with Web Services Developer/Web Developer)
Enabling and disabling access
Task: Add security checks to business logic
- Modify an enterprise bean to limit the invocation of one or more business methods to a particular role.
- Modify an enterprise bean to limit all the business methods of the enterprise bean to a particular role.
- Match security behaviors to declarative security specifications (default behavior, security roles, security role references, and method permissions).
- From a list of responsibilities, predict which roles are responsible for which aspects of security: application assembler, bean provider, deployer, container provider, system administrator, or server provider.
- Use the isCallerInRole and getCallerPrincipal methods in an enterprise bean to restrict access to the enterprise bean's business methods.
- Predict the behavior of an enterprise bean that:
- only uses security annotations.
- uses both security annotations and security tags in the enterprise bean's deployment descriptor.
Other Tasks
Task: Schedule the execution of business logic
- Create a Session Bean that:
- sets a programmatic timer that logs a message.
- has a business method that lists all active timers.
- has a business method that cancels a timer.
- creates an automatic timer.
Task: Package and Deploy EJB applications
- Determine the application in which the EJB will be used.
- If the EJB will be used in a web application, put the EJB classes and optional deployment descriptor, or JAR containing the EJB classes and optional deployment descriptor, in the appropriate location in the WAR.
- If the EJB will be used in an enterprise application, create an EJB JAR that contains the EJB classes and optional deployment descriptor.
- Use EARs (prefer WARs)
- Use embedded EJB containers and EJB-lite
- Provide the biz interface and any required stub jars to the EJB client if the client is not deployed in the same module as the EJBs
- Deploy the application.
EJB 3.1 Technology Content - additional material for building certification questions and course material
EJB 3.1 Overview
- Design an application that appropriately uses EJB 3.1 technology.
- Predict which types of EJBs are capable of running on a server conforming to the Java EE 6 Web Profile
- Identify correct and incorrect statements or examples about EJB programming restrictions.
- Match the seven EJB roles with the corresponding description of the role's responsibilities. [Is this still correct?]
- Package an EJB in a WAR.
- Package an EJB in an EJB-JAR.
- Package an EJB in an EAR.
- Predict the behavior of the EJB Container when deploying an enterprise bean that:
- only uses annotations.
- uses both annotations and a deployment descriptor.
General EJB 3.1 Enterprise Bean Knowledge
Note: Ian believes this section can be subsumed into the other sections. Is that correct?
Identify correct and incorrect statements or examples about the lifecycle of all 3.1 Enterprise Bean instances, including the use of the}}{{{}{}{}{}{}{}{}@PostConstructand}}{{{}{}{}{}{}{}{}@PreDestroycallback methods.Identify correct and incorrect statements or examples about how enterprise beans declare dependencies on external resources using JNDI or dependency injection, including the general rules for using JNDI, annotations and/or deployment descriptors, EJB references, connection factories, resource environment entries, and persistence context and persistence unit references.Identify correct and incorrect statements or examples about Timer Services, including the bean provider's view and responsibilities, the}}{{{}{}{}{}{}{}{}TimerService,}}{{{}{}{}{}{}{}{}Timer{}{}{}{}{}{}{}TimerHandleinterfaces, and}}{{{}{}{}{}{}{}{}@Timeoutcallback methods.andIdentify correct and incorrect statements or examples about the EJB context objects that the container provides to 3.1 Session beans and 3.1 Message-Driven beans, including the security, transaction, timer, and lookup services the context can provide.
EJB 3.1 Session Beans
- Design the EJB tier of an application that appropriately uses Stateful, Singleton, and Stateless Session Beans
- Create a Singleton Session Bean that:
- exposes a no-interface, local view.
- has one or more business method(s)
- logs a message before being destroyed.
- starts-up on application-deployment.
- injects a local EJB.
- injects a remote EJB.
- Create a Stateful Session Bean that:
- has one or more business method(s).
- exposes a local view through a remote business interface.
- logs a message before being passivated.
- logs a message after being activated.
- logs a message upon being removed.
- Create a Stateless Session Bean that:
- has one or more business method(s).
- uses transaction demarkation annotations on at least one of the business methods.
- exposes a remote view through a remote business interface.
- exposes a local view through a local business interface
- logs a message after being created.
- uses JNDI to lookup another EJB.
- Create a Singleton Session Bean that:
- has one or more business method(s).
- exposes a local, no-interface view.
- injects another EJB that exposes a no-interface view.
- depends on one or more other singleton session beans.
- uses container-managed concurrency.
- explicitly sets the concurrency lock-mode at the class and method level.
- Modifies the default access timeout value.
- Create a Stateless Session Bean that:
- exposes a web-service endpoint. (overlap with Web Services Developer)
- has one or more web methods. (overlap with Web Services Developer)
- Create a Singleton Session Bean that:
- represents a JAX-RS resource. (overlap with Web Services Developer/Web Developer)
- responds to HTTP GET and POST requests. (overlap with Web Services Developer/Web Developer)
- injects a resource.
- Create a Stateless Session Bean that:
- sets a programmatic timer that logs a message.
- has a business method that lists all active timers.
- has a business method that cancels a timer.
- creates an automatic timer.
- Predict when EJB clients can modify an EJB objects state (pass-by-reference vs. pass-by-value).
- Predict the Java EE components that are allowed to inject references to enterprise beans.
EJB 3.1 Message-Driven Beans
- Create a Message-Driven Bean.
- Create code that uses JMS to send a message by:
- Injecting a JMS connection factory.
- Injecting a JMS queue.
- Creating a message using the connection factory and queue.
- Sending the message.
Transactions
- Create an enterprise bean that uses container-managed transaction demarkation.
- Create an enterprise bean that uses bean-managed transaction demarkation.
- Modify the transaction attributes of an enterprise bean.
- Predict the behavior of an enterprise bean with both transaction annotations and deployment descriptor tags.
- Modify an enterprise bean to correctly use getRollbackOnly, setRollbackOnly and the SessionSynchronization interface.
Interceptors
- Create an enterprise bean:
- declares a method-level interceptor.
- declares a class-level interceptor.
- includes an interceptor method.
- Create the interceptor classes required by the previous enterprise bean.
- Predict the order in which enterprise bean interceptors are invokes for a given enterprise bean and its interceptor(s).
- Predict the behavior of an enterprise bean interceptor that:
- uses interceptor annotations only.
- uses both interceptor annotations and tags in the deployment descriptor.
Exceptions
- Modify an enterprise bean to correctly use an application exception.
- Modify an enterprise bean to correctly handle a system exception.
- Modify an enterprise bean to define a runtime exception as an application exception.
- Predict whether the bean-developer, container provider, or neither is responsible for throwing or handling an exception.
- Predict what happens when an EJB client encounters an exception when it invokes an EJB.
- Given a particular method condition, predict: whether an exception will be thrown, the type of exception thrown, the container's action, and the client's view.
Embeddable EJB Containers
- EJB-lite vs Full EJBs
- Use in unit testing
Security Management
- Modify an enterprise bean to limit the invokation of one or more business methods to a particular role.
- Modify an enterprise bean to limit all the business methods of the enterprise bean to a particular role.
- Match security behaviors to declarative security specifications (default behavior, security roles, security role references, and method permissions).
- From a list of responsibilities, predict which roles are responsible for which aspects of security: application assembler, bean provider, deployer, container provider, system administrator, or server provider.
- Use the isCallerInRole and getCallerPrincipal methods in an enterprise bean to restrict access to the enterprise bean's business methods.
- Predict the behavior of an enterprise bean that:
- only uses security annotations.
- uses both security annotations and security tags in the enterprise bean's deployment descriptor.