Data Service Patterns Jeff Zhuk

Similar documents
Creating Web Application with BEA WebLogic Workshop. Jeff (Yefim) Zhuk

From the book. Integration-Ready Architecture and Design. Cambridge University Press

JDBC [Java DataBase Connectivity]

Java Technologies Resources and JNDI

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

PHP Development for ClearPath. Session 3028, Tuesday, May 15, 2012, 10:30AM Ron Neubauer, Principal Engineer, Unisys Corporation

JavaEE Interview Prep

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

WHAT IS EJB. Security. life cycle management.

Prototype 1.0 Specification

Chapter 1. JOnAS and JMX, registering and manipulating MBeans

Excel4apps Wands 5 Architecture Excel4apps Inc.

Table of Contents. Introduction... xxi

1Z Java SE 5 and 6, Certified Associate Exam Summary Syllabus Questions

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

Questions and Answers

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Author - Ashfaque Ahmed

Fast Track to Java EE 5 with Servlets, JSP & JDBC

Oracle 10g: Build J2EE Applications

Struts interview questions

Fast Track to Java EE

Application Development Issues. Overview: Velocity: what is it, what is it good for? Part 1: Code Generators Part 2: Web Applications With Velocity

Web Applications and Database Connectivity using JDBC (Part II)

COURSE DETAILS: CORE AND ADVANCE JAVA Core Java

Building Web Applications With The Struts Framework

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

Peers Techno log ies Pv t. L td. Core Java & Core Java &Adv Adv Java Java

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

JSP. Common patterns

ADVANCED JAVA COURSE CURRICULUM

Oracle Retail Accelerators for WebLogic Server 11g

Enterprise Java Technologies (Part 1 of 3) Component Architecture. Overview of Java EE. Java Servlets

Refactoring to Seam. NetBeans. Brian Leonard Sun Microsystems, Inc. 14o

Advanced Web Technology - Java Server Faces

INTRODUCTION TO COMPONENT DESIGN IN JAVA EE COMPONENT VS. OBJECT, JAVA EE JAVA EE DEMO. Tomas Cerny, Software Engineering, FEE, CTU in Prague,

LTBP INDUSTRIAL TRAINING INSTITUTE

JAVA SYLLABUS FOR 6 MONTHS

Apcoordinator User's Guide J2X ENZ2(00)

Oracle EXAM - 1Z Java EE 6 Enterprise JavaBeans Developer Certified Expert Exam. Buy Full Product.

A JavaBean is a class file that stores Java code for a JSP

The Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4

Contents. 1. JSF overview. 2. JSF example

Deployment Manual. SAP J2EE Engine 6.20

Module 3 Web Component

IBM Operational Decision Manager Version 8 Release 5. Configuring Operational Decision Manager on WebLogic

SpagoBI Server installation on JBoss. Alessandra Toninelli 2013/11/04 11:36

Complete Java Contents

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Getting Social with Digital Messaging Server. Jim Crespino Director, Developer Enablement

Enterprise JavaBeans. Layer:08. Persistence

Tutorial: Developing a Simple Hello World Portlet

ive JAVA EE C u r r i c u l u m

JAVA MICROSERVICES. Java Language Environment. Java Set Up. Java Fundamentals. Packages. Operations

Using SailFin and Eclipse to build SIP-based and RESTful applications

web.xml Deployment Descriptor Elements

Chapter 2 WEBLOGIC SERVER DOMAINS. SYS-ED/ Computer Education Techniques, Inc.

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

Oracle 1Z Java EE 6 Web Component Developer(R) Certified Expert.

HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests

The Struts MVC Design. Sample Content

Oracle EXAM - 1Z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Buy Full Product

J2EE - Version: 25. Developing Enterprise Applications with J2EE Enterprise Technologies

Struts Lab 3: Creating the View

OSCAR Documentation ) Developers For developer registration the java and jsp files involved are the following

NetBeans IDE Field Guide

JBoss Enterprise Application Platform 5

Process Commander Installation Guide

Contents at a Glance

Shale and the Java Persistence Architecture. Craig McClanahan Gary Van Matre. ApacheCon US 2006 Austin, TX

Java Server Page (JSP)

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC.

Orgnazition of This Part

CA IdentityMinder. Glossary

Exam Questions 1Z0-895

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

Specialized - Mastering JEE 7 Web Application Development

Distributed Multitiered Application

Deccansoft Software Services. J2EE Syllabus

Backend. (Very) Simple server examples

Jakarta Struts: Declarative Exception Handling

Teamcenter Global Services Customization Guide. Publication Number PLM00091 J

Important notice regarding accounts used for installation and configuration

Customizing the WebSphere Portal login and logout commands

Vendor: SUN. Exam Code: Exam Name: Sun Certified Web Component Developer for J2EE 5. Version: Demo

Jakarta Struts: An MVC Framework

Programming with the SCA BB Service Configuration API

Programming with the SCA BB Service Configuration API

