<Insert Picture Here> Productive JavaEE 5.0 Development Frank Nimphius Principle Product Manager
Agenda Introduction Annotations EJB 3.0/JPA Dependency Injection JavaServer Faces JAX-WS Web Services Better JavaEE Productivity with ADF <Insert Picture Here>
The benefit of the JEE standard Implementation independent blueprint Describes how J2EE platform features work and how they are used by developers Developed through the Java Community Process Ensure that J2EE applications are portable across J2EE containers Leverage J2EE container services Solid base for custom, open source and vendor frameworks
JEE 5 - what's in the box? JSP 2.1 JSF 1.2 Servlet 2.5 EJB 3.0 /JPA 1.0 JAX-WS 2.0 JMS 1.1 JNDI 1.2 JCA 1.5 JTA 1.1 JMX 1.2 JACC and JAAS 1.0 J2EE Management 1.1
Annotations <Insert Picture Here>
Annotations in Java EE Simplify development of applications EJB / JPA Servlet Web Services Can be used instead of deployment descriptors Define types of beans, interfaces Lifecycle callbacks Use of resources DataSource, JMS object, mail, etc. Use of services Transactions, Security settings, Timer, etc. Common metadata annotations API (JSR 250)
Common metadata annotations Annotations javax.annotation.resource javax.annotation.postconstruct javax.annotation.predestroy javax.annotation.security.runas javax.annotation.security.rolesallowed javax.annotation.security.permitall javax.annotation.security.denyall javax.annotation.security.declareroles Module used EJB, Web, App Client EJB, Web EJB, Web EJB EJB EJB EJB EJB
EJB 3.0 / JPA <Insert Picture Here>
From "Good" to "Better" EJB 2.1 CMP Proprietary POJO Persistence EJB Java Persistence API JDO
Example: JPA Entity @Entity @Table(name="CUSTOMERS") public class Customer { @Id @Column(name= CUSTID ) private Long id; private String name; private Address address; private HashSet orders = new HashSet(); CUSTOMERS CUSTID (PK) NAME public Long getid() { return id; } protected void setid (Long id) { this.id = id; }...
Data Manipulation To insert new data: Create a new entity object Call the EntityManager.persist() method @PersistenceContext private EntityManager em;... public void persistuser() { User user = new User(); user.setfirstname( Frank"); user.setlastname( Nimphius"); em.persist(user); }
D E M O N S T R A T I O N EJB 3.0 / JPA
Dependency Injection <Insert Picture Here>
Resource lookup in J2EE 1.4 Need ejb-ref entry: <ejb-ref-name>mycart</ejb-ref-name> <ejb-ref-type>session</ejb-ref-type> <home>carthome</home> <remote>cart</remote> Complex lookup: Object homeobject = context.lookup("java:comp/env/mycart"); CartHome home = (CartHome) PortableRemoteObject.narrow(homeObject,CartHome.class); Cart cart = (Cart) PortableRemoteObject.narrow(home.create(), Cart.class); cart.additem("myitem1");
Dependency injection in JEE 5.0
Dependency injection Container can initialize instance variables at time bean is made available These techniques can be used to inject: Resources, Session bean references EntityManager Web service references Common annotations
Examples @EJB AdminService bean; public void privilegedtask() { bean.admintask(); } @Resource(name= mydb ) public void setdatasource(datasource mydb) { customerdb = mydb; } @Resource javax.ejb.sessioncontext sc; TimerService ts = sc.gettimerservice();
D E M O N S T R A T I O N Dependency Injection
JavaServer Faces <Insert Picture Here>
Evolution of J2EE web tier Servlets JSP JSF Each is built on the previous layer Progressive levels of abstraction Higher level programming
JSF technology JSF UI components - encapsulated in JSP tag libraries Navigation Model defines rules for navigation Managed Beans - facilitate the UI logic of the application Helper Objects Validation and conversion Abstracts away from HTTP Developers don t need to understand request-response cycle Abstracts away from HTML Developers work with components, not markup Developers don t need to decode requests
JSF architecture Device Renderer UIComponent is rendered through Renderer class Expression Language Value Binding is used to access managed bean also know as a "backing bean" Managed bean accesses J2EE persistence layer UI Component Expr. Language Managed bean JSF Page J2EE Persistence Layer / EJB 3.0 RDBMS
New in JSF 1.2 Common Expression Language used in JSP 2.1 and JSF 1.2 Component tree is rendered so that no premature JSP rendering happens Messages are improved and allow to override default messages in component attributes. Also, labels can be part of the message Improved state saving to better handle multiple frames and windows. In addition, client state can be encrypted Component ID generation can be switched off
Better JavaEE Productivity with ADF <Insert Picture Here>
JSR-227 Device Renderer Standard data binding Uses meta-data to describe business APIs Abstracts Business Services Exposes consistent client programming API Reduces learning curve Visual and declarative development UI Component Expr. Language bindings Object JSF Page ADF Binding ADF DataControl EJB 3.0 Web Service BPEL RDBMS
D E M O N S T R A T I O N Building JavaEE Web Applications with ADF
JAX-WS Web Services <Insert Picture Here>
Java EE 5 WS APl JAX WS 2.0 Web Services metadata 2.0 JAXB 2.0
JAX-WS Java API for XML Web Services SOAP messages over http Translates API calls from and to SOAP messages Uses annotations to define POJO or stateless EJB session bean as Web Service @WebService @WebMethod Business methods Must be public Can't be static or final
@PostConstruct, @PreDestroy PostConstruct Called by the container Called before WS interacts with client PreDestroy Called by container Called before endpoint is removed from operation
Web Service with JAX-WS 2.0 Annotate bean class or endpoint interface POJO or Stateless EJB Package and deploy Not required to run through Web Service Assembler or any other tool Doesn t need an endpoint interface @WebService(HelloServiceInf.class) public class HelloServiceBean{ @WebMethod public String sayhello(string name) {}.. }
Using JAX-WS Web Services JavaEE 5.0 simplified Web Service invocation Annotation used on Web Service client public class ResponseServlet extends HTTPServlet { @WebServiceRef(wsdlLocation= "http://localhost:8080/helloservice/hello?wsdl") static HelloService service;
D E M O N S T R A T I O N JAX-WS Web Service
Summary Standards are important JEE 5.0 simplifies standard based application development EJB 3.0 and JavaServer Faces are new in JEE 5.0 EJB 3.0 simplifies J2EE persistence using POJOs and POJIs JSF is a framework for building display agnostic web applications JAX-WS introduces annotations to Web Services JSR-227 defines a standard binding layer that abstracts Business Service implementation details