64
Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the JavaEE 5 Platform Page 1 © Copyright 2006, Sun Microsystems, Inc. Building Applications with the JavaEE 5 Platform Roberto Chinnici Senior Staff Engineer Sun Microsystems, Inc.

Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 1

© Copyright 2006, Sun Microsystems, Inc.

Building Applications with the

Java™ EE 5 Platform

Roberto ChinniciSenior Staff EngineerSun Microsystems, Inc.

Page 2: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 2

© Copyright 2006, Sun Microsystems, Inc.

Agenda

Introduction to the JavaTM EE 5 platform

The role of tools

The big four: components, persistence, web services, web tier

Ongoing innovation

Demos

Page 3: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 3

© Copyright 2006, Sun Microsystems, Inc.

JavaTM EE 5 Goal

Make it easier to develop

JavaTM EE applications

Especially when getting started

with JavaTM EE

Page 4: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 4

© Copyright 2006, Sun Microsystems, Inc.

How Did We Make It Easier?

Declarative programming

Originally - deployment descriptors

Now - JavaTM language annotations

Remove requirements

Plain Old JavaTM Objects (POJOs)

More and better defaults

More powerful frameworks

Less work for you to do

Easier to learn and more productive!

Page 5: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 5

© Copyright 2006, Sun Microsystems, Inc.

Annotations in JavaTM

EE 5

Made extensive use of annotations

For defining and using web services

To map JavaTM classes to XML

To greatly simplify EJB development

To map JavaTM classes to databases

To specify external dependencies

To reduce need for deployment descriptors

Just starting to scratch the surface of what's possible

Page 6: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 6

© Copyright 2006, Sun Microsystems, Inc.

J2EETM 1.4 Web Service

<?xml version='1.0' encoding='UTF-8' ?><webservices xmlns='http://java.sun.com/xml/ns/j2ee' version='1.1'> <webservice-description> <webservice-description-name> HelloService</webservice-description-name> <wsdl-file> WEB-INF/wsdl/HelloService.wsdl</wsdl-file> <jaxrpc-mapping-file> WEB-INF/HelloService-mapping.xml </jaxrpc-mapping-file> <port-component xmlns:wsdl-port_ns='urn:HelloService/wsdl'> <port-component-name>HelloService</port-component-name> <wsdl-port>wsdl-port_ns:HelloServiceSEIPort</wsdl-port> <service-endpoint-interface> endpoint.HelloServiceSEI</service-endpoint-interface> <service-impl-bean> <servlet-link>WSServlet_HelloService</servlet-link> </service-impl-bean> </port-component> </webservice-description></webservices>

<?xml version='1.0' encoding='UTF-8' ?><configuration xmlns='http://java.sun.com/xml/ns/jax-rpc/ri/config'> <service name='HelloService' targetNamespace='urn:HelloService/wsdl' typeNamespace='urn:HelloService/types' packageName='endpoint'> <interface name='endpoint.HelloServiceSEI' servantName='endpoint.HelloServiceImpl'> </interface> </service></configuration>

package endpoint;

import java.rmi.*;

public class HelloServiceImpl

implements HelloServiceSEI {

public String sayHello(String param)

throws java.rmi.RemoteException {

return “Hello “ + param;

}

}

package endpoint;

import java.rmi.*;

public interface HelloServiceSEI

extends java.rmi.Remote {

public String sayHello(String param)

throws java.rmi.RemoteException;

}

Page 7: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 7

© Copyright 2006, Sun Microsystems, Inc.

JavaTM EE 5 Web Service

package endpoint;

import javax.jws.WebService;

@WebService

public class Hello {

public String sayHello(String param) {

return “Hello “ + param;

}

}

Page 8: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 8

© Copyright 2006, Sun Microsystems, Inc.

JavaTM EE 5 Major Features

Simplified web services support

More web service standards support

Dependency injection

Greatly simplified EJBTM development

New JavaTM

Persistence API

Easy web applications with JavaServerTM

Faces

And fully compatible with J2EE 1.4

Page 9: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 9

© Copyright 2006, Sun Microsystems, Inc.

How Much Easier Is It?

Adventure Builder1

J2EE 1.4 – 67 classes, 3284 lines of code

Java EE 5 – 43 classes, 2777 lines of code

36% fewer classes to manage!

RosterApp2

J2EE 1.4 – 17 classes, 987 lines of code

Java EE 5 – 7 classes, 716 lines of code

J2EE 1.4 XML files – 9 files, 792 lines

Java EE 5 XML files – 1 file, 5 lines

58% fewer classes, 89% fewer XML files to manage![1] Source: Debu Panda, Oracle