Server Extensions Developer Guide

User Manual. KSU Student Portal. Version 1.0. Submitted in partial fulfillment of the requirements of the degree of MSE

Programming with the SCA BB Service Configuration API

OpenClinica: Towards Database Abstraction, Part 1

BEA WebLogic. Server. MedRec Clustering Tutorial

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

Strecks Java 5 Extensions

4.1 The Life Cycle of a Servlet 4.2 The Java Servlet Development Kit 4.3 The Simple Servlet: Creating and compile servlet source code, start a web

idashboards Administrator s Manual Version 7.5

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

KS CM 2.0 Implementation and Deployment Guide

Transcription:

Data Service Patterns Jeff Zhuk From the book and beyond Integration-Ready Architecture and Design Cambridge University Press Software Engineering With XML, Java,.NET, Wireless, Speech and Knowledge Technologies

e-business e-government e-training Login Common Use Cases Policy Maker Admin Change Business Rules Change User Roles Access Rules: Accessibility Single Sign-On Role based Access User Privacy Control Device Independence User Registrar Registration Recognize Common Problems and Use Design Patterns Member Customize Search Content Management Knowledgebase User Profile Content Management Authoring, Update, Versioning Forms, Permits, Applications Scheduling events/facilities Workflow Routing Planning and Approval Document/Photo Imaging Task Tracking and Reporting Data and Service Evaluation Collaboration Collaboration Email Conferencing Instant Messaging Privilege-based Data/Service Sharing Search Search for Data and Services GIS (Maps and Routes) Linking Related Cases Content-based Subscription

Cross Application Reuse Areas Initialization Data Access Security More See http://javaschool.com/school/public/jz.hints.htm for design and coding hints

Struts-config.xml Action-JSP map Client(s) Web Browser Http Post/Get Data Intensive Web Application Submit Form Display Page Web Tier Generic Data Action Extract business data Receive the Forward value and map to a JSP Web Tier JSPs (Forms) App Sever A set of Specific Actions use DataService to execute dynamic queries and provide object processing PooledConnection Create Select Update Insert Delete Database Read SQL and replace variables with field values from a form The DataAction alone with the DataService implement common functions and provide generic application behavior. SQL Statement Resources

Sequence Diagram DataAction Specific Service Action DataService Client Events/Operations Http Post/Get Extract data from the page and call a proper service Request SQL execution with SQL statement name and map of parameters Specific processing; Work with objects and prepare data for JSP Pass data saved in data beans, Session, or Request objects to JSP Generic data processing: Retrieve SQL from resources; Replace run-time variables; Execute SQL, process ResultSet (if any) and return a list of object-beans Map the Forward value to a proper JSP (via Struts-config.xml) and display the next JSP page

HTTPServlet Action DataAction keys: HashMap execute() abstract perform() OMD ServletContextListener interface ITSServletContextListener contextinitialized() init data initialize() to be overriden by a subclass MyServletContextListener initialize() custom initialization SpecificAction1 specificdata perform() SpecificAction2 specificdata perform() Legend: Java library Custom Library in the com.util.jar Java classes we need to code Uses DataService datasource DataSource datasources Hashtable getdata(sqlname, map, bean.class) : List setdata(sqlname, map) setdatasource(ds) Uses

