Library Example February 2010 – August 2010

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialistica in Informatica – Università di Trento.
Advertisements

Communicating in J2EE.
12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
JSP and web applications
Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 12. November 2009.
JSF Portlet Backing Beans and UI Components Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Development and Deployment Roles Venugopal Pakanati.
JBoss Seam: Contextual Components Jason Bechtel
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 14: Naming.
EJB Development and Support Services. EJB Development and Support Services Topics to be Covered: EJB Design Bean/Container Interaction Java Naming and.
Current Topics in Programming Languages Lecture 15_1 George Koutsogiannakis SUMMER
1 Lecture 18 George Koutsogiannakis/Spring 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
Creating of Rich Client Applications using NetBeans 6 and Java Swing Miroslav Nachev.
JNDI Java Naming and Directory Interface See also:
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
1 The JNDI ENC and Injection Every EJB container that is deployed in an application server has its own personal internal registry called the Enterprise.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
4-Tier Model Client Tier Web Tier Business Tier EIS Tier.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
1 Security Most Java EE applications need to provide identity to users who access them and security for that access. Applications may want to prevent hostile.
1 Lecture 15 George Koutsogiannakis SUMMER 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
SelfDiagnose “who is to blame” ernest micklei, April 2007.
Chapter 3 Vector Class. Agenda Design and Implementation of Vector class – add, get, set remove, copy, equals, ensureCapacity Hangman using Vector class.
Enterprise JavaBeans EJB Container Services. EJB container Enterprise JavaBeans are deployed in an EJB container within the application server EJB container.
Session Beans Overview EJB container Remote Invocation Represent client's access to app Local / Remote speed / flexibility trade-off when to choose local.
Enterprise JavaBeans Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
JavaServer Faces Anti-Patterns Dennis Byrne - ThoughtWorks
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
TDDD05 EJB Lab (Part of slides reused from Mikhail’s) Lu Li
Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat
J2EE Structure & Definitions Catie Welsh CSE 432
1 Lecture 16 George Koutsogiannakis/SUMMER 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Topic : JNDI Kaster Nurmukan. JNDI2(c)CDAC(Formerly NCST) What is JNDI? Naming and Directory Services Naming Concepts Issues JNDI Architecture Programming.
A TUTORIAL TO USING EJBs by SHREERAM IYER 09/17/2001.
Ch 2 – Application Assembly and Deployment COSC 617 Jeff Schmitt September 14, 2006.
Fall CIS 764 Database Systems Engineering L7. EJB’s.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
Presentation & Business Tier Design Patterns Pearce.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Sakai code exercises Aaron Zeckoski.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
Enterprise JavaBeans Session Beans. Session beans are a type of Enterprise JavaBean component designed to implement business logic responsible for managing.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
DEVELOPING ENTERPRISE APPLICATIONS USING EJB
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
D Copyright © 2004, Oracle. All rights reserved. BMP Entity EJBs J2EE Connector Architecture.
Introduction to OSGi +ActorFrame Surya Bahadur Kathayat
Enterprise Java v JNDI Enterprise Naming Conext (ENC) and Injection JNDI ENC.
EJB Enterprise Java Beans JAVA Enterprise Edition
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
Interstage BPM v11.2 1Copyright © 2010 FUJITSU LIMITED INTERSTAGE BPM API DEVELOPMENT.
Современные технологии баз данных Лекция 7. Объектно-реляционное отображение (ORM) Технология отображения объектов какого- либо объектно-ориентированного.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Introduction to Java Server Faces (covered topics) ● Reasons to use „Java Server Faces“ ● JSF application structure ● JSF component model ● JSF managed.
Transactions and Security. Contents  Transactions  Transaction Support in EJB  Security  Security Support in EJB.
Principles of Software Development
J2EE Application Development
null, true, and false are also reserved.
Developing Java Applications with NetBeans
Introduction to Session beans
Developing Java Applications with NetBeans
Aspect Oriented Programming
Plug-In Architecture Pattern
Presentation transcript:

