Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

03.egovFrame Runtime Environment Training Book


Published on

eGovFrame - Framework for e-government
Run-time Environment

  • Be the first to comment

03.egovFrame Runtime Environment Training Book

  1. 1. eGovFrame Training Book Runtime Environment eGovFrame Center 2012
  2. 2. Table of contentsI OverviewII Foundation LayerIII Persistence LayerIV Presentation Layer Page l 2
  3. 3. Runtime Environment Composition OverviewRuntime Environment is the foundation of software applications and provides the basicfunctionality required to run software eGovFrame Runtime Environment Presentation UX Business Logic Persistence Integration Layer Layer Layer Layer Layer Foundation Layer Service Group Page l 3
  4. 4. Runtime Environment Composition of eGovFrameRuntime Environment is the foundation of software applications and provides the basicfunctionality required to run an enterprise application Application Program Runtime Environment UX Layer Persistent Layer Client Screen Presentation Layer DB Biz Logic Layer Integration Layer Foundation Layer Page l 4
  5. 5. Composition of the runtime environment Composition of eGovFrameThe runtime environment consists of 6 service groups, 38 services. SupportMVC, DI, AOP, etc patterns, based on Spring framework Runtime Environment Presentation Layer UX Layer Biz Logic Persistence Layer Integration Layer Layer Ajax Support Internationalization UX/UI Controller Component Biz. Process TBD Data Access DataSource Message Service Management MVC Security HTML5 CSS3 TBD ORM Transaction Naming Service Exception Handling UI Adaptor JavaScript Module App Framework Web Service Foundation Layer AOP Cache Compress/Decompress Encryption/Decryption Excel File Handling File Upload/Download FTP Hot-Deploy ID Generation IoC Container Logging Mail Marshalling/Unmarshalling Object Pooling Property Resource Scheduling String Util XML Manipulation Page l 5
  6. 6. Composition of the runtime environment Composition of eGovFrameThe runtime environment consists of 6 service groups, 38 services. SupportMVC, DI, AOP, etc patterns, based on Spring framework Runtime Environment Presentation Layer UX Layer Biz Logic Persistence Layer Integration Layer Layer Ajax Support Internationalization UX/UI Controller Component Biz. Process TBD Data Access DataSource Message Service Management MVC Security HTML5 CSS3 TBD ORM Transaction Naming Service Exception Handling UI Adaptor JavaScript Module App Framework Web Service Foundation Layer AOP Cache Compress/Decompress Encryption/Decryption Excel File Handling File Upload/Download FTP Hot-Deploy ID Generation IoC Container Logging Mail Marshalling/Unmarshalling Object Pooling Property Resource Scheduling String Util XML Manipulation Page l 6
  7. 7. Runtime Environment OSS OverviewRuntime Environment consists of a variety of open source software Open Source S/W Version Applied Service Reference URL Spring 3.0.5 IoC Container, AOP, Property, Resource Spring Security 2.0.4 Server Security Log4j 1.3 Logging EHCache 2.4.1 Cache Commons Compress 1.1 Compress/Decompress Commons VFS 1.0 File Handling Commons FileUpload 1.2.2 File Upload/Download Commons Net 3.0.1 FTP Common Email 1.1 Mail Commons Pool 1.5.6 Object Pooling Jakarta Regexp 1.5 String Util Apache Xerces 2 2.2.9 XML Manipulation JDOM 1.1 java simplified encryption (jasypt) 1.7 Encryption/Decryption Apache POI 3.2 Excel jXLS 0.9.9 Castor 1.2 Marshalling/Unmarshalling Apache XML Beans 2.4 Quartz 1.8.5 Scheduling Page l 7
  8. 8. Features & Effects Overview Features • Adopt proven open source SW, optimized for e-government projects • Utilize Spring framework as a core foundation that is a pervasive lightweight framework • Apply DI, AOP, MVC, etc for SW architecture and implementation • Provide a common interface for integrating solutions as defining associated standard interface Effects • Improve development productivity • Improve e-government system reusability • Improve interoperability of e-government system • Standardize e-government application software • Promote Open Source Software • Enhance SMEs competitiveness Page l 8
  9. 9. RE*) Open Source - Spring Framework Overview Foundation Layer  Overview • Open source framework supports Java based enterprise applications • POJO based lightweight container (very loosely coupled) • Developed by Rod Johnson (Based on “Expert one-on-one J2EE Design and Development”)  Spring Mission and Goals • Spring should be fun and easier than J2EE in use. • Spring should not depend on the API. • Spring integrates with existing good solutions rather than competing.  EJB Problems • Heavy weight remote model • High complexity + Portability, Difficult to ensure performance and scalability· RE*) : Runtime Environment Page l 9
  10. 10. Spring Framework Composition Foundation LayerSpring Framework consists of DAO, ORM, AOP, JEE, Web, based on the core that governs theBean object life cycle Page l 10
  11. 11. IoC Container Foundation Layer Overview • Manage creating objects and object dependencies by external setting, rather than hard coding within source code • IoC is an abbreviation of the “Inversion of Control” or referred to “Reverse control” • Improve flexibility and scalability Key Features • Dependency Injection - Inject dependencies among objects in the external setting - Framework determines dependencies(objects) and relationships which will be used at run time • Bean Lifecycle Management - Manage the life cycle of object creation, destruction, etc Page l 11
  12. 12. IoC Container Foundation Layer Inversion of Control (IoC) is an object-oriented programming practice where the object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis. In traditional programming, the flow of the business logic is determined by objects that are statically assigned to one another. With IoC, the flow depends on the object graph that is instantiated by the assembler and is made possible by object interactions being defined through abstractions. The binding process is achieved through dependency injection. Inversion of control as a design guideline serves the following purposes: • There is a decoupling of the execution of a certain task from implementation. • Every module can focus on what it is designed for. • Replacing modules has no side effect on other modules. IoC Container The container is an object that implements the concept of Inversion of Control. It manages the object lifecycle from creation to destruction and takes control for all objects. Dependency Injection (DI) DI is a software design pattern that allows a choice of component to be made at run-time rather than compile time. It is a style of object configuration in which an objects fields and collaborators are set by an external entity, such as bean definition. Page l 12
  13. 13. IoC Container Foundation Layer Key Features • DI (Dependency Injection) A B C Configuration [Module Call Conceptual View – Non DI [Module Call Conceptual View –Use DI • Bean Lifecycle Management Page l 13
  14. 14. IoC Container Foundation Layer Non-IoC/DI vs IoC/DI Non-IoC/DI IoC/DI Bar Bar Foo Foo Baz Baz vs package x.y; package x.y; public class Foo { public Foo(Bar bar, Baz baz) { // ... public class Foo { } } public void process() { <beans> Bar bar = new Bar(); <bean name="foo" class="x.y.Foo"> <constructor-arg> Baz baz = new Baz(); <bean class="x.y.Bar"/> // ... </constructor-arg> } <constructor-arg> <bean class="x.y.Baz"/> } </constructor-arg> </bean> </beans> Page l 14
  15. 15. IoC Container Foundation Layer Container • creates objects and take a role as an assembler to inject dependency between Business Objects objects (POJOs) Configuration Metadata The Spring Container • represents how the Spring container Configuration instantiates, configures, and assembles the Metadata objects in an application. It is traditionally produces supplied in a simple and intuitive XML format. Fully configured system Ready for use Bean • is an object that created and managed by Spring IoC Container Page l 15
  16. 16. IoC Container Foundation Layer In Spring, the Bean Factory is an IoC container to control beans and inject dependency among them. The Application Context is springs more advanced container(include Bean Factory) and it adds more enterprise-specific functionality. Normally, the Application Context is used over the BeanFactory. BeanFactory • The Bean Factory is the actual container which instantiates, configures, and manages a number of beans. (ex: dependency injection, bean lifecyclemanagement) • It is represented by the interface org.springframework.beans.factory.BeanFactory, for which there are multiple implementations. Application Context • Extend BeanFactory interface and add functionality such as Spring AOP, message resource, internationalization, event processing, etc to develop and run an enterprise application • As the ApplicationContext includes all functionality of the BeanFactory, it is generally recommended that it be used over the BeanFactory Page l 16
  17. 17. IoC Container Foundation Layer Injection Type • Constructor Injection : Configuring dependency through an argument constructor • Setter Injection : Configuring dependency through setters on the object. package x.y; <beans> <bean name="foo" class="x.y.Foo"> public class Foo { <property name="bar"> public void setBar(Bar bar) { <bean class="x.y.Bar" /> // ... </property> } <property name="baz"> <bean class="x.y.Baz" /> public void setBaz(Baz baz) { </property> // ... </bean> } </beans> } Page l 17
  18. 18. IoC Container Foundation Layer XML configuration file • Bean configuration file has <beans/> as root, and provides related Namespace and Schema <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="" xmlns:xsi="" xsi:schemaLocation=""> <bean id="..." class="..."> <!-- collaborators and configuration for this bean go here --> </bean> <bean id=“xmlEmpDAO” class=“egovframework.example.service.impl.XmlEmpDAO“ /> <bean id=“xmlEmpService” class=“egovframework.example.service.impl.XmlEmpServiceImpl” > <property name=“xmlDAO” ref=“xmlEmpDAO” /> </bean> <bean name=“otherExampleBean” class=“egovframework.example.OtherExampleBean“ /> </beans> Page l 18
  19. 19. IoC Container Foundation Layer Annotation • Available to use Java annotation instead of XML configuration files (Java 5 or higher) • As using annotation, simplify configuration files, and mapping between view pages and objects or methods can be clearly defined. Page l 19
  20. 20. IoC Container Foundation Layer Annotation Type • Using Java Annotation, Spring Bean definitions can be set, then need to add namespace and element <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="" xmlns:xsi="" xmlns:context="" xsi:schemaLocation=""> <context:annotation-config/> </beans> Page l 20
  21. 21. IoC Container Foundation Layer Auto Scan, based on Annotation • Normally declaring all the beans or components in XML bean configuration file, so that Spring container can detect and register beans or component. • Spring is also able to auto scan, detect and instantiate beans from pre-defined project package. • ‘base-package’ attribute is the basic package to find components, can be assigned multiple package with ‘,’ separation mark. • <context:exclude-filter> tag and <context:include-filter> tag are used to state what component is included or excluded to the scanning <?xml version="1.0" encoding="UTF-8"?> <beans ··· > <context:component-scan base-package=“egovframework“/> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/> </context:component-scan> </beans> Page l 21
  22. 22. IoC Container Foundation Layer Annotation type • @Required : Applied to setter method, mark a property as being required-to-be-set (i.e. an annotated (setter) method of a class must be configured to be dependency injected with a value) ethods public class SimpleMovieLister { // the SimpleMovieLister has a dependency on the MovieFinder private MovieFinder movieFinder; // a setter method so that the Spring container can inject a MovieFinder @Required public void setMovieFinder(MovieFinder movieFinder) { this.movieFinder = movieFinder; } // business logic that actually uses the injected MovieFinder is omitted... } • @Autowired : auto wire a bean on the setter method, constructor or a field. It can autowire property in a particular bean • @Resource : marks a resource that is needed by the application. It finds the target bean with name @Service public UserServiceImpl implements UserService { @Resource (name="userDAO") private UserDAO userDAO; } • @PostConstruct, @PreDestroy : Use to assign Instantiation callback, Destruction callback methods Page l 22
  23. 23. IoC Container Foundation Layer @Resource @Resource annotation의 name 값으로 대상 bean을 찾을 수 있다. @Resource annotation은 field 또는 메소드에 사용할 수 있다. public class SimpleMovieLister { private MovieFinder movieFinder; @Resource(name="myMovieFinder") public void setMovieFinder(MovieFinder movieFinder) { this.movieFinder = movieFinder; } } Page l 23
  24. 24. IoC Container Foundation Layer Auto-detecting components • Set Name- Set bean name with @Component, @Repository, @Service, @Controller annotation’s name value @Service("myMovieLister") @Repository public class SimpleMovieLister { public class MovieFinderImpl implements MovieFinder { // ... // ... } } ApplicationContext for web application • Spring provides classes for easy WebApplicationContext setting • Add following settings in web.xml for ApplicationContext setting with the Listener (Servlet 2.4 or later) <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> Page l 24
  25. 25. AOP Foundation Layer Overview • Aspect-oriented programming (AOP) is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns • AOP is programming techniques to support the processing of modularizing Logging, security, transactions, and common functions without changing existing business logic Configuration File AOP Applied OOP OOP + AOP Page l 25
  26. 26. AOP Foundation Layer Main Concept • Advice, JoinPoint, Pointcut, Weaving, Aspect Pointcut JoinPoint Weaving Advice Benefits • Remove duplicate code • Improve readability of the business logic • Improve productivity • Improve reusability • Increase ease of change Page l 26
  27. 27. AOP Foundation Layer Relations for AOP components A set of Join point Join point is the time (condition: select*) which a method is called in Spring Source Code EmployeeService Aspect 소스코드 Processing what you want to apply insertEmployee() updateEmployee() Pointcut selectEmployeeList() Advice selectEmployee() deleteEmployttList() Joinpoint Page l 27
  28. 28. AOP Foundation Layer Develop functions of cross-cutting concerns (Create Advice) • Advice, JoinPoint, Pointcut public class AdviceUsingXML { public void beforeTargetMethod(JoinPoint thisJoinPoint) { Class clazz = thisJoinPoint.getTarget().getClass(); String className = thisJoinPoint.getTarget().getClass().getSimpleName(); String methodName = thisJoinPoint.getSignature().getName(); // Obtain the target method Logger and log the current class and method status information Log logger = LogFactory.getLog(clazz); logger.debug(className + "." + methodName + " executed."); } } Apply AOP (Create setting file) • Remove duplicated code <aop:config> <aop:pointcut id="targetMethod" expression="execution(* egovframework.rte.fdl.aop.sample.*Sample.*(..))" /> <aop:aspect ref="adviceUsingXML"> <aop:before pointcut-ref="targetMethod" method="beforeTargetMethod" /> </aop:aspect> </aop:config> Page l 28
  29. 29. Data Source Persistence Layer Overview • Service for providing database connection • Remove dependencies about business logic and database connection Key Features • Service to connect database - Create database connection, using JDBC driver <bean id="dataSource” class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${driver}" /> <property name="url" value="${dburl}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> </bean> • driverClassName : JDBC driver class name • url : Database access JDBC URL • username : Database access username • password : Database access password Page l 29
  30. 30. Data Source Persistence Layer Key Features • DBCP DataSource - Database connection module, using JDBC driver. This is database connection pool, called Commons DBCP in Jakarta projects. <bean id="dataSource” class="org.apache.commons.dbcp.BasicDataSource” destroy-method="close"> <property name="driverClassName" value="${driver}" /> <property name="url" value="${dburl}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="defaultAutoCommit" value="false" /> <property name="poolPreparedStatements" value="true" /> </bean> • driverClassName : jdbc driver class name • url : DataBase url • username : DataBase access user name • password : DataBase access password • defaultAutoCommit : configure auto-commit function about connection • poolPreparedStatements : PreparedStatement configuration (user or not) Page l 30
  31. 31. Data Access Persistence Layer Overview • Provide a service to respond in a consistent manner for a variety of database solutions and database access technologies • Improve business efficiency by providing abstract data access method • SQL statement can be mapped easily to JavaBeans(or Map), using iBATIS which apply simple XML technology rather than java code to access a relational database Key features • Provide an abstraction access method for JDBC (Do not directly call JDBC related API) • Support removing SQL statement from Java source code (Ensure ease of management / maintenance / tuning) • Support various binding/mapping for input/output objects of Query execution • Support dynamic query change through dynamic SQL • Support a variety of DB processing (Batch SQL, Paging, Callable statement, BLOB/CLOB, etc) Page l 31
  32. 32. Data Access Persistence Layer Features • iBATIS is a persistence framework that emphasize on simplicity and minimize the repetitive and complex DB query using SQL Map - Support Stored Procedure with XML or mapping between SQL statements and Java objects, as emphasis on simplicity, one of iBATIS main ideas - Persistence framework, developed by Clinton Begin(Apache Software Foundation) in 2001 Elements iBATIS Hibernate comparison Hibernate takes more time due to Round Trip Delay Time Short Long features such as automatic generation of query Flexibility Good Poor Learning Curve Short Long iBATIS is much more similar to JDBC SQL knowledge Should be higher Do not required much Page l 32
  33. 33. Spring with iBatis Persistence Layer Spring and iBATIS • In order to use iBATIS in Spring, define the sqlMapClient of iBATIS like below • Bean definition (context-sqlMap.xml) - id and class name are fixed values - dataSource : make Spring manages DataSource as using DataSource bean id which configured in Spring - configLocation : configure the location of SqlMap Configuration file다 <beans . . .> <!-- SqlMap setup for iBATIS Database Layer --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean" p:dataSource-ref="dataSource" p:configLocation-ref="classpath:/egovframework/sqlmap/rte/sql-map-config.xml" /> </beans> Page l 33
  34. 34. Spring with iBatis Persistence Layer Persistence Layer development sequence, using iBATIS • Define SqlMapClient Bean (context-sqlMap.xml) • Define the location of SQL Map XML in SQL Map Config XML • Configure SQL related information in SQL Map XML files • Create a DAO class Extends EgovAbstractDAO class which inherits SqlMapClientDaoSupport to make DB query and run, using SQL Map XML query id Page l 34
  35. 35. MVC Presentation Layer Overview • MVC(Model-View-Controller) pattern separates code by Model, View, Controller 3 factors, depending on functions - Model : objects include application data and business logic - View : display the information of model to users - Controller : intermediary of Model and View (Reflect the status of model change, based on the user request and select view for a response) • MVC pattern reduces dependency by separating the UI code and business code, increases reusability and can be easier to change • Though ‘MVC pattern’ is not used only for Web Framework, ‘MVC service’ in eGovFrame means Web MVC Framework utilizing MVC pattern Page l 35
  36. 36. MVC Presentation Layer Relationship and flow between Spring MVC components • When client’s request comes in, the DispatcherServlet first receives the request. • The DispatcherServlet consults the HandlerMapping and invokes the Controller associated with the request. • The Controller process the request by calling the appropriate service methods and returns a ModeAndView object to the DispatcherServlet. The ModeAndView object contains the model data and the view name. • The DispatcherServlet sends the view name to a ViewResolver to find the actual View to invoke. • Now the DispatcherServlet will pass the model object to the View to render the result. • The View with the help of the model data will render the result back to the user. Page l 36
  37. 37. MVC Presentation Layer Spring MVC core components • DispatcherServlet - The front controller of Spring MVC Framework. Supervise life cycle of web request and respond. • HandlerMapping - Decide which controller will process the target URL when web request comes in. • Controller - Perform the business logic and the result data is reflected in the ModelAndView. • ModelAndView - Consist of model data object which reflects controller’s result and target page information (or view object). • ViewResolver - Provide a mapping between view names and actual views. • View - Display the model object which is result data. Page l 37
  38. 38. Page l 38