Generic DataAction Code public class DataAction extends org.apache.struts.action.action { private static Logger log = Logger.getLogger("DataAction"); protected HashMap keys; public ActionForward execute(actionmapping map,.) { // generic code in the execute() method String forwardto = null; keys = preparekeys(request); // capture form and other key data try { // perform specific action implemented in a subclass forwardto = perform(request); catch(exception e) { log.severe(getclass().getname() + " e="+e); // prepare message for a generic error page request.setattribute("msg", e.getmessage()); throw e; forward = map.findforward(forwardto); // ActionMapping map return (forward); public String perform(httpservletrequest request) throws Exception { return null;

Specific Action Implementation Example public class LoginAction extends DataAction { public String perform(httpservletrequest request) throws Exception { List beans = DataService.getData( "getlogin", // name of the SQL file is getlogin.sql keys, // HashMap of key-values collected by DataAction LoginBean.class); // class that matches expected record structure if(beans.size() == 1) { // SUCCESS! //Create instance of SessionBean and bind it to session SessionBean sessionbean = new SessionBean(); LoginBean bean = (LoginBean) beans.get(0); sessionbean.setusername(bean.getloginname()); session.setattribute( sessionbean, sessionbean); return success ;. return failure ;

package beans; LoginBean Class Example import java.util.hashmap; import java.util.logging.logger; /** * The LoginBean class matches the record selected by the getlogin.sql */ public class LoginBean { private String loginname; private String password; // add getter and setter methods for data members above!!! public String getloginname() { return loginname; // TODO more getter and setter methods

Initialization with web.xml public class ITSServletContextListener implements ServletContextListener { // This method is called at application start time public void contextinitialized(servletcontextevent sce) { ServletContext servletcontext = sce.getservletcontext(); String sqllocation = servletcontext.getinitparameter( sqllocation"); String jndiname = "java:"+servletcontext.getinitparameter("datasource"); InitialContext context = new InitialContext(); DataSource datasource = (DataSource)context.lookup(jndiName); // get other DataSource names, like ITSDataSource // JBoss deploy directory will include your oracle-ds.xml or similar file // that associate this name with a connection string and a driver com.its.util.dataservice.setsqllocation(sqllocation); com.its.util.dataservice.setdatasource(datasource); // The initialize() method is overriden in the MyServletContextListener public void initialize(servletcontextevent sce) { // app-specific init public void contextdestroyed(servletcontextevent sce) {

Provide DataSource Names and SQL Location in the WEB.XML file -------------------------------------- Extract from WEB.XML ---------------------------------- <listener> <listener-class>your.package.myservletcontextlistener</listener-class> </listener> <context-param> <param-name>sqllocation</param-name> <param-value>sql</param-value> </context-param> <context-param> <param-name>datasource</param-name> <param-value>specificdatasourcenameprovidedinjboss_ds_file </param-value> </context-param> <context-param> <param-name>anotherdatasource</param-name> <param-value>anotherspecificdatasourcenameprovidedinjboss_ds_file </param-value> </context-param> ------------------------------------------------------------------------------------------------------ Recommendations: Use DataSource for most frequently used data Use AnotherDataSource names like MyAppDataSource for other data

SQL Statements SQL statements are stored as separate files in the SQL directory in the WEB-INF area Samples below demonstrate how SQL statements and their usage by DataService methods // List beans = DataService.getData("getLogin", keymap, LoginBean.class); Two lines below is stored in the getlogin.sql file select username, password from LoginTable where username = ':loginname' and password = ':password // int nrecords = DataService.setData( insertuser, map); The line below is stored in the insertuser.sql file Insert into LoginTable values(':loginname, ':password ) Note that run-time variable names follow the :" character

DataService API Include the library com.its.util.jar in the CLASSPATH and import com.its.util.dataservice // execute insert/delete/update SQL statements stored in the sqllocation @ param sqlstatementname for example getlogin stored as the getlogin.sql @ param map of key-values to replace SQL <<keys>> with run-time values @ return numberofrowseffected public static int setdata(string sqlstatementname, HashMap map) // use other than DataSource connection pool public static int setdata(string sqlstatementname, HashMap map, String dsname) // execute select statement and return a list of record-beans @ param sqlstatementname for example getlogin stored as the getlogin.sql @ param map of key-values to replace SQL <<keys>> with run-time values @ param beanclass (e.g. LoginBean.class) supports records retrieved by the SQL statement @ return list of objects of the beanclass public static List getdata(string sqlstatementname, HashMap map, Class beanclass) // use other than DataSource connection pool public static List getdata(string sqlname, HashMap map, Class beanclass, String dsname) @param datasource your DataSource specified in JNDI context @param datasourcename of your DataSource specified as JNDI name public static void setdatasource(datasource datasource, String dsname) public static void setdatasource(datasource datasource)

More DataService API // execute insert/delete/update SQL statements @ param sqlstatement @ return numberofrowseffected public static int setdata(string sqlstatement) // use other than DataSource connection pool public static int setdata(string sqlstatement, String dsname) // execute select statement and return a list of record-beans @ param sqlstatement @ param beanclass supports records retrieved by the SQL statement @ return list of objects of the beanclass public static List getdata(string sqlstatement, Class beanclass) // use other than DataSource connection pool public static List getdata(string sqlstatement, Class beanclass, String dsname) // If application creates data from scratch no SQL is needed boolean createtable(string tablename, Class class) Example: DataService.createTable( LoginTable, LoginBean.class); int insert(string tablename, Object[] objects) Example: LoginBean[] logins; // array of beans populated in an action int nrows = DataService.insert( LoginBean, logins);

IOMaster API Include the library com.its.jar in the CLASSPATH Import com.its.util.iomaster; // start server daemon and assign service processing point public static void startserverdeamon(int iport, String servicename, String methodname) // request service from a client and receive service response public static String clientsocketrequest( String ihost, int iport, String imessage) // write a file with array of bytes public static boolean writebinfile(string ifilename, byte[] idata) // read a file public static byte[] readbinfile(string filename)

Secure Web 1. Use HTTPS in all applications 2. Re-direct all HTTP://... front pages to HTTPS://...443 3. Avoid FTP access as not secure 4. Use SSLSocket to transfer data between hosts (available since JDK1.4) 5. Prefer POST to GET method, avoid links that reveal data 6. Hide link URL with Java Script 7. Use Java Script to prevent View Source actions Example: <a href=http://javaschool.com onmouseover=\"document.status= Text you want to display'; return true;\" onmouseout=\"document.status=''; return true;\" >Link</a>