Skip to main content

JEE

Architecture

Java EE platform suggests a distributed multitiered architecture model for enterprise applications:

  • Client Tier
    • Application Clients: clients that run directly on the client machine. They are usuallyquite rich and they interact directly with the bussines tier.
    • Web Clients: Dynamic web pages (e.g. HTML, XHTML, JS) generated by web components. The web client simplifies the distribution, deployment, and update of the system.
    • Applets: small clients written in Java integrated as part of a web page and executed on the browser. They require tha Java plug-in.
  • Web Tier
    • Java Servlet: Java class which lets applications and server communicate via of a request-response programming model
    • JavaServer Faces
    • JavaServer Pages (JSP): text-based documents (i.e. HTML) with added JSP elements. It allows to combine Java code with HTML.
  • Business Tier
    • EJB (enterprise java bean): server-side component that encapsulates the business logic of an application
  • Enterprise information system (EIS) Tier

A Tier is a logical grouping of several components that are served for specific purpose

Containers

Container offers services to manage:

  • The component lifecycle
    • Deployment
    • Activation/instantiation
    • Configuration
    • Execution scope
    • Termination
  • lookup of other components
  • communication between components

Before a component (web, enterprise bean, or application client) can be executed, it must be assembled into a Java EE module and deployed into its container.

EJB Types

There are two types of EJB:

  1. Session:Performs a task for a client; optionally, may implement a web service
    1. Stateful: the instance variables represent the state of a unique client/bean session. Yt can have only one client and each client creates a new instance.
    2. Stateless: does not maintain a conversational state with the client and all instances of a stateless bean are equivalent
    3. Singleton: maintains the state of the bean per lifecycle of the application. Instantiated once per application.
  2. Message-driven: Acts as a listener for a particular messaging type, such as the Java Message Service API

Injection Mechanism

Past exams exercises

2021 02 05 Q3 (6 points) Milan kindergarten

The Municipality of Milan wants to create a web-based system to let parents register their children in a public kindergarten in various regions of the city. The Municipality would like to have a robust architecture to manage this system. Parents use the system to enter an Enrollment Request (ER) where they specify the information about their child, including the area they live in. Kindergartens receive through the system the ER, evaluate it and contact the applicants to inform them if they are rejected/accepted and to further communicate with them. In particular, the system offers the following functions to parents:

  • F1 - Child registration: The parent should be able to register his/her child in the system by giving information such as name/surname, birthdate of the child, working status, phone number, and e- mail address of the parents. As a result of the registration, parents will be able to log in to the system.
  • F2 - Enrollment request: When logged in, parents issue the ER by giving the following data in addition to the data in their profile: city area of interest, and if the child needs any special medical care.
  • F3 - Kindergarten rating: Parents can rate the kindergarten of their child.
  • F4 - Visualization of ER status: This can be one of the following: pending or accepted (for simplicity, we assume that there is enough availability for all children of a certain area, so no application is rejected).

Moreover, the system offers the following functions to kindergartens’ staff:

  • F5 - Kindergarten registration: This is performed by providing at least the following data: kindergarten name, city area, email, capacity.
  • F6 - Profile update: Kindergartens can update their capacity. They will stop receiving ERs whenever their capacity is full.
  • F7 - ER evaluation: The kindergarten’s staff can accept/reject an application.

Finally, the system offers the following support functions:

  • F8 - Upon submission, the system sends ERs to all available kindergartens of the desired city area. Notice that a parent cannot apply for a specific kindergarten, but only for a region.

Notice that when one of the kindergartens accepts an ER, then the ER status is changed to accepted. Also, the system keeps track of who is enrolled in each kindergarten, based on the acceptance information.

Point A (2 points) Web Tier Components

Identify at least two different Components of the Web Tier, their main responsibility and, for each Component, list the requirements that it satisfies.

SOLUTION

The web tier of the application is composed of various JSPs containing HTML forms and Servlets to manage them. For example, below are listed some of the needed components:

Component Responsibility Requirement
JSP Front-end for Child Registration F1
JSP Front-end for kindergarten Registration F5
JSP Front-end for ER form F8
ChildRegistration_Servlet To forward the forms data to corresponding Bean F5
KindergartenRegistration_Servlet To forward the forms data to corresponding Bean F1
ER_Servlet To forward the ER-Form data to corresponding Bean F8

Point B (3 points) Identify beans

Given the entities defined in the following table, focus on the business layer part of your system, and in particular on the definition of the Beans. More precisely, identify the required Beans, specify their types and, for each Bean, list the functions it satisfies (F1-F8) and at least one method (the most important one).

Component Type Requirement
Kindergarten_Manager Stateless Bean F5, F6, F7
ER_Manager Stateless Bean F4, F8
Child_Manager Stateless Bean F1,F2,F3

Kindergarten_Manager, Child_Manager are stateless beans to manage the operations related to the Kindergarten and Child entities such as registration, profile updating and so on.

ER management could be implemented as a stateless bean, the ER_Manager. To address F8, when a new request is generated by filing the ER form, the main task of the ER_Manager bean is to first extract the requested region in the ER, then query the database to find all the available kindergartens in that region and then send them the ER.

Some methods of Child_Manager, Kindergarten_Manager, and ER_Manager are the following:

  1. Child_Manager:
public Integer updatePassword(String userID, Integer rate) {}
public Integer updateResidenceAddress(String addr) {}
  1. Kindergarten_Manager:
public void SetAvailability(Boolean availability) {}
public Integer updateRating(String userID, Integer rate) {}
  1. ER_Manager:
public Collection<Kindergarten> findKindergartenByRegion(String RegionName){}
public void sendERs(Collection<Kindergarten> kindergartensInRegion) {
    for (kindergarten k : kindergartensInRegion) {
        // send the ER to k
    }
}

Point C (1 point) Reflect on Message-Based model

Reflect on the possibility to adopt a Message-Based Communication model. Which part of the business layer is most suited to be addressed through such model? What is the JEE API to use in this case? Explain how you would incorporate such JEE API in your system.

SOLUTION

The JMS style that could be used here is the publisher-subscriber model, so each region would be a Topic and upon ER submission the Publisher notifies the Subscriber of the respected region. The main advantage of having JMS versus Stateless bean is that here the load of the ER management task is distributed over different Beans, each one responsible for single region.