Process Information Factory
SUN J2EE Architecture(Introduction, J2EE Patterns, Samples)
-- Understanding the SUN J2EE Architecture --
© Josef Schiefer, IBM Watson
SUN J2EE Architecture
Tiered Approach (5 Tiers)
SUN J2EE Architecture
SUN J2EE Architecture
Front Controller / Dispatcher
SUN J2EE Architecture
Front Controller Interaction
SUN J2EE Architecture
Front Controller Alternatives…
SUN J2EE Architecture
Servlet Front Controller
SUN J2EE Architecture
JSP Front Controller
SUN J2EE Architecture
JSP Front Controller – JSP Code<%@page contentType="text/html"%> <%@ page import="corepatterns.util.*" %><html><head><title>JSP Front Controller</title></head><body><h3><center> Employee Profile </h3><% /**Control logic goes here... We either dispatch to another JSP at this point or simply allow the remaining portions of scriptlet code to execute**/String page;/**ApplicationResources provides a simple API forretrieving constants and other preconfigured values**/ApplicationResources resource = ApplicationResources.getInstance();try{
RequestHelper helper = new RequestHelper(request); // Use a helper object to gather parameterCommand cmdHelper= helper.getCommand(); // Command helper perform custom operationpage = cmdHelper.execute(request, response);
} catch (Exception e){request.setAttribute(resource.getMessageAttr(),"Exception occured : " + e.getMessage());page = resource.getErrorPage(e);
}// dispatch control to viewif(page!=null){
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page);dispatcher.forward(request, response);
}%><FORM method=POST ><table width="60%"><tr><td> Not detected next page </td></tr></table></FORM></body></html>
SUN J2EE Architecture
Servlet Controller Strategy
SUN J2EE Architecture
Command & Controller Strategy
SUN J2EE Architecture
Screen Mappings
<request-mappings><screen-definition url="/WEB-INF/xml/screendefinitions.xml" language="en_US"/><screen-definition url="/WEB-INF/xml/ja/screendefinitions.xml" language="ja_JP"/><default-screen>MAIN</default-screen><signin-screen>SIGN_IN</signin-screen><signin-error-screen>SIGN_IN_ERROR</signin-error-screen><url-mapping url="/main" screen="MAIN"/><url-mapping url="/search" screen="SEARCH"/><url-mapping url="/category" screen="CATEGORY"/>
…..<url-mapping url="/verifysignin" screen="SIGN_IN_SUCCESS" useRequestHandler="true" useFlowHandler="true">
<request-handler-class>com.sun.j2ee.blueprints.petstore.control.web.handlers.SigninHandler</request-handler-class>
<flow-handler class="com.sun.j2ee.blueprints.petstore.control.web.handlers.SigninFlowHandler">
<handler-result result="2" screen="SIGN_IN_ERROR"/><handler-result result="1" screen="SIGN_IN_SUCCESS"/>
</flow-handler></url-mapping>
…..<exception-mapping exception-class="com.sun.j2ee.blueprints.petstore.control.exceptions.SigninFailedException" screen="SIGN_IN_ERROR"/>
</request-mappings>
SUN J2EE Architecture
Screen Definitions
<screen-definitions><template>/template.jsp</template><screen>
<screen-name>main</screen-name><parameter key="title" value="Welcome to the BluePrints Petstore" direct="true"/><parameter key="banner" value="/banner.jsp" direct="false"/><parameter key="sidebar" value="/sidebar.jsp" direct="false"/><parameter key="body" value="/main.jsp" direct="false"/><parameter key="mylist" value="/mylist.jsp" direct="false"/><parameter key="advicebanner" value="/advice_banner.jsp" direct="false"/><parameter key="footer" value="/footer.jsp" direct="false"/>
</screen><screen>
<screen-name>cart</screen-name><parameter key="title" value="Cart" direct="true"/><parameter key="banner" value="/banner.jsp" direct="false"/><parameter key="sidebar" value="/sidebar.jsp" direct="false"/><parameter key="body" value="/cart.jsp" direct="false"/><parameter key="mylist" value="/mylist.jsp" direct="false"/><parameter key="footer" value="/footer.jsp" direct="false"/><parameter key="advicebanner" value="/advice_banner.jsp" direct="false"/>
</screen> ….</screen-definitions>
SUN J2EE Architecture
Example – Flight Reservation
SUN J2EE Architecture
Screen Flow Management / Controllers
MainServlet
rq : RequestProcessorsfm : ScreenFlowManager
init()doGet()doPost()doProcess()getRequestProcessor()getScreenFlowManager()
FlowHandlerException
toString()
FlowHandler
doStart()processFlow()doEnd()
<<throws>>
ScreenFlowManager
getNextScreen()getCurrentScreen()getExceptionScreen()
<<throws>>
WebControl ler
init()handleEvent()destroy()
<<Interface>>
RequestProcessor
processRequest()
WebAction
setServletContext()doStart()processRequest()doEnd()
<<Interface>>
WebControl lerImpl
ejbcontrol ler : EJBControl ler
init()handleEvent()destroy()
Event
getEventName()
<<Interface>><<creates>>
EJBControllerEJB
StateMachine stateMachine
handleEvent()
StateMachine
HashMap attributes
processEvent()
<<processes>>
EJBAction
init()doStart()processEvent()doEnd()
<<Interface>>
<<processes>>
SUN J2EE Architecture
Class Model – Web Application
WebActionSupport
setServletContext()doStart()doEnd()
EventSupport
getEventName()
ServiceLocator
getWebClientController()
<<Interface>> HttpSessionListener<<Interface>>
M
EJBActionSupport
init()doStart()doEnd()
EventResponseSupport
payload : Object
getPayload()
FlowHandlerException
toString()
FlowHandler
doStart()processFlow()doEnd()
<<throws>>
ScreenFlowManager
getNextScreen()getCurrentScreen()getExceptionScreen()
<<throws>>
MainServlet
rq : RequestProcessorsfm : ScreenFlowManager
init()doGet()doPost()doProcess()getRequestProcessor()getScreenFlowManager()
ServiceLocatorImpl
webController : WebControllersession : HttpSession
getWebClientController()sessionCreated()sessionDestroyed()
WebController
init()handleEvent()destroy()
<<Interface>>
WebActionException
toString()
RequestProcessor
processRequest()
WebAction
setServletContext()doStart()processRequest()doEnd()
<<Interface>>
<<throws>>
WebControllerImpl
ejbcontroller : EJBController
init()handleEvent()destroy()
Event
getEventName()
<<Interface>>
<<creates>>
EJBControllerEJB
StateMachine stateMachine
handleEvent()
StateMachine
HashMap attributes
processEvent()<<processes>>
EventResponse
getEventName()
<<Interface>>
EJBAction
init()doStart()processEvent()doEnd()
<<Interface>>
<<processes>>
<<creates>>
SUN J2EE Architecture
Class Diagram - Flight Management
TravelAgentEJB
travelAgency : String
MailerEJB
sendMail()
PaymentEJB
isCreditCardValid()chargeCreditCard()awardTravel()sendPaymentConfirmation()
LoginEJB
user : Stringpassword : String
SignOnEJB
authenticate()createUser()
AddressEJB
city : Stringcountry : Stringstate : StringstreetName1 : StringstreetName2 : StringzipCode : String
ContactInfoEJB
address : AddressLocaleMail : StringfirstName : StringlastName : Stringtelephone : String
ProfileEJB
bannerPreference : StringpreferredLanguage : StringfavoriteDestinations : String
FlightInformationEJB
findFlights()findAlternativeFlights()getFlight()getFlightPrice()calculateItineraryPrice()getAvailableSeats()
FlightTransactionEJB
processPayment()makeReservation()getFlight()
PersonEJB
userID : Stringprofile : ProfilecontractInfo : ContractInfo
FlightManagementFacadeEJB
userID : StringpersonEJB : PersonflightInformation : FlightInformationflightTransaction : FlightTransaction
getPerson()getUserID()setUserID()getFlightInformation()getFlightTransaction()
MileageAccountEJB
number : Stringmileage : intstatus : String
addMiles()
CreditCardEJB
cardNumber : StringcardType : StringexpiryDate : String
CustomerEJB
creditCards : CreditCard[]mileageAccount : MileageAccountreservations : Reservation[]
ReservationEJB
reservationNumber : Stringcustomer : CustomerhcreditCard : CreditCardseatClass : StringseatNumber : intdate : Dateitineraries : Itinerary[]roundTrip : boolean
0..n0..n
AirplaneEJB
number : Stringtype : Stringmanufacturer : StringmaxSeats : int
SeatsInfoEJB
seatsClass : StringmaxSeats : intavailableSeats : intprice : double
ItineraryEJB
number : StringdepartureAirport : AirportdestinationAirport : Airportflights : Flight[]mileage : int
1..21..2
FlightEJB
flightNumber : Stringairline : Stringduration : intdepartureDateTime : DatearrivalDateTime : DateseatsInfos : SeatsInfo[]distance : intflightLegs : FlightLeg[]
AirportEJB
airportCode : StringairportName : String
FlightLegEJB
departureAirportdestinationAirport
SUN J2EE Architecture
Controllers/Events/Actions
WebActionSupport
setServletContext()doStart()doEnd()
FMWebControllerImpl
init()handleEvent()destroy()
FMControllerEJB
handleEvent()
WebControllerImplejbcontroller : EJBController
init()handleEvent()destroy()
EJBControllerEJBStateMachine stateMachine
handleEvent()
LogonEventuserName : Stringpassword : String
EventSupport
getEventName()
UserProfileEventAT_CREATE : StringAT_UPDATE : StringAT_DELETE : StringUT_CUSTOMER : StringUT_TRAVELAGENT : StringactionType : StringuserType : StringcontractInfo : ContractInfoEJBcreditCard : CreditCardEJBprofile : ProfileEJBtravelAgency : String
FlightInfoEventAT_AVAILABLEFLIGHTS : StringAT_PRICEDFLIGHTS : StringAT_ITINERARYPRICE : StringAT_LISTITINERARIES : StringactionType : StringitineraryNumber : StringcustomerNumber : StringdepartureCity : StringdepartureDateTime : DatereturnDateTime : DatedestinationCity : StringroundTrip : booleanselectedFlights : String[]
FlightTransactionEventAT_PAYMENTMETHODAT_CREDITCARDSELECTIONAT_CHANGEITINERARYAT_RESERVEFLIGHTactionType : StringpaymentMethod : StringselectedFlights : String[]itineraryNumber : StringreservationNumber : StringPM_CREDITCARD : StringPM_AWARDTRAVEL : String
LogonWebAction
processRequest()
UserProfileWebAction
processRequest()
FlightInfoWebAction
processRequest()
FlightTransactionWebAction
processRequest()LogonEJBAction
processEvent()
LogoffWebAction
processRequest()
EJBActionSupport
init()doStart()doEnd()
UserProfileEJBAction
processEvent()
FlightInfoEJBAction
processEvent()
FlightTransactionEJBAction
processEvent()
ServiceLocatorImplwebController : WebControllersession : HttpSession
getWebClientController()sessionCreated()sessionDestroyed()
FMServiceLocatorImpl
getWebClientController()
SUN J2EE Architecture
Typical Web Request : ScreenFlowManager
: WebAction
: RequestDispatcher : Customerh
: MainServlet : RequestProcessor : WebController : EJBControl lerEJB : StateMachine
: EJBAction
Here is the business logic executed.
doPost()
forward(nextScreen)
Web Page
getNextScreen()
nextScreen
processRequest()
doStart()
processRequest()
Event
doEnd()
handleEvent()handleEvent()
processEvent
processEvent()
EventResponseEventResponse
EventResponse
EventResponse
SUN J2EE Architecture
Price Itinerary : FlightManagementFacadeEJB : FlightInformationEJB : FlightEJB : SeatsInfoEJB : FlightInfoEJBAction
getFlightInformation()
FlightInformation
calculateItineraryPrice()
* getSeatsInfos()
The information which fl ights are part of the itinerary are contained in the event information.
SeatsInfos
*getPrice()
Price
summarized flight prices
* getFlight()
SUN J2EE Architecture
Component Diagram
CustomerTavelAgent.JAR<<fil...
MainServlet<<Servle...
FlightManager.EAR<<fil...
FlightManager.WAR<<fil...
SignOn.JAR<<fil...
FlightManagement.JAR<<fil...
JSP Pages
webactions
actions
events
controller
ejb
web
screenflow
RequestProcessor
ServiceLocator
WebController
ScreenFlowManager
FlowHandler
FlowHandlerException
WebAction
WebActionSupport
WebActionExceptionEJBControllerEJB<<SessionBea...
StateMachine
EJBAction
EJBActionSupport
FlightInformation.JAR<<fil...
SUN J2EE Architecture
Summary
5 Tiers Architecture Event objects are used to pass data between the layers Heavy usage of local interfaces for EJBs (support of fine-grained
objects) Web Action / EJB Actions Web Controller / EJB Controller EJB/Web Packaging Screen Dispatchers / Screen Management / Screen Mappings J2EE Patterns
http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns
J2EE Blueprintshttp://java.sun.com/blueprints