2000: Making IT Happen with J2EE

17
1 Making it Happen with J2EE Russell Castagnaro Chief Mentor 4Charity.com [email protected] Introduction z Presenter yRussell Castagnaro yChief Mentor x4Charity.com xSyncTank Solutions, Inc y[email protected] yExperience Introduction z 4Charity.com yApplication Service Provider for the Non- Profit industry yPure Java development yHttp://www.4charity.com yLocations: x San Francisco,CA x Honolulu, HI yWe’re Hiring…

description

This was a presentation I used to give all the time back in the early days of J2EE

Transcript of 2000: Making IT Happen with J2EE

Page 1: 2000: Making IT Happen with J2EE

1

Making it Happen with J2EE

Russell CastagnaroChief Mentor [email protected]

Introduction

zPresenteryRussell CastagnaroyChief Mentor ⌧4Charity.com ⌧SyncTank Solutions, Inc

y [email protected]

Introductionz4Charity.comyApplication Service Provider for the Non-

Profit industryyPure Java developmentyHttp://www.4charity.comyLocations:⌧ San Francisco,CA ⌧ Honolulu, HI

yWe’re Hiring…

Page 2: 2000: Making IT Happen with J2EE

2

Presentation Goals

zBrief overview of the J2EE APIzDiscuss various application architectureszExplain when each API should be usedzMost examples use BEA’s Weblogic Server

What is the J2EE?

zJava2 Enterprise EditionzA set of Eleven Application Programming

Interfaces (API) that provide a standard way to solve common issues.zDelivers on the promise of Standards-

based heterogeneous applications development.

The J2EE API’s

zDatabase Connectivity (JDBC)zRemote Method Protocol (RMP/ RMI)zNaming and Directory Interface (JNDI)zServlets and Server Pages (JSP)zMessaging (JMS)zTransaction Services (JTS/ JTA)

Page 3: 2000: Making IT Happen with J2EE

3

The J2EE API’s

zCORBA Communication (IIOP/ CORBA)zMail (Mail and JAF)zEnterprise Beans (EJB)zExtensible Markup Language (XML / XSL)

The J2EE API’s

Java Database Connectivity

zThe first of the J2EE API’s.zProvides a standard set of interfaces to

access any compliant data source.zImproved upon ODBC standard.zSQL 92 compliant.

Page 4: 2000: Making IT Happen with J2EE

4

Remote Method ProtocolRemote Method Interface

zCommunication protocol between Java objects on separate Virtual Machines (JVM).zEnables distributed communications with

no knowledge of networking or sockets.zMakes remote objects seem local.zUses Java Serialization to send objects

across a network.

Java Naming & Directory Interface

zSimple interface that allows for resource discovery and binding.zA way to ‘look up’ an object locally or

remotely.zA way to enter objects into a directory of

objects.zOther interfaces leverage JNDI (i.e.

LDAP).

Java Servlets

zJava access to network (HTTP) requests and responses.zIntegration with a Web Server via a

Servlet Engine.zImproved performance over CGI.z70% of successful Java projects are

Servlet-based!

Page 5: 2000: Making IT Happen with J2EE

5

Java Sever Pages

zBuilds on the Servlet API.zProvides a “pure” presentation-layer

templating mechanism.zAllows HTML coders to write HTML, not

the Java Programmers.

Java Messaging Service

zAsynchronous messaging between de-coupled components.zDefines the Message Oriented

Middleware interface for Java applications.zSupports:yGuaranteed Message DeliveryyPoint-to-point messagingyPublish/ Subscript messaging

Java Transaction Servicesz JTS uses the Java Transaction Architecture

(JTA) to monitor and access all transactions that take place in a given system.

z Implements the OMG Object Transaction Service (OTS) definition.

zDefines the interfaces between :yTransaction ManageryApplicationyApplication ServeryResource (Database Management System)

Page 6: 2000: Making IT Happen with J2EE

6

CORBA / IIOP

zInternet Inter-Orb Protocol is the standard protocol from accessing CORBA resources.zCORBA resources may be COBOL, C,

C++, etc.zRMI over IIOP is supported in Java 2!

Java Mail & Activation