[2] Source: Raghu Kodali, Oracle

Page 10: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 10

© Copyright 2006, Sun Microsystems, Inc.

JavaTM EE 5 Platform Vendors

Page 11: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 11

© Copyright 2006, Sun Microsystems, Inc.

Project GlassFish

Open Source of Java EE 5 code base

Production quality: All of Sun Java System Application Server 9.0 PE

Included in Java EE 5 SDK

Community at Java.Net—for real

CVS, bug DBs, discussions at Java.Net

OSI licenses

Mostly CDDL, some ASL

Page 12: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 12

© Copyright 2006, Sun Microsystems, Inc.

Big Picture

Project

GlassFishSun Java System

AS 9.0

Derby

Open ESB

Portal Server

MQ

Distributions

Maven Repo

Java EE 5 SDK

Java EE RI

Communities

NetBeans™

IDE

NetBeans Enterprise Pack 5.5Tools

Eclipse Plugin

Users and Other Groups

Other DistributionsSun or Not!

Using All or Pieces

Page 13: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 13

© Copyright 2006, Sun Microsystems, Inc.

Smart Developers Use IDEs

Vast productivity gains

Core language support

code completion, refactorings, online documentation, debugging, profiling

Integrated unit testing

Plugins for disparate technologies

best-of-breed techs rapidly integrated

Logical view of a project

Page 14: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 14

© Copyright 2006, Sun Microsystems, Inc.

JavaTM EE 5 IDE Vendors

Page 15: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 15

© Copyright 2006, Sun Microsystems, Inc.

NetBeansTM

IDE

Fast, Comprehensive IDE and Platform

Plugin Ecosystem and Easy updates

Bundled Sun JavaTM

System Application Server 9

Plugins for other application servers

Comprehensive JavaTM

EE 5 support

UML tools, BPEL tools, Matisse GUI builder,

Mobility pack, ...

Page 16: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 16

© Copyright 2006, Sun Microsystems, Inc.

Major Platform Components

Business Logic: EJB 3.0

Persistence: JavaTM

Persistence API

Web services: JAX-WS 2.0

XML data binding: JAXB 2.0

Web applications: JSF 1.2

What about the future?

Page 17: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 17

© Copyright 2006, Sun Microsystems, Inc.

Innovation Happens Here

Project Tango: full WS-* stack

Web Beans (SEAM): conversational

applications

DynaFaces: effortless AJAX

Scripting (see other talk)

JBI: Enterprise service bus

All build on the platform's strengths

Page 18: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 18

© Copyright 2006, Sun Microsystems, Inc.

EJB 3.0

Simplified component model

session beans, message-driven beans

Separate JavaTM

persistence API

Inversion of contractual view

contracts benefit developers, not containers

Full compatibility with EJB 2.1

orderly evolution of clients and servers

Page 19: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 19

© Copyright 2006, Sun Microsystems, Inc.

New Component Contract

Components are plain JavaTM

classes

Interfaces are plain JavaTM

interfaces

Requirements are via metadata

annotations like @Stateless, @Remote

No container interfaces in sight

Deployment descriptors not required

Resource injection

Page 20: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 20

© Copyright 2006, Sun Microsystems, Inc.

Example

// EJB 2.1 Stateless Session Bean: Bean Class

public class PayrollBean implements javax.ejb.SessionBean {

SessionContext ctx;public void setSessionContext(SessionContext ctx) { this.ctx = ctx;}public void ejbCreate() {...}public void ejbActivate() {}public void ejbPassivate() {}public void ejbRemove() {}

public void setTaxDeductions(int empId, int deductions) {...

}}

Page 21: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 21

© Copyright 2006, Sun Microsystems, Inc.

Example

// EJB 3.0 Stateless Session Bean: Bean Class

@Stateless public class PayrollBean implements Payroll {

public void setTaxDeductions(int empId,int deductions) {...

}}

Page 22: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 22

© Copyright 2006, Sun Microsystems, Inc.

Example

// EJB 2.1 Stateless Session Bean: Interfaces

public interface PayrollHomeextends javax.ejb.EJBLocalHome {

public Payroll create() throws CreateException;

}

public interface Payroll

extends javax.ejb.EJBLocalObject {

public void setTaxDeductions(int empId, int deductions);

}

Page 23: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 23

© Copyright 2006, Sun Microsystems, Inc.

Example

// EJB 3.0 Stateless Session Bean: Business Interface

public interface Payroll {

public void setTaxDeductions(int empId, int deductions);

}

Page 24: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 24

© Copyright 2006, Sun Microsystems, Inc.

