Rapid Prototyping using Open Source J2EE technology by usr10478

VIEWS: 16 PAGES: 23

									Rapid Prototyping using Open
  Source J2EE technology
    - the whys, wherefores and gotchas
            Brian Fowler
              Logica UK Ltd
            6th June 2001



    OOPS-152 British Computer Society
          fowlerb@logica.com

                                         Begin
                                                            Page 1

Where are we going?
During the talk I hope to talk about...

   J2EE in a web/wap context;

   The mCards demo;

   Rapid Prototyping with J2EE;

   Development Environments;

   Summary;

   Where to find out more.




      Previous Page Go Back Go Forward Next Page Overview Quit
                                                                         Page 2

J2EE 101
What is J2EE?
J2EE is the Java 2 Enterprise Edition. The J2EE specification

   Extends the standard edition;

   Provides a framework to develop scalable distributed applications;

   Practical implementations are mainly supplied by 3rd Parties. N.B. Applica-
    tion servers come with Java libraries implementing the J2EE Specification.
    You don’t need to download the Sun J2EE JDK.




     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                                                                       Page 3

Overview of Web Architecture
                                    J2EE Application Server



                                            Servlet Container                               EJB Container


                                               Servlet
                                                                                                    EJB

                     HTTP Request                                                  Remote
                                                                                   Call


                                                   JSP


                                                                     Custom Tags

                           HTTP Response




                                           State
                                                                                                               JDBC
                                                                JavaBean




                                                                                                            Database




    Previous Page Go Back Go Forward Next Page Overview Quit
                                                                      Page 4

The Servlet Container
The servlet container manages objects that are used to process HTTP requests.
These objects include

   Servlets;

   Java Server Pages (JSPs);

   Custom JSP Tags.

HTTP is a stateless protocol. The Servlet Container maintains user sessions by
generating and propagating a session id. This is done by either

   Setting a cookie in the response;

   URL rewriting.

Session management is largely transparent to the programmer. However URL
rewriting must be implemented explicitly. Usually using a JSP Custom Tag.

     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                          Page 5

Java Servlets
Java Servlets are Java Classes that extend HttpServlet.

Java Servlets are good for

   Processing an incoming HTTP request;

   Calling classes that implement business logic and dealing with the results;

   Setting request and session variables;

   Forwarding the request to a JSP to construct the content to return.

Java Servlets are bad for

   # Generating HTML, WML etc. etc;

   # Implementing business logic.


     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                      Page 6

JSP - Java Server Pages
JSPs are text files that are used to generate content. They are compiled to
Servlet classes by the servlet container. They can present dynamic information
using Custom JSP Tags and/or embedded Java code.

JSPs are good for
   Serving dynamic content.

JSPs are very bad for
   # Processing user form data in an HTTP request;
   # Implementing business logic or calling classes that implement business
     logic.

JSPs are not Java Source files! Ideally they should contain no Java code (per-
sonal view, JSPs should be maintainable my non-Java programmers) In particu-
lar, if you have more Java than HTML in your page, something is wrong!

     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                        Page 7

Custom JSP Tags
Custom JSP Tags allow extra HTML like tags to be defined to aid the generation of
content. They are implemented using Java Classes that extend Tag, TagSupport,
BodyTag or BodyTagSupport.

Custom JSP Tags are good for

   Presentation logic e.g. looping through Iterators;

   URL Rewriting;

   Eliminating Java code from JSPs.

Custom JSP Tags are bad for

   # Implementing or calling classes that implement business logic.




     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                                                     Page 8
J2EE Application Server
  But how do they fit together?
         Servlet Container                                EJB Container


            Servlet                                    E.g. A user submits a login and password
                                                               EJB
                                                       from a form, with incorrect password.
                                                Remote
                                                Call     Ì The servlet processes the request;

                JSP
                                                         Ì The servlet calls login business logic;
                                                         Ì The servlet places a JavaBean in the
                                  Custom Tags
                                                           request containing information about
ponse                                                      the failure;
                                                         Ì The servlet forwards the request to the
        State
                                                           login form JSP;
                                                                          JDBC
                             JavaBean                    Ì The JSP accesses the JavaBean via
                                                           JSP and Custom Tags and constructs
                                                           the appropriate login form page.




                Previous Page Go Back Go Forward Next Page Overview Quit
                                                                          Page 9

Enterprise JavaBean Container
The EJB Container manages EJBs. It can take responsibility for

   Persistence;

   Transactions;

   Caching;

   Pooling;

   Security.

This is very useful especially at the prototyping stage, as it frees the developer
from worrying about and explicitly coding these services.




      Previous Page Go Back Go Forward Next Page Overview Quit
                                                                      Page 10

But what are Enterprise JavaBeans?
Enterprise JavaBeans (1.1) are a collection of Java classes and (a) XML de-
scriptor(s) that implement and extend standard classes to implement distributed
business logic components.
There are two types of EJBs

   Session Beans;

   Entity Beans.

NB: Enterprise JavaBeans are not JavaBeans!




     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                        Page 11

Session Beans
Session Beans represent actions not specific to one data entity.
Session Beans come in two types

   Stateless;

   Stateful.

To write a Session Bean the programmer has to

   Implement the Bean by providing a class which implements SessionBean;

   Implement the Remote Interface by extending EJBObject;

   Implement the Home Interface by extending EJBHome.

Whether the Bean is stateful or stateless is declared in the XML descriptor.




      Previous Page Go Back Go Forward Next Page Overview Quit
                                                                          Page 12