Library Example February 2010 – August

Contents Creating a Library Session Bean 1.Current situation 2.Desired new situation 3.IF project for connecting the front-end 4.EJB project for business logic 5.JAAS project for authentication 6.Client project for testing the EJB 7.JSF project for deploying the ABC-Library

Current Situation UML(1) public interface LibraryManagerIF HashSet allCustomers(); HashSet allBooks(); HashSet allBooks(String name) String addCredits(String name, int credits) String lend(String title, String name) String newBook(String title) String newCustomer(String name) String removeBook(String title) String removeCustomer(String name) String unlend(String title) public interface LibraryManager implements

Current Situation UML(2) public class Book private static HashMap books = new HashMap (); static Book findBook(String title) static void removeBook(String title) static HashSet allBooks() private String title = null; private Customer lendTo = null; Book(String newTitle) public String getTitle() Customer getLendTo() void setLendTo(Customer customer) public class Customer private static HashMap customers = new HashMap (); static Customer findCustomer(String name) static void removeCustomer(String name) static HashSet allCustomers() private String name = null; private int credits = 0; private HashSet books = new HashSet (); Customer(String newName) public String getName() int getCredits() void setCredits(int newCredits) HashSet getBooks() void addBook(Book book) void removeBook(Book book)

Current Situation UML(3) public class LibraryAdmin public LibraryAdmin() public static String[] check(String usr, String pwd) class LibraryPrincipal public static final String MANAGER = "manager"; public static final String ADMINISTRATOR = "administrator"; public static final String CASHIER = "cashier"; private static HashMap principals = new HashMap (); static LibraryPrincipal findLibraryPrincipal(String name) private String name = null; private String password = null; private String[] roles = null; LibraryPrincipal(String newName, String newPassword, String[] newRoles) String getName() String getPassword() String[] getRoles()

Current Situation The given ABC-Library-Model has no real database! It’s “java-database” is implemented by HashMap attributes in the Book & Customer classes. The 6 Library classes are packed in a jar-file and becomes an integral part of the JBoss lib. This package is to be used by a MVC (JSF) frontend. There is no Authentication and Confidentiality yet! No separate logging! ABC-Library should be a separate module in Jboss and not part of JBoss? Adding a database is a JBoss Service. conf C:\jboss GA\server\default data deploy deployers lib log tmp work ABC-Library.jar

ABC-LibraryIF.jar ABC-Library-EJB.jar Desired New Situation UML LibraryManagerBean LibraryManagerIF Book Customer conf C:\jboss GA\server\default data deploy deployers lib log tmp work ABC-Library-JAAS.sar ABC-Library-EJB.jar ABC-Library-IF.jar implements ABC-Library-Client LibraryAdminBean CustomerDAO LibraryPrincipal Log BookDAO Main ABC-Library-JAAS LoginModule

New Situation Create Interace projectEJB means creating a Stateless Session Bean. It’s convenient to make 5 projects: 1.IF project 2.EJB project 3.JAAS project 4.Client project 5.JSF project The IF project is part of all other projects. The minimum testable configuration is IF, EJB and JAAS. After a successful test we create(copy) the front-end project, remove the model ABC-Library.jar and make a connection to the enterprise back-end.

IF Project. 1.Create in eclipse a new java-project 2.Create a new directories “src” 3.Set project properties: 1.Java Build Path 2.Source = “src” 3.Default output folder = “classes” 4.Copy from model to “src”: LibraryManagerIF 5.Change Book→BookDAO and Customer → CustomerDAO 6.Create serializable data classes BookDAO and CustomerDAO 7.Update a copy an old build,xml file for deploying IF

IF Project. 1.Create in eclipse a new java-project 2.Create a new directory “src” 3.Set project properties: 1.Java Build Path 2.Source = “src” 3.Default output folder = “classes” 4.Copy from model to “src”: LibraryManagerIF 5.Create a new interface LibraryAdminIF 6.Change Book→BookDAO and Customer → CustomerDAO 7.Create serializable data classes BookDAO and CustomerDAO 8.Update a copy an old build,xml file for deploying IF