Example

// EJB 3.0 Stateless Session Bean: // Alternative: Remote Interface specified on bean class

@Stateless @Remote public class PayrollBean implements Payroll {

public void setTaxDeductions(int empId,int deductions) {...

}

}

Page 25: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 25

© Copyright 2006, Sun Microsystems, Inc.

Example

// EJB 3.0 Message-driven bean: Bean Class

@MessageDriven public class PayrollMDB implements javax.jms.MessageListener {

public void onMessage(Message msg) {

...}

}

Page 26: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 26

© Copyright 2006, Sun Microsystems, Inc.

By dependency injection or simple lookup

Use of JNDI interfaces no longer needed

Specify dependencies by annotations or XML

Annotations applied to:

Instance variable or setter property => injection

Bean class => dynamic lookup

Environment Access

Page 27: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 27

© Copyright 2006, Sun Microsystems, Inc.

Example

@Statelesspublic class MyBean {

@Resource SessionContext context;@Resource int timeout;

String uniqueKey;

@Resource

public void setUniqueKey(String s) { uniqueKey = s;}

// ... rest of the code goes here ...

}

Page 28: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 28

© Copyright 2006, Sun Microsystems, Inc.

Bean instance is supplied with references

to resources in environment

Occurs when instance of bean class is created

No assumptions as to order of injection

Optional @PostConstruct method is called when

injection is complete

Dependency Injection

Page 29: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 29

© Copyright 2006, Sun Microsystems, Inc.

@Resource

for connection factories, simple environment entries,

topics/queues, EJBContext, UserTransaction, etc.

@EJB

For EJB business interfaces or EJB Home interfaces

@PersistenceContext, @PersistenceUnit

For container-managed EntityManager / Factory

@WebServiceRef

For web service references

Available Annotations

Page 30: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 30

© Copyright 2006, Sun Microsystems, Inc.

Example

// EJB 3.0 Stateless Session Bean: Bean Class// Data access using injection and Java Persistence API

@Stateless public class PayrollBean implements Payroll {

@PersistenceContext EntityManager payrollMgr;

public void setTaxDeductions(int empId,int deductions) { payrollMgr.find(Employee.class, empId)

.setTaxDeductions(deductions);}

}

Page 31: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 31

© Copyright 2006, Sun Microsystems, Inc.

Other Uses of Annotations

Method permissions

@RolesAllowed @PermitAll @DenyAll

Transaction attributes

@TransactionAttribute(REQUIRED)

Event notifications

@PostConstruct @PreDestroy

Application exceptions

@ApplicationException(rollback=true)

Page 32: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 32

© Copyright 2006, Sun Microsystems, Inc.

Examples

@RolesAllowed({HR_Manager, HR_Admin})public int getSalary(int empId) {...}

@TransactionAttribute(REQUIRED)public int getTaxDeductions(int empId) {...}

@PostConstruct@PostActivateprivate void connectToBookingSystem() {...}

@ApplicationException(rollback=true)public class ReservationFailed extends RuntimeException {...}

Page 33: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 33

© Copyright 2006, Sun Microsystems, Inc.

Annotations Work Because...

They sit next to the program element they affect

Name a concept directly

Thus making it first class to developers

Morale: even with powerful IDEs, source

code is still seen as the truth

Push to remove even more boilerplate going forward

Page 34: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 34

© Copyright 2006, Sun Microsystems, Inc.

Extend built-in interposition model

Container interposes on all business method

invocations

Interceptors interpose after container

Around methods or lifecycle events

Can control program flow

Benefits: extensibility, separation of concerns

Interceptors

Page 35: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 35

© Copyright 2006, Sun Microsystems, Inc.

Example

@Stateless@Interceptors(Profiler.class)

@Stateless public class PayrollBean implements Payroll {

public void setTaxDeductions(int empId,int deductions)

{

...

}

}

Page 36: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 36

© Copyright 2006, Sun Microsystems, Inc.

Example

public class Profiler { @AroundInvoke public Object profile(InvocationContext invocation) throws Exception { long started = System.currentTimeMillis(); try { return invocation.proceed(); } finally { long elapsed = started – System.currentTimeMillis(); Method method = invocation.getMethod(); logger.logProfiledCall(method.toString(), elapsed); } }

private logger = ...; }

Page 37: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 37

© Copyright 2006, Sun Microsystems, Inc.

JavaTM

Persistence

Entities are plain JavaTM

objects, serializable

and usable as detached objects

Rich modeling capabilities

inheritance, polymorphism

Not tied to EE or EJB

Usable in the web tier

