Download presentation
Presentation is loading. Please wait.
Published byEmil Shields Modified over 9 years ago
1
Java Web 应用开发: J2EE 和 Tomcat 蔡 剑, Ph.D.
2
本讲内容 EJB 层技术 (II) Transaction and Security Resource Connection Deployment Web Services
3
Review: J2EE Framework (X)HTML XML Applet Client Application JAFJMSJDBC JTA JNDI JSTL Servlets JSPs Web Container Session Beans Entity Beans EJB Container J2EE Application Server RDMS Mail Server Java Application CORBA Server Directory Service Message Queue JDBC JavaMail RMI IIOP JNDI JMS HTTP Message Beans Application Client Container JAX RPC SAAJ JAXRJACC Mgmt JMX JAFJMSJDBC JTA JNDI JAX RPC SAAJ JAXRJACC Mgmt JMX JAX RPC SAAJ JAXR JMS Mgmt JMX
4
Web Application Architecture: MVC Model Model Encapsulates application state Responds to state queries Exposes application functionality Notifies views of changes Model Encapsulates application state Responds to state queries Exposes application functionality Notifies views of changes View Renders the models Request updates from models Sends user gestures to Controller Allows controller to select View View Renders the models Request updates from models Sends user gestures to Controller Allows controller to select View Controller Define application behavior Maps user actions to model updates Select view for response One for each functionality Controller Define application behavior Maps user actions to model updates Select view for response One for each functionality State Query State Change View Selection User gestures Change Notice
5
Transaction Concept begin transaction debit checking account credit savings account update history log commit transaction
6
CMT Transaction Management public void transferToSaving(double amount) throws InsufficientBalanceException { checkingBalance -= amount; savingBalance += amount; try { updateChecking(checkingBalance); if (checkingBalance < 0.00) { context.setRollbackOnly(); throw new InsufficientBalanceException(); } updateSaving(savingBalance); } catch (SQLException ex) { throw new EJBException ("Transaction failed due to SQLException: " + ex.getMessage()); }
7
BMT Transaction Management : JDBC public void ship (String productId, String orderId, int quantity) { try { con.setAutoCommit(false); updateOrderItem(productId, orderId); updateInventory(productId, quantity); con.commit(); } catch (Exception ex) { try { con.rollback(); throw new EJBException("Transaction failed: " + ex.getMessage()); } catch (SQLException sqx) { throw new EJBException("Rollback failed: " + sqx.getMessage()); }
8
BMT Transaction Management : JTA public void withdrawCash(double amount) { UserTransaction ut = context.getUserTransaction(); try { ut.begin(); updateChecking(amount); machineBalance -= amount; insertMachine(machineBalance); ut.commit(); } catch (Exception ex) { try { ut.rollback(); } catch (SystemException syex) { throw new EJBException ("Rollback failed: " + syex.getMessage()); } throw new EJBException ("Transaction failed: " + ex.getMessage()); }
9
Transaction Allowance Bean Type Container- Managed Bean- Managed JTAJDBC EntityYNN SessionYYY Message- driven YYY
10
Updating Multiple Databases
11
Resource Connections Resource Manager Type Connection Factory TypeJNDI Subcontext JDBC javax.sql.DataSourcejava:comp/env/jdbc JMS javax.jms.TopicConnectionFactor y javax.jms.QueueConnectionFactor y java:comp/env/jms JavaMail javax.mail.Sessionjava:comp/env/mail URL java.net.URLjava:comp/env/url Connector javax.resource.cci.ConnectionFa ctory java:comp/env/eis JAXR Resource Adapter javax.xml.registry.ConnectionFa ctory java:comp/env/eis/ JAXR
12
Database Connection private String dbName = "java:comp/env/jdbc/SavingsAccountDB"; InitialContext ic = new InitialContext(); DataSource ds = (DataSource) ic.lookup(dbName); Connection con = ds.getConnection();
13
EJB Deployment: Security Declare
14
Programmatic Security in the EJB Tier public String getUser() { return context.getCallerPrincipal().getName (); } boolean result = context.isCallerInRole("Customer");
15
Propagating Security Identity
16
Web Deployment: Security Declare
17
Packaging Modules EJB 模块,其包含 ejb 文件及相应类 Web 模块,其包含网络层的组件及资源 应用客户模块,其包含应用客户类 资源适配器模块,其包含 java 连接器 (connector), 资源适配器,和帮助库函数及 相关资源。
18
Deployment Configuration Files EJB 部署描述文件 网络层部署描述文件 web.xml 应用客户部署描述文件 资源适配器部署描述文件
19
EJB Deployment: Packaging
20
EJB and Web Services J2EE1.4 Web Services.Net Web Services Perl Web Services EJB2.1 Container Stateless Session Bean SOAP
21
Web Services
22
Web Services Support Web services are Web-based enterprise applications that use open, Extensible Markup Language (XML)-based standards and transport protocols to exchange data with calling clients. The J2EE platform provides the XML APIs and tools you need to quickly design, develop, test, and deploy Web services and clients that fully interoperate with other Web services and clients running on Java-based or non-Java- based platforms. It is easy to write Web services and clients with the J2EE XML APIs. No low-level programming is needed because the XML API implementations do the work of translating the application data to and from an XML-based data stream that is sent over the standardized XML-based transport protocols. The translation of data to a standardized XML-based data stream is what makes Web services and clients written with the J2EE XML APIs fully interoperable.
23
Web Services Concept
24
Web Services
25
Web Services Standards
26
Three Players of WS
27
SOAP
28
UDDI
29
WSDL
30
J2EE Web Services
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.