zProvides non-networking specific access to internet mail services.zIncludes implementation that can access

SMTP, POP, and IMAP servers.zMime type support for various data-types

Enterprise Java BeanszCross platform Java-based component

architecturezProvides for portability across server

vendorszWell defined interfaces between client,

server component, server and resourceszHandles data persistence and transaction

integrity

Page 7: 2000: Making IT Happen with J2EE

7

Extensible Markup Languagez Self-describing, pure data representationz Compatible with heterogeneous systemszMethod of configuration of most systemsz Can be used within most of the core APIz Transformations via Extensible Stylesheet

Language Transformation (XSLT)

The J2EE

zYou may remain completely within the realm of J2EE and provide enterprise solutions.zOccasionally the Java Native Interface is

needed to access other systems.

J2EE Construction

zI will use a construction metaphor for using the J2EE

Page 8: 2000: Making IT Happen with J2EE

8

Enterprise Mortar: JDBC, JNDI and RMI

zJDBC Connects your databases to Java.yUse Connections, Statements, Result Sets,

etc..yCall Stored Procedures, etc..

zJNDI locates distributed components.zRMI allows distributed objects to

communicate as if they were local.

Enterprise Bricks: EJB, JMS, JTS

zEJB encapsulates business logic, insulates you from the persistence layer, provides fault tolerance and fail-overzJMS provides GMD in Queues or TopicszJTS allows you to control transaction

isolation level for better data management

Enterprise support beams:Servlets

zServletsyProvide the application structure.yDictate how to navigate inside the

application. yAre strong, but not pretty.

Page 9: 2000: Making IT Happen with J2EE

9

The Enterprise Exterior: JSP

zJSP’s are responsible for the user experiencezHides the internal structure from clientszAllows less experienced developers or

web content producers to focus on presentation

How do the new API’s Help?zInterfaces* that provide maximum

flexibility.zThey provide several contracts:yDeveloper - ComponentyContainer -ComponentyServer - Container

zYou can avoid deployment specifics in client code.

Companies Really Are Using J2EE

zCompanies that use Java:yMost use JDBC and ServletsyMany use JNDI/ RMI or IIOPyBigger players are using EJB, JMS and XML

zCompanies that do not use Java:yMany are using XML, COM, or CORBA

Page 10: 2000: Making IT Happen with J2EE

10

Common Acceptance Path

zUse Servlets (performance, speed of deployment, ease of development)zUse JDBC (robust, simple, easy to deploy)zUse RMI/JNDI (distributed applications)zUse JNI (integration with other software)zUse EJB and JMS (high availability,

performance, abstraction)

Now what?zYou already knew all of that…zMaybe:yYour CTO declared that all future

development should be EJB’s!yYour client decided to listen to some Gartner

Group/ Forrester/ Giga Group advice.yYou want to develop distributed, scalable

applications in Java.

Avoiding Success With J2EEzUse one API exclusively, ALL THE TIME.zUse EJB’s, particularly Entity Beans

excessively.zCreate ‘Monolithic’ Distributed

applications.zIgnore other reasonable advice.

Page 11: 2000: Making IT Happen with J2EE

11

Heavyweight JSP’s

JSP

RDBMS

JSP

JSP

JDBC

JDBC

JDBC

<jsp:scriptlet>id = null; SQLDataBean bean = new SQLDataBean();bean.setSQL(stmt); bean.setDriver(driver);bean.setURL(url); Properties p = new Properties();p.put("user",user); p.put("password",pass);p.put("url",bean.getURL()); bean.setProperties(p);bean.setColumns(columns); bean.setFields(columns);bean.setReturnClosed(false); java.sql.ResultSet rs = null;try {Object o = bean.execute(request); rs = (java.sql.ResultSet) o;

rs.next(); description = rs.getString(3);position = rs.getString(2); salary = rs.getString(4);

} catch (Exception e) { e.printStackTrace(new PrintWriter(out));} finally {

try { rs.close(); } catch (Exception er) { }}

</jsp:scriptlet>

CMP Entitillic

Servlet

RDBMS

JSP Application

JDBC- VIA CMP

EntityEntity Entity