Usable on the JavaTM

SE platform

Page 38: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 38

© Copyright 2006, Sun Microsystems, Inc.

Example

@Entity public class Customer {

@Id private Long id;

private String name;

@OneToMany Set<Order> orders = new HashSet();

public Set<Order> getOrders() { return orders; }

public void addOrder(Order order) {getOrders().add(order);

}

}

Page 39: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 39

© Copyright 2006, Sun Microsystems, Inc.

Persistence Basics

Entity manager used to:

entity lifecycle operations (persist, merge)

find

create query objects

manage transactions

Injectable persistence context:

@PersistenceContext EntityManager em;

Page 40: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 40

© Copyright 2006, Sun Microsystems, Inc.

Persistence Gotcha

EntityManager not threadsafe

Certain components (e.g. servlet) are

multithreaded

If you mix the two, results are unpredictable

Workaround

inject an EntityManagerFactory instead

@PersistenceUnit EntityManagerFactory emf;

Page 41: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 41

© Copyright 2006, Sun Microsystems, Inc.

ORM and NetbeansTM

Generate entity classes from existing database structures

Generate database tables form handwritten

Entity classes

Use Entity Wizards for creating Entities and Persistence units

In short, all tedious, error-prone work is gone

Works with EE and SE applications

Page 42: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 42

© Copyright 2006, Sun Microsystems, Inc.

Web Services and XML

JAX-WS 2.0, JAXB 2.0, StAX, JSR-109 1.2

New web services and XML stack

Fast, streaming-based processing

Support 100% XML Schema

Highly extensible

Open set of protocols, transports, encodings

Page 43: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 43

© Copyright 2006, Sun Microsystems, Inc.

JAX-WS 2.0

New, easy to use web services API

Embrace plain old JavaTM

objects concept

Descriptor-free programming

Layered architecture

Protocol and transport independence

Integrated data binding via JAXB 2.0

Page 44: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 44

© Copyright 2006, Sun Microsystems, Inc.

Example

@WebService

@Stateless

public class Calculator {

@Resource

WebServiceContext context;

public int add(int a, int b) {

return a+b;

}

}

Page 45: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 45

© Copyright 2006, Sun Microsystems, Inc.

Layered Architecture

Calls Into

Implemented on Top of

Messaging Layer:

Dispatch/Provider

Application Code

Strongly-Typed Layer:

Annotated Classes

Page 46: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 46

© Copyright 2006, Sun Microsystems, Inc.

What Does It Mean?

Upper layer uses annotations extensively

Easy to use, great for tools

Fewer generated classes

Lower layer is more traditional

API-based, for advanced scenarios

Most application will use the upper layer only

Either way, portability is guaranteed

Page 47: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 47

© Copyright 2006, Sun Microsystems, Inc.

Interoperability

Standards-compliant

W3C/WS-I SOAP 1.1/1.2, WSDL 1.1, BP 1.0/1.1

Foundation for full WS-* web services stack

Project Tango

Fast Infoset

Support for more WS-* technologies over time

WS-Addressing in JAX-WS 2.1

Page 48: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 48

© Copyright 2006, Sun Microsystems, Inc.

Example - Client

@Stateless

