SUN J2EE Architecture - TU Wienjs/download/j2ee_intro.pdf · /template.jsp ... ejbcontroller :...
Transcript of SUN J2EE Architecture - TU Wienjs/download/j2ee_intro.pdf · /template.jsp ... ejbcontroller :...
Process Information Factory
SUN J2EE Architecture(Introduction, J2EE Patterns, Samples)
-- Understanding the SUN J2EE Architecture --
© Josef Schiefer, IBM Watson
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
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
Screen Flow Management / Controllers
MainServletrq : RequestProcessorsfm : ScreenFlowManager
init()doGet()doPost()doProcess()getRequestProcessor()getScreenFlowManager()
FlowHandlerException
toString()
FlowHandler
doStart()processFlow()doEnd()
<<throws>>
ScreenFlowManager
getNextScreen()getCurrentScreen()getExceptionScreen()
<<throws>>
WebController
init()handleEvent()destroy()
<<Interface>>
RequestProcessor
processRequest()
WebAction
setServletContext()doStart()processRequest()doEnd()
<<Interface>>
WebControllerImplejbcontroller : EJBController
init()handleEvent()destroy()
Event
getEventNa me()
<<Interface>><<creates>>
EJBControllerEJBStateMa chi ne stateMa chi ne
ha ndl eEvent ()
StateMachineHashMap attributes
processEvent()
<<processes>>
EJBAction
init()doStart()processEvent()doEnd()
<<Interface>>
<<processes>>
SUN J2EE Architecture
Class Model – Web Application
WebAct ionSupport
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>>
MainServletrq : RequestProcessors fm : ScreenFlowManager
init()doGet()doPost()doProcess()getRequestProcessor()getScreenFlowManager()
ServiceLocatorImplwebController : WebControllersession : HttpSession
getWebClientController()sessionCreated()sessionDestroyed()
WebController
ini t()handleEvent()destroy()
<<Interface>>
WebActionException
toString()
RequestProcessor
processRequest()
WebAction
setServletContext ()doStart()processRequest ()doEnd()
<<Interface>>
<<throws>>
WebControllerImplejbcontroller : EJBController
init()handleEvent()destroy()
Event
getEventName()
<<Interface>>
<<creates>>
EJBControllerEJBStateMachine stateMachine
handleEvent()
StateMachineHashMap attributes
processEvent()<<processes>>
EventResponse
getEventName()
<<Interface>>
EJBAction
init()doStart()processEvent()doEnd()
<<Interface>>
<<processes>>
<<creates>>
SUN J2EE Architecture
Class Diagram - Flight Management
TravelAgentEJBtravelAgency : String
MailerEJB
sendMail()
PaymentEJB
isCreditCardValid()chargeCreditCard()awardTravel()sendPaymentConfirmation()
LoginEJBuser : Stringpassword : String
SignOnEJB
authenticate()createUser()
AddressEJBcity : Stringcountry : Stringstate : StringstreetName1 : StringstreetName2 : StringzipCode : String
ContactInfoEJBaddress : AddressLocaleMail : StringfirstName : StringlastName : Stringtelephone : String
ProfileEJBbannerPreference : StringpreferredLanguage : StringfavoriteDestinations : String
FlightInformationEJB
findFlights()findAlternativeFlights()getFlight()getFlightPrice()calculateItineraryPrice()getAvailableSeats()
FlightTransactionEJB
processPayment()makeReservation()getFlight()
PersonEJBuserID : Stringprofile : ProfilecontractInfo : ContractInfo
FlightManagementFacadeEJBuserID : StringpersonEJB : PersonflightInformation : FlightInformationflightTransaction : FlightTransaction
getPerson()getUserID()setUserID()getFlightInformation()getFlightTransaction()
MileageAccountEJB
number : Stringmileage : intstatus : String
addMiles()
CreditCardEJBcardNumber : StringcardType : St ringexpiryDate : String
CustomerEJBcreditCards : CreditCard[]mileageAccount : MileageAccountreservations : Reservation[]
ReservationEJBreservationNumber : Stringcustomer : CustomerhcreditCard : CreditCardseatClass : StringseatNumber : intdate : Dateitineraries : Itinerary[]roundTrip : boolean
0..n0..n
AirplaneEJBnumber : Stringtype : Stringmanufacturer : StringmaxSeats : int
SeatsInfoEJBseatsClass : StringmaxSeats : intavailableSeats : intprice : double
ItineraryEJBnumber : StringdepartureAirport : AirportdestinationAirport : Airportflights : Flight[]mileage : int
1..21..2
FlightEJBfl ightNumber : Stringairline : Stringduration : intdepartureDateTime : DatearrivalDateTime : DateseatsInfos : Seats Info[]distance : intfl ightLegs : Fl ightLeg[]
AirportEJBairportCode : StringairportName : String
FlightLegEJBdepartureAirportdestinationAirport
SUN J2EE Architecture
Controllers/Events/Actions
WebActionSupport
setServletContext()doStart()doEnd()
FMW ebContr ollerImpl
init()handleEvent()destroy()
FMControllerEJB
handleEvent()
WebControllerImplejbcontroller : EJBController
init()handleEvent()destroy()
EJBControllerEJBSt ateMachine st ateMachine
handleEvent()
LogonEv entuserName : Stringpassword : String
EventSupport
getEvent Name()
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[]
Flight TransactionEventAT_PAYMENTMETHODAT_CREDITCARDSELECTIONAT_CHANGEITINERARYAT_RESERVEFLIGHTactionType : StringpaymentMethod : StringselectedFlights : String[]itineraryNumber : StringreservationNumber : StringPM_CREDITCARD : StringPM_AWARDTRAVEL : String
LogonWebAction
processRequest()
UserProfileWebAction
processRequest()
FlightInfoWebAction
processRequest()
Flight Transac tionW ebAc tion
processRequest()LogonEJBAction
processEvent()
LogoffWebAction
processRequest()
EJBActionSupport
init()doStart()doEnd( )
UserProfileEJBAction
processEvent()
Flight In foEJ BAction
processEvent()
FlightTransactionEJBAction
processEvent()
ServiceLocatorImplwebController : WebControllersession : HttpSession
getWebClientController()sessionCreated()sessionDestroyed()
FMServiceLocatorImpl
getW ebClient Cont ro ller ()
SUN J2EE Architecture
Typical Web Request : ScreenFlowManager
: Web Act io n
: Req uestDispatcher : Customerh
: MainServlet : RequestProcessor : WebController : EJBControllerEJB : StateMachine
: EJBActio n
Herelogi
doPost()
forward(nextScreen)
Web Page
getNextScreen()
nextScreen
processRequest()
doStart()
p ro cessRe quest()
Event
doEnd()
handleEvent()handleEvent() processEvent
processEvent()
EventResponseEventRespo nse
EventResponseEventResponse
SUN J2EE Architecture
Price Itinerary : FlightManagementFacadeEJB : FlightInformationEJB : FlightEJB : SeatsInfoEJB : Fli ght In fo EJBActi on
getFligh tInforma ti on()
Fli ghtIn formatio n
calculateItineraryPrice()
* g etSeatsInfos()
The information which fl ights are part of the itinerary are contained in the event information.
SeatsInfos
*getPrice()
Price
summarized fl ight prices
* getFlight()
SUN J2EE Architecture
Component Diagram
Customer Tavel Agent.JAR<< fil...
MainSer vl et<<Ser vl e. ..
FlightManager.EAR<<fil...
Fli ghtM anager .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 ArchitectureEvent objects are used to pass data between the layersHeavy usage of local interfaces for EJBs (support of fine-grained objects)Web Action / EJB ActionsWeb Controller / EJB ControllerEJB/Web PackagingScreen Dispatchers / Screen Management / Screen MappingsJ2EE Patternshttp://developer.java.sun.com/developer/technicalArticles/J2EE/patternsJ2EE Blueprintshttp://java.sun.com/blueprints