EntityEntity

EntityEntityEntity Entity

Entity

Page 12: 2000: Making IT Happen with J2EE

12

Expensive Relaunchitis

Servlet

RDBMS

Servlet Servlet

JDBC

Session SessionJMS

Entity Entity XMLJMS

Entity

Latentcerocis

Java App

RDBMS

JButtonActionListener

Home

Entity

RMI

Reporting Overkill-us

RDBMS

JSPServlet

Home

Entity

Page 13: 2000: Making IT Happen with J2EE

13

Report Overkill-us

zDo not use Entity classes to access read-only data

z Compare the number of sql statementsySelect name,ssn,salary from empySelect name,ssn,salary from emp where id=1ySelect name,ssn,salary from emp where id=2ySelect name,ssn,salary from emp where id=3y…

z Consider the RMI communication time.z Contemplate the App Server overhead.

Some Successful StrategieszUse coarse-grained entities where possiblezUse Interfaces from the start of developmentzUse JSP to encapsulate the presentation layerzDo not put business logic in your JSP’szUse Bean Managed Persistence or OR Mapping

toolsz You still need code reviews!

Use coarse-grained Entities

zJDBC is your friend!zContainer Managed Persistence is not

always appropriate.zDo not let the Database structure dictate

your object architecture.

Page 14: 2000: Making IT Happen with J2EE

14

Use Remote Interfaces from the beginning

zDefine your interfaces very early in the construction phasezCreate stub implementationszThis allows the presentation layer

development to continue without waiting for the server side components

Use Interfaces with EJB

EJB Data Access

z There are many ways that you can access your data via EJByUsing a Session

⌧SQL in the Session or DD⌧Data Access Objects

yUsing an Entity⌧Container Managed Persistence⌧Bean Managed Persistence

• SQL embedded in the Entity or DD• Data Access Objects• O/R Mapping Tool

Page 15: 2000: Making IT Happen with J2EE

15

EJB Data Access

zUsing a Session with SQL EmbeddedyVery straightforwardyEasy to ConfigureySomewhat FlexibleyMay be difficult to maintainyHard to reuse

Session With SQL Embeddedpublic AddressData getBusinessAddress() throws RemoteException {

AddressData address = new AddressData();try {

Connection c = null; PreparedStatement s = null; ResultSet rs = null;try {

c = getConnection(); s = c.createStatement();String query = getEnvironmentValue("ADDRESS_SQL");s.prepareStatement(query); s.setString(id); rs = s.executeQuery();while (rs.next()){

address.setStreet(rs.getString("ADDRESS")); address.setCity(rs.getString("CITY")); address.setState(rs.getString("STATE")); address.setZip(rs.getString("ZIP")); address.setCountryCode(rs.getString(“COUNTRY_CD");

} //while} catch (SQLException e){ e.printStackTrace(); } finally {

if ( s != null ) s.close(); if ( rs != null ) rs.close();if ( c != null) c.close();

} //catch

} catch (SQLException e){}return address;

}

EJB Data Access

zUsing a Session with a Data Access ObjectyModularyReusableyDifficult to expand to complex relationshipsyTransactions, data-integrity must be

maintained manually

Page 16: 2000: Making IT Happen with J2EE

16

Session With DAO

public AddressData getBusinessAddress() throws RemoteException, BeanDNEException

{AddressDataBean address = new AddressDataBean(ein);

return address.getAddressData();

}

Other PointszThe same follows for EntitieszUse a Cookie Cutter Approach ySpecify your interfaces earlyyWrite a tool or use an IDE that will create the

skeleton code for youy Implement only what you need

zAssign a person to take on the role of deployment specialist (its not fun)

Using the J2EE

zUse the appropriate technologyzDon’t throw away all of the design

principles you have learnedzJust say no to ‘distributed monolithic’

applications

Page 17: 2000: Making IT Happen with J2EE

17

Finally

z Thanks for attendingz Live in Hawaii or Bay Area? Do you like this

stuff? Email your resume to us!z Source Code Availableyhttp://www.synctank.com/javacony [email protected]

z Check for EJBWiz to be released as open source soon

z Aloha