public class MyBean {

@WebServiceRef(CalculatorService.class)

Calculator calculator;

public int mymethod() {

return calculator.add(35, 7);

}

Page 49: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 49

© Copyright 2006, Sun Microsystems, Inc.

Message Handlers

Similar to interceptors, but closer to the wire

Protocol handlers:

see the protocol message (e.g. SOAP)

Logical handlers:

see a logical message (XML payload)

Possible to pass data from handlers to interceptors using the message context

Page 50: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 50

© Copyright 2006, Sun Microsystems, Inc.

RESTful Web Services

Use messaging API in JAX-WS 2.0

Dispatch (client)

Provider (server)

HTTPBinding defined for this purpose

Payloads can be XML or not:

javax.transform.Source

JAXB objects

javax.activation.DataSource

Page 51: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 51

© Copyright 2006, Sun Microsystems, Inc.

Example

Service s = ...;

URI address = new URI("http://...”);

s.addPort(portName, HTTPBinding.HTTP_BINDING,address.toString());

Dispatch<Source> d = s.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);

Map<String, Object> requestContext = d.getRequestContext();

requestContext.put(MessageContext.HTTP_REQUEST_METHOD,new String("GET"));

Source result = d.invoke(null);

Page 52: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 52

© Copyright 2006, Sun Microsystems, Inc.

WSIT (Project Tango)

Full, interoperable WS-* stack

WS-Addressing, WS-ReliableMessaging

WS-MetadataExchange, WS-Policy, WS-SecurityPolicy

WS-Security, WS-SecureConversation, WS-Trust

WS-AtomicTransaction, WS-Coordination

Configured via descriptors

NetBeansTM

plugin to automate configuration

Page 53: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 53

© Copyright 2006, Sun Microsystems, Inc.

JavaTM Business Integration

Messaging infrastructure for composite application

Service contracts are WSDL-based

Supports JavaTM

EE web services

Other service technologies can be integrated

BPEL, Xquery, XSLT, Rule engines, ...

BPEL engine for service orchestration

Page 54: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 54

© Copyright 2006, Sun Microsystems, Inc.

JBI Overview

XQuery

JavaEEProcessRules

Xform Soap Route MOM

WSDL/Soap

WSDL/Soap

BPELBPEL

EJB

XQuery

Rule

RoutingTable

XSLT

Deploy

Install

NMR

JBI

Composite Service

Page 55: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 55

© Copyright 2006, Sun Microsystems, Inc.

Web Services and NetbeansTM

Web services client and server wizards

XML Schema and WSDL aware editor

Two-way roundtrip process designer

Deployment to JBI-enabled BPEL engine

Full process debugging

Liberty-based identity management

WSIT plugin

UML tools

Page 56: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 56

© Copyright 2006, Sun Microsystems, Inc.

JavaServerTM

Faces 1.2

The Java EE Standard Web Application

Framework

Dependency injection in managed beans

Easy to use, powerful, extensible Expression

Language, shared with JSP

Large market of JSF components

Over 200 components from over 20 vendors,

such as...

Apache, BusinessObjects, ESRI, Oracle, Sun, etc.

Page 57: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 57

© Copyright 2006, Sun Microsystems, Inc.

JSF Is AJAX-Friendly

Extensible component model

Well-defined request processing lifecycle

Flexible rendering model

Full refresh not required

Encapsulation enables hiding JavaScript from

the page author

State management helps keeping client and

server in sync

Page 58: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 58

© Copyright 2006, Sun Microsystems, Inc.

DynaFaces (Avatar)

Add-on to JSF 1.2

Extends the JSF 1.2 request lifecycle

Page author can identify AJAX “zones”

Refreshed independently

Component author can create composite

components via zones

Use provided JavaScript library for maximum

control

Page 59: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 59

© Copyright 2006, Sun Microsystems, Inc.

The easiest way to AJAXify an existing application

Demarcate one or more AJAX zones within a page

For each zone, provide some helper attributes to inform DynaFaces how to AJAXify the components within that zone.

Zones will refresh via AJAX, without full page refresh.

1. Click something in here

2. See update here

Action in one zonecauses reaction in

another zone

Using AJAX Zones

Page 60: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 60

© Copyright 2006, Sun Microsystems, Inc.

AJAX and NetbeansTM

Visual editing of JSF pages

NetbeansTM

plugin for drag-and-drop AJAX widgets using jMaki

Lots of widgets

Yahoo, Dojo, scriptaculous, Google, ...

JavaTM

Studio Creator technology

Portlet development

Page 61: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 61

© Copyright 2006, Sun Microsystems, Inc.

Web Beans (SEAM)

Observation#1: in joint EJB 3.0/JSF use,

backing beans act as glue between:

JSF-based front end

Stateless session bean for the business logic

JavaTM

Persistence API for persistence

Observation #2: knowledge of long-running processes is spread all over

Page 62: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 62

© Copyright 2006, Sun Microsystems, Inc.

Web Beans Solution

Use EJB 3.0 components as managed beans

Introduce conversation markers

@Begin, @End, @BeginTask, @EndTask

Move flow logic out of the beans

Support for “outjection”

moving objects out of the beans back into the

context

Page 63: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 63

© Copyright 2006, Sun Microsystems, Inc.

Conclusion

JavaTM EE 5 platform here now

Large improvements in ease-of-development

New technologies more focused, flexible, extensible, toolable, easy to learn

Fast pace of innovation all around the

platform

Lots of open source offerings

Page 64: Building Applications with the EE 5 Platform Java · Colorado Software Summit: October 22 – 27, 2006 Roberto Chinnici – Building Applications with the Java ™ EE 5 Platform Page

Colorado Software Summit: October 22 – 27, 2006

Roberto Chinnici – Building Applications with the Java™ EE 5 Platform Page 64

© Copyright 2006, Sun Microsystems, Inc.

Building Applications with the

Java™ EE 5 Platform

Roberto ChinniciSenior Staff EngineerSun Microsystems, Inc.