Bean Interfaces. package efg.library.IF; import public interface LibraryAdminIF { String[] check(String usr, String pwd); } package efg.library.IF; import java.security.Principal; import java.util.HashSet; import public interface LibraryManagerIF { Principal getPrincipal(); HashSet allCustomers(); HashSet allBooks(); HashSet allBooks(String name) throws Exception; String addCredits(String name, int credits) throws Exception; String lend(String title, String name) throws Exception; String newBook(String title) throws Exception; String newCustomer(String name) throws Exception; String removeBook(String title) throws Exception; String removeCustomer(String name) throws Exception; String unlend(String title) throws Exception; } By default all methods are public

DAO Data Access Object. public class BookDAO implements Serializable { private static final long serialVersionUID = L; private String title = null; private String lendTo = null; public void setTitle (String newTitle) { title = newTitle; } public void setLendTo(String newLendTo){ lendTo = newLendTo; } public String getTitle() { return title; } public String getLendTo(){ return lendTo; } } public class CustomerDAO implements Serializable { private static final long serialVersionUID = L; private String name = null; private int credits = 0; private HashSet titles = new HashSet (); public void setName( String newName) { name = newName; } public void setCredits(int newCredits) { credits = newCredits; } public void addTitle (String newTitle) { titles.add(newTitle); } public void setBooks (HashSet newTitles) { titles = newTitles; } public String getName() { return name; } public int getCredits() { return credits;} public HashSet getBooks() { return titles; } }

build.xml IF Project.

EJB Project. 1.Create in eclipse a new java-project 2.Create a new directory: “src” 3.Set project properties: 1.Java Build Path 2.Source = “src” 3.Default output folder = “classes” 4.Project = Interface project 5.External jar = jboss-ejb3x.jar 4.Copy from model to src: LibraryManager →LibaryManagerBean 5.Add Annotations to LibraryManagerBean 6.Add one new public method: Principal getPrincipal() 7.Update a copy an old build.xml file for deploying

public class LibraryManagerBean implements LibraryManagerIF private EJBContext context = public Principal getPrincipal() { return context.getCallerPrincipal(); public HashSet allBooks() { return Book.allBooks(); }... before every method

LibraryAdminBean package efg.library; import javax.ejb.Stateless; import public class LibraryAdminBean implements LibraryAdminIF { public LibraryAdminBean() { System.out.println("LibraryAdmin()"); } public String[] check(String usr, String pwd) { System.out.println("LibraryAdmin.check("+usr+", "+pwd+")"); LibraryPrincipal principal = LibraryPrincipal.findLibraryPrincipal(usr); if (principal != null && pwd.equals(principal.getPassword())) { return principal.getRoles(); } return null; }

EJB Project - build.xml

EJB JNDI view java:comp namespace of the component jboss.j2ee:jar=P1-ABC-Library-EJB.jar,name=LibraryAdminBean,service=EJB3 : +- EJBContext (class: javax.ejb.EJBContext) +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef) +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl) +- env (class: org.jnp.interfaces.NamingContext) +- ORB[link -> java:/JBossCorbaORB] (class: javax.naming.LinkRef) Global JNDI Namespace +- LibraryAdminBean (class: org.jnp.interfaces.NamingContext) | +- local (class: Proxy for: efg.library.IF.LibraryAdminIF) | +- local-efg.library.IF.LibraryAdminIF (class: Proxy for: efg.library.IF.LibraryAdminIF) +- LibraryManagerBean (class: org.jnp.interfaces.NamingContext) | +- remote (class: Proxy for: efg.library.IF.LibraryManagerIF) | +- remote-efg.library.IF.LibraryManagerIF (class: Proxy for: efg.library.IF.LibraryManagerIF)

