Enterprise Java Overview

namibiancurrishInternet and Web Development

Nov 12, 2013 (3 years and 8 months ago)

96 views

Enterprise Java Overview

Panos Konstantinidis

Java Developer

JUG Leader & Java Champion

http://thejavablog.wordpress.com



Java Enterprise Edition


Introduction to JEE


JEE architecture/technologies


JEE Application Servers


SOA


The next step


Spring Framework.

Enterprise Systems


Enterprise Systems


Large scale and complex systems


n number or tiers


Distributed


Thousands of users


Multithreading


Thousands or millions of requests per hour


Support for fail
-
over


Support for transactions


Support for security

Before JEE


Developer had to do everything


Care about multithreading


Care about transactions


Care about fail
-
over


Care about security


... on top of that care about the business logic

After JEE


Application Server/Container takes care of
application details


Multithreading


Security


Fail
-
over


etc.


Developer takes care of business logic

JEE Architecture



JEE architecture layers
(image taken from http://www.itindepth.com/)


Servlets


Servlets


Java objects that extend the functionality of a
web server


Run on the server


Require a servlet container to run in


Platform and server independent


They access all the Java APIs


Having HTML/XML/WML code within a Java
class is ugly, error
-
prone and hard to maintain

JSP


JSP


A simple and easy way to create dynamic web
content


HTML/XML/WML/etc with Java code (scriplets)
embedded into it


Runs on the server


Platform and server independent


Needs to be pre
-
compiled into a servlet

Servlets & JSP


They work together


JSP used for presentation


Servlets are used as controllers/implement
logic


By separating logic from presentation
(design) it is easier to maintain, scale and
build web applications

EJB


The cornerstone of a JEE application


Server side components


They enable fast and simplified
development of distributed, transactional,
secure and portable enterprise applications


They are deployed into a container

EJB (continued)



Three types of EJB (Session, Entity,
Message driven)



The container is responsible for


Loading and initialising


Transactions


Persistence (activation/passivation and db
persistence)



communication with clients via remote
interfaces


JNDI for finding EJB instances

Session Beans


Perform actions on behalf of a particular
client


Stateful


Maintains conversational state with the client


Stateless


Does not maintain state between client calls.
The container can substitute beans as
necessary between method calls.

Entity Beans



Map data to a database row


Provide abstraction layer so when working
with an entity the storage mechanism is not
specific.


Container Managed


The container persists the data to the db
automatically.


Beans Managed


Developer writes code that persists data to the
db and container calls these methods

Message Driven Beans


Receive asynchronous notifications from a
JMS server


for example send a purchase order to a JMS
queue


Client does not interact with them directly
but only through message queues

Java Messaging Service


Software that provides service for
messaging


Can be stand
-
alone or consolidated within
an application server


JMS Queue


Messages are sent into a queue and read from
the queue. One consumer only


JMS Topic


Publish/subscribe mode. Messages are
broadcast to all the consumers

JNDI


Java Naming and Directory Interface


It is used to store and retrieve objects by
name


Object have to register with a naming service
first


Can interact with existing naming services
like LDAP

JTA


The Java Transaction API allows
application servers to handle transactions


Developer declares the transaction
properties


The application server takes care of the
rest

Java Mail


The Java Mail API provides classes that
model a mail system


Supports many common protocols


IMAP


POP


SMTP


MIME

JAAS


Java Authentication and Autorisation Service


Authenticates users, makes sure users can log
into the system and execute Java code


Authorises users, makes sure users have the
right permissions to perform the actions required


Authentication modules include



Kerberos


Keystore


Windows NT

JDBC


Java Database Connectivity


Lets developers access database from
Java


Also provides access to other form of data
such as excel files


There are drivers for all the known
databases

J2EE Connectors


Connectors provide a way to connect J
2
EE
applications to heterogenous systems not
written in Java (Siebel, SAP, etc)



System vendor provides the right connector

Application Servers


Take care of application
-
related
functionality


Provide sophisticated means to handle
multithreading/transactions/security/etc


Handle the life
-
cycle of the installed
components


Usually cost thousands of pounds per CPU

Application Servers
(continued)



All of application servers provide their own
services (JMS, JNDI, servlet containers,
etc)



Some application servers


WebLogic


WebSphere


Oracle


JBoss (free and open source, but you pay for
support)



Glassfish (same)


Deployment


You deploy the application onto the
application server in a form of EAR
(Enterprise ARchive) file


EAR is nothing more than a zipped file that
contains all relevant files needed.


It is expanded on deployment

Console


Application servers usually provide a
console where the administrator or
developer can manage the application


Deploy/undeploy applications


Define JDBC resource


Define users and roles


etc

Web Services


Services residing somewhere on the web


Web services enable application to
application interaction via the web


Built on existing standards (SOAP over
HTTP)



Web services are focused on messages not
APIs (we don't care what created the
message)


Web Services (continued)



Interoperability between disparate systems


You can access a .NET web service from a
Java client (the opposite is also true), etc


Enable Service Oriented Architecture
(SOA)



Traditional approach is based on objects, we
discover and use objects


With SOA we discover and use services

Web Services protocol


Simple Object Access Protocol (SOAP)



Transmission over existing HTTP protocol


In essence we send HTTP requests with the
whole SOAP message in the body of the
POST


XML based

WSDL


Web Services Description Language


Describes a web service


Describes methods and parameter types


Describes return types


How to access it (what port it's running on,
where it's running on)



XML based


Complicated, use tools to generate the
WSDL

UDDI


Universal Description, Discovery and
Integration


It's a registry of services


Publishes information about a web service
(similar to yellow pages)



Publishes the access point of a web service

Spring


Aims behind Spring


Enterprise Java should be easier.


Interfaces are better than classes.


JavaBeans better than EJBs.


Testability is important and should be easier.

Spring (continued)



Small size (around
6
MB).


One core jar file (and a few more
dependencies).


Spring manages life
-
cycle and configuration
of application objects.


Dependency Injection


Objects are given their dependencies instead
of creating/looking for them.


Spring gives dependencies upon instatiation.

Spring (continued)



Application data are configured through an
XML configuration file.


Can be complicated and hard to maintain if
there are too many beans configured.


Like JEE, developer is only concerned
about business logic, Spring takes care of
application related functionality.

Spring Modules


Spring contains several modules, each one
can be used on its own.


Core and Context modules, the heart of the
Spring framework. Provide fundamental
functionality.


AOP module.


JDBC module.


ORM Module (hooks for other ORM
implementations).


Web Module.

Spring Core Modules


Initialise all the application objects
(JavaBeans) by reading the XML
configuration file.


Supply enterprise services such as JNDI,
multithreading, remote calls etc.


Provide support with integration with other
frameworks (FreeMarker, iBatis etc).

Spring & AOP


Aspect


a general feature we want to
apply globally to our application (e.g.
logging or exception handling).


Aspects are declared through the XML
configuration file.


Container executes the aspect after, before
or around a method call.


Around can change the method behaviour.

Spring & JDBC


Provides functionality for JDBC.


Database information (url, port etc) is
configured via the XML configuration file.


Handles the creation of connections, result
sets, statements, pools etc.


Closes the connection and returns it to the
pool of available connections.

Spring & Transactions


Declare transactions in the configuration
file/class meta data by using annotations.


Can declare roll back behaviour per method
or exception type.


You can't do that with EJBs, only
programmatically.


No native support for distributed
transactions. Only through JTA.


EJBs support distributed transactions by
default.

Spring & Persistence


Doesn't support out of the box ORM
solutions.


We need to integrate with existing
technologies (Hibernate, TopLink etc). Spring
provides the right plumbing to do so.


Alternatively use plain JDBC.

Spring & Web applications


Provides its own web framework (Spring
MVC).


Typical MVC pattern with a central servlet
acting as controller.


Spring supports several web
-
oriented tasks
(multipart file uploading, session handling
etc).


Can be integrated with other web
frameworks like Struts, Tapestry, JSF.

Spring & Distributed
computing


Remote calls to Spring ca be done via


RMI (same as EJBs)



JAX/RPC (for Web Services)


Spring & Security


Spring Security (formerly Acegi security)



Supports declarative security via XML
configuration or class meta data annotations
for security (EJBs also support declarative
security via roles and users).

Spring & Deployment


Platform independent.


A Spring application should run the same
on any other machine that supports Spring.


Migration should be easy (just copy & paste
the application data & the XML
configuration file).


Same with EJBs, although a bit tricky.

Learning more


Enterprise Java
-

http://java.sun.com/javaee/


JEE compatible servers
-

http://java.sun.com/products/servlet/industry.html


JEE tutorial
-

http://java.sun.com/javaee/
5
/docs/tutorial/doc/


JDBC tutorial
-

http://java.sun.com/docs/books/tutorial/jdbc/basics/


JNDI
-

http://java.sun.com/products/jndi/tutorial/


Servlets tutorial
-

http://java.sun.com/j
2
ee/tutorial/
1
_
3
-
fcs/doc/Servlets.html


JMS
-

http://java.sun.com/products/jms/


Spring Framework
-

http://www.springframework.org/


Spring projects
-

http://www.springsource.org/projects


WebLogic Server
-

http://www.bea.com


WebSphere server
-

http://www.ibm.com/software/info/websphere/r


JBoss Server
-

http://www.jboss.org/


Glassfish Server
-

https://glassfish.dev.java.net/

Questions?