Entity Beans
Entity beans are objects that represent data persisted on the database.
Entity beans can be

   Container Managed;

   Bean Managed.

To write an Entity Bean the programmer has to

   Implement the Bean by providing a class which implements EntityBean;

   Implement the Remote Interface by extending EJBObject;

   Implement the Home Interface by extending EJBHome.

The data mapping and management configuration is in XML descriptors.




     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                  Page 13

mCards
mCards is a simple (primarily) WAP application for sending mCards. It uses
Servlets, JSPs, Custom Tag Libraries and EJBs. It is deployed on JBoss and
Tomcat. It is a distributed application.




                      Most of the application is running on a linux box
                      in London. But when a greeting is sent, an Entity
                      Bean called sentGreeting is created on a computer
                      in Nantes, France.




 When a SMS message is sent, this happens using
 a computer in Terrible House, Everdead.

     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                        Page 14

Rapid Prototyping with J2EE
The Whys
“This all seems very complicated, its only a prototype why not just use CGI Perl?”

   The J2EE architecture is neat, logical, scalable and reusable;

   Development may be slower the first time but not in future;

   With J2EE database mapping is automated, don’t have to worry about the
    detail now but can revise later;

   Component nature of architecture makes team development natural.




      Previous Page Go Back Go Forward Next Page Overview Quit
                                                                    Page 15

Rapid Prototyping with J2EE
The Wherefores
“How do I get started?”

   Download the Sun JDK 1.3 from http://www.javasoft.com/;

   Download the JBoss and Tomcat bundle from http://www.jboss.org/. JBoss
    is a cutting edge application server, which from personal experience is a
    great deal easier to work with than BEA WebLogic. Tomcat is now the
    reference JSP/Servlet implementation.

   JBoss includes the Hypersonic Database. However JBoss is very config-
    urable, it was fairly straightforward to configure for PostgreSQL or other
    databases with JDBC drivers.




     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                           Page 16

Rapid Prototyping with J2EE
Designing: A How
  Have a single entry servlet, which takes all requests;
  Design the servlet to validate the request and call the appropriate Session Bean
   to implement the business logic. Analyse the result and forward to an appropriate
   JSP to serve the response;
  Design, beg, borrow or steal JSP Custom Tag libraries;
  Do you have a page flow? Consolidate into a JSP presentation design;
  Design your JSPs to only read and display data from the request/session. Minimise
   Java code making it hard for your web page designer to break your code!
  Assume the Session Bean is ignorant of the front end. In particular it should not
   be dealing with HttpRequest or HttpReponse objects;
  Use container managed Entity Beans to model your data;
  Think reuse all the time, make your EJBs and Tag Libraries as generic as possible.


    Previous Page Go Back Go Forward Next Page Overview Quit
                                                                       Page 17

Rapid Prototyping with J2EE
The Gotchas
“You make this all sound great! Especially at this election time, I’m a cynic now
tell it as it is!”

   There is a terrible temptation to start by writing JSPs. Don’t!

   Design Entity Beans carefully, every time a member variable changes it will
    be written to the database. So don’t use lots of setters;

   The Servlet specification is now fairly stable, write once deploy anywhere is
    pretty much true. However the EJB Specification is not, expect lots of work
    in moving application servers and things are going to change in EJB 2.0;

   Beware classpaths!




      Previous Page Go Back Go Forward Next Page Overview Quit
                                                                      Page 18

Rapid Prototyping with J2EE
Development Environments
Under Linux I like

   xemacs as an editor;

   CVS for version control;

   Apache Ant as a “make” facility.

Under Windows 98/Me/2000 try

   Sun Forte Community edition as an IDE but still write an Ant build file;

   Tortoise CVS as an interface to a remote CVS repository.

Forte is integrated with Tomcat and has good JSP debugging facilities that many
of the free versions of IDEs don’t have.


      Previous Page Go Back Go Forward Next Page Overview Quit
                                                         Page 19

Apache Ant

  Apache Ant is a platform independent make facility;

  Uses an XML build file;

  Available from http://jakarta.apache.org/.




    Previous Page Go Back Go Forward Next Page Overview Quit
                                                              Page 20

Things to take away
I hope I have given you

   An overview of J2EE web architecture;

   Some reasons to use it;

   An example design approach;

   Some Open Source products to use and where to find them.




     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                    Page 21

Where can I find out more?
Recommended sources:

   Java Server Programming J2EE Edition (Wrox);

   The Server Side http://www.serverside.com/;

   Enterprise JavaBeans 2nd Edition by Richard Monson-Haefel (O’Reilly);

   Sun Website http://www.javasoft.com/.

What I have talked about today is only a small part of J2EE and of what JBoss
can do.




     Previous Page Go Back Go Forward Next Page Overview Quit
                                                                        Page 22

Credits
Thanks to

   Immo for his support;

   Frantz Epineuse of Logica France for the use of their facilities;

   Charles Wicksteed and Alistair Caunt for their advice;

   Dave Du Vergier, Matt Pennington, James Douglas and Rich Millward for
    various J2EE architecture discussions;

   Alice Kerman and Chris Hobdey for acting as guinea pigs for my JSP/Servlet
    explanations!
                                     A
I typeset this presentation using PDFLTEX by Han The Thanh, Petr Sojka and Jiri
Zlatuska.
Finally, please remember to vote tomorrow!


     Previous Page Go Back Go Forward Next Page Overview Quit

								
To top