JAAS Project public boolean login() throws LoginException { try { InitialContext ctx = new InitialContext(); LibraryAdminIF libraryAdmin = (LibraryAdminIF)ctx.lookup("LibraryAdmin/local"); String[] myroles = libraryAdmin.check(username, password); if (myroles != null) { roles = new MyGroup("Roles"); for (int i=0; i<myroles.length; i++) { roles.addMember(new MyPrincipal(myroles[i])); } callerPrincipal = new MyGroup("CallerPrincipal"); callerPrincipal.addMember(new MyPrincipal(username)); ret = succeeded = true; } catch (NamingException ne) { ret = succeeded = false; } return ret; }

Client Project (1) import java.util.HashSet; import efg.library.IF.BookDAO; import efg.library.IF.CustomerDAO; import efg.library.IF.LibraryManagerIF; import javax.naming.InitialContext; import org.jboss.security.client.SecurityClient; import org.jboss.security.client.SecurityClientFactory; public class Main { public static void main(String[] args) throws Exception { InitialContext ctx = new InitialContext(); LibraryManagerIF manager = (LibraryManagerIF)ctx.lookup("LibraryManager/remote"); System.out.println("librarymanager="+manager); SecurityClient securityClient = SecurityClientFactory.getSecurityClient(); securityClient.setSimple("henk", "geheim"); securityClient.login(); printBooks(manager); printCustomers(manager); manager.addCredits("Eric", 1); printCustomers(manager); securityClient.logout();

Client Project (2) securityClient.setSimple("john", "geheim"); securityClient.login(); printBooks(manager); manager.newBook("aapje"); printBooks(manager); printCustomers(manager); manager.newCustomer("aapje"); printCustomers(manager); manager.removeCustomer("aapje"); printCustomers(manager); securityClient.logout(); securityClient.setSimple("fred", "geheim"); securityClient.login(); printCustomers(manager); manager.lend("aapje", "Eric"); printCustomers(manager); securityClient.logout(); securityClient.setSimple("john", "geheim"); securityClient.login(); printBooks(manager); manager.removeBook("aapje"); printBooks(manager); securityClient.logout(); }

Client Project (3) private static void printBooks(LibraryManagerIF manager) { HashSet books = manager.allBooks(); for (BookDAO book : books) { System.out.println(book.getTitle()); } System.out.println(" "); } private static void printCustomers(LibraryManagerIF manager) { HashSet customers = manager.allCustomers(); for (CustomerDAO customer : customers) { System.out.print(customer.getName()+", "+customer.getCredits()); HashSet books = customer.getBooks(); for (String title : books) { System.out.print(", "+title); } System.out.println(); } System.out.println(" "); }

Do TESTING for first milestone. Deploy IF Deploy JAAS Deploy EJB do Client-test

JSF Project Inject a connector to EJB private LibraryManagerIF libraryManager = null;

JSF Project LibraryAccessBean public String doLogin() { boolean[] render = {... } session.setAttribute("render", render); try { SecurityClient securityClient = SecurityClientFactory.getSecurityClient(); securityClient.setSimple(usr, pwd); securityClient.login(); Principal principal = libraryManager.getPrincipal(); String name = principal.getName(); securityClient.logout(); boolean[] menu = null; if (name.equals("eric")) { menu =... } else if (name.equals("fred")) { menu =... } else if (name.equals("john")) { menu =... } else if (name.equals("henk")) { menu =... } session.setAttribute("menu", menu); } catch (Exception e) { setException(e.getMessage()); return "LibraryAccess"; } return "LibraryManager"; }

JSF Project LibraryManagerBean public void doNewBook(ActionEvent ae) { if (title.equals("")) { FacesContext ctx = FacesContext.getCurrentInstance(); ctx.addMessage( "subview-choice:subview-new-book:form-new-book:input-new-book“, new FacesMessage(" title is a required field")); return; } try { securityClient.setSimple(usr, pwd); securityClient.login(); setMessage(libraryManager.newBook(title)); title=""; securityClient.logout(); } catch (Exception e) { setException(e.getMessage()); }

Do TESTING for second milestone. Deploy JSF do Browser-test

More steps to do. 1.Use the Jboss database service