Você está na página 1de 22

Shreekanth Vankamamidi

Right Sizing Ease of Development Web Services Robustness Enterprise Java Platform

Java EE 6.0
Pruning Extensibility Profiles Ease of Development EJB Lite Restful Services Web Profile

Java EE 5.0
Ease of Development Annotations EJB 3.0 Persistence New and update Web services

J2EE 1.3
EJB 2.0 CMP, Local Interfaces Component Architecture

J2EE 1.4
Web Services Management Deployment Async Connector

J2EE 1.2
Servlet JSP EJB RMI/IIOP

December 1999

September 2001

November 2003

May 2006

December 2009

J2EE 1.3 Packaging


EJB 2.0
EJB 2.0 Interoperability Local Interfaces EJB QL Message-driven Bean

Servlet 2.3
Servlet Filtering Application lifecycle Listeners and Events Enhanced Internationalized support

JSP 1.2
XML Views of JSP Pages

J2EE 1.4 Packaging


EJB 2.1
Stateless Session Beans as Web Service end points EJB as Web Service client Timer service (to receive timed call backs) JCA 1.5 Does bi-directional communication with EIS and App Server

Servlet 2.4
JAX-RPC Web Services Endpoints Added listeners to Request Attributes (Session Listeners)

JAX-RPC Web Service End Points


Define JAX-RPC interface (matches WSDL) Provide implementation class Declare in web.xml (servlet) Declare in WEB/webservices.xml (service-impl-bean & servlet-link)

Web Services in J2EE


Options
JAX-RPC class as Servlet JAX-RPC as Stateless Session Bean Deployment Generate JAX-RPC stubs, etc from WSDL Package stubs, WSDL, classes in ejb-jar or war ejb-jar.xml or web.xml webservices.xml, webservicesclient.xml

Client Access
JAX-RPC or plain SOAP/HTTP

Service End Point Interface

public interface Country implements java.rmi.Remote { public String getCountry(int id) throws RemoteException; }

Service Implementation
import java.xml.rpc.server.ServiceLifecycle; public class CountryImpl implements Country, ServiceLifecycle { public String getCountry(int id){ return country; } } Configuration File (config.xml ) // to generate the various server-side artifacts required by the JAX-RPC runtime <?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://java.sun.com/jax-rpc-ri/xrpcc-config"> <rmi name=MyServices" targetNamespace="http://sunreg.org/wsdl" typeNamespace="http://sunreg.org/types"> // name here for public registry <service name=CountryService" packageName=.."> <interface name="SunRegPort" servantName="SunRegImpl"/> </service> </rmi> </configuration>

JEE 5.0
EJB 3.0
EJB 3.0 simplified
No longer home interfaces for EJB components Annotations as major facilitator for implementing EJB 3.0 components @Stateless public class StockBean implements Stock { public double getQuote(String symbol) { return 100.33; } }

Java Persistence Architecture API

Servlet 2.3
Servlet Filtering Application lifecycle Listeners and Events Enhanced Internationalized support

JSP 1.2
XML Views of JSP Pages

Web Services JAX-WS


Annotations IoC

Web services started with SOAP(only described what the messages looked like)
Then WSDL, which did not tell how to write Web services in Java

Then JAX-RPC 1.o, followed by JAX-RPC 1.1 and then thought of with JAX-RPC 2.0 (to align with industry direction)
But the industry not merely using RPC web services, also doing Message Oriented web services So RPC was removed and finally ending up with JAX-WS 2.0

Whats new in JAX-WS Similarities


JAX-WS still supports SOAP 1.1 over HTTP 1.1 JAX-WS still supports WSDL 1.1

Differences

JAX-RPC and JAX-WS support SOAP 1.1. JAX-WS also supports SOAP 1.2. JAX-RPC ignored the HTTP binding (Sending XML over http without SOAP) JAX-WS adds support for it. JAX-RPC maps to Java 1.4. JAX-WS maps to Java 5.0. JAX-WS relies on many of the features new in Java 5 The data mapping model
JAX-RPC has its own data mapping model, which covers about 90 percent of all schema types. Those that it does not cover are mapped to javax.xml.soap.SOAPElement. JAX-WS's data mapping model is JAXB. JAXB promises mappings for all XML schemas. JAX-WS's basic interface mapping model is not extensively different from JAX-RPC's; however: JAX-WS's model makes use of new Java 5.0 features. JAX-WS's model introduces asynchronous functionality. JAX-WS's dynamic client model is quite different from JAX-RPC's. Many of the changes acknowledge industry needs:
It introduces message-oriented functionality. It introduces dynamic asynchronous functionality.

The interface mapping model


The dynamic programming model

JAX-WS also adds a dynamic server model, which JAX-RPC does not have.

MTOM (Message Transmission Optimization Mechanism)


JAX-WS, via JAXB, adds support for MTOM, the new attachment specification. Since everyone supports MTOM, so attachment interoperability should become a reality.

Reasons you may want to stay with JAX-RPC 1.1:

If you want to stay with something that's been around a while, JAX-RPC will continue to be supported for some time to come. If you don't want to step up to Java 5. If you want to send SOAP encoded messages or create RPC/encoded style WSDL.

Reasons to step up to JAX-WS 2.0:


If you want to use the new message-oriented APIs. If you want to use MTOM to send attachment data. If you want better support for XML schema through JAXB. If you want to use an asynchronous programming model in your web service clients. If you need to have clients or services that can handle SOAP 1.2 messages. If you want to eliminate the need for SOAP in your web services and just use the XML/HTTP binding. If you like playing with leading edge technology.

EJB 3.0 split into 3 sub specification

EJB 3.0 Simplified API


EJB components no longer require home interfaces J2SE 5.0 annotations are now a major facilitator for implementing EJB 3.0 components EJB 3.0 introduces the notion of a business interface, rather than separate remote and local interfaces @Stateless public class StockBean implements Stock { public double getQuote(String symbol) { return 100.33; } } @Remote public interface Stock { public double getQuote(String symbol) { return 100.33; } } Remote interface

Core Contracts and Requirements


Container services Uses annotations (in additional to xml) to apply container services.
@TransactionAttribute(TransactionAttributeType.REQUIRESNEW)

Callbacks Callbacks are now handled through annotations as well Interceptors EJB now has ability to perform AOP for pre/post processing and cross cutting concerns. Dependency injection Instead of JNDI lookups, an EJB can define a resource reference by injecting code

Java Persistence Architecture (JPA) EJB 3.0 introduces a new style of persistence, POJO-based persistence Modeled on successful patterns. Simplifies JDBC access patterns. Can be integrated with Web services. Container stays out of the way; you can use JPA in a Java EE or Java SE environment. Standardized O/R mapping metadata. Support for top-down, meet-in-the-middle, and bottom-up development. Support for disconnected and connected objects states, eliminating the need for separate Data Transfer Objects. Figure 2 shows an example.

Java EE 6 is next big step in the journey towards the idea of a simple, streamlined and well-integrated platform
Pruning: Pruning the Dead meat

JAX-RPC JAX-RPC was an early attempt at modeling SOAP web services as RPC calls. Web services are now much more robust, feature-rich and popular JAX-WS API effectively supersedes JAX-RPC JAXR JAXR is for interfacing with UDDI registries. Unfortunately, UDDI is not widely used. EJB 2.x Entity Beans CMP The complex, heavyweight model replaced by the popular, lightweight, POJO based JPA persistence model. Java EE Application Deployment JSR 88 was an attempt at developing deployment tools that work across application servers. Unfortunately, this API has never got popular, and never gained much vendor support Java EE Management Application server management tools that work in a cross-vendor manner. Like JSR 88, the idea never paved off. Biggest criticism of Java EE is its too large, profiles designed to address this issue. The proposed Java EE Web Profile will only include APIs that are likely to be used in most Java web applications Java ME supports the idea of Profiles geared towards particular device runtime environments.

Profiles: Its sub-set of Java EE API tuned for specific applications


API Servlet 3.0 JSP 2.2 JSTL 1.2 EL 1.2 JSF 2.0 WebBeans 1.0 (?) EJB 3.1 (Lite)

Web Profile

Full Profile

Y Y Y Y Y Y

EJB 3.1 (Full)


JPA 2.0

Y
Y

JTA 1.1
JMS 1.1

Y
Y

JavaMail 1.4
JAX-WS 2.2

Y
Y

JAX-RS 1.1
JAXB 2.2 JACC 1.0 JCA 1.6

Y
Y Y Y

Web Beans 1.0:


Tries to resolve issue in Java EE where the presentation layer(Servlets, JSP,JSF) and persistence layer (EJB, JPA, JCA) are grown separately without much closer interactions. Web Beans resolves the issue by defining beans which can be interacted by multiple tiers. Java Bean with constructor and no Parameter is a Web Bean Almost every Java bean is a Web Bean by its nature and can enable Web Bean specifications by XML configurations. A Web Bean implementation may be a Java class, an EJB session or singleton bean class, a producer method or a JMS queue or topic Web-beans.xml marks application as Web Bean Application
@Stateful @RequestScoped @Named("translator") public class TranslatorControllerBean implements TranslatorController { @Current TextTranslator translator; // The bean also has getters and setters for all the fields on the page.

public class TextTranslator { private Translator sentenceTranslator; @Initializer TextTranslator(Translator sentenceTranslator) { this.sentenceTranslator = sentenceTranslator; // Stateless session bean

JSF 2.0

Despite of competitive Java presentation tier framework, still JSF holds ground JSF adds Facelets (Open source view technology) as a view technology JSF 2.0 brings Java EE 5 style annotation-driven configurations
JSF 2.0 changes JSF life cycle to account for Ajax

EJB 3.1

EJB 3.1 continued to making EJB as simple as possible


Business inerfaces made optional even for Session Beans (helps Sessoins beans to use in JSF with Web Beans) Adds Singleton beans to share thread safe application state Supports Cron-style scheduling API Can invoke Session beans methods asynchronously Concept of EJB lite which supports Transaction and Security but not remoting, messaging and scheduling. Allows EJB lite to package as part of War files

JPA 2.0

Adds a number of much needed ORM mapping enhancements such as ability to model collections, maps and lists Both Entity Manager and Query APIs enchanced to support to retrieve first result. Standardized second level of caching Adds Criteria API

Servlet 3.0

Introduced annotations @WebServlet, @ServletFilter to reduce web.xml configurations Ability to programmatically add Servlets, Filters and Listeners
@WebServletContextListener() public class SimpleServletContextListener { public void contextInitialized(ServletContextEvent event){ ServletContext context = event.getServletContext(); context.addServlet(simpleServletName, desc", "net.javabeat.servlet30.newfeatures.SimpleServlet", initParams, -1, false); }

Web Fragments: Servlets 3.0 is not really required to change web.xml for adding 3rd party libraries like struts, spring.

A web fragment can be considered as one of the segment of the whole web.xml and it can be imagined that one or more web fragments constitute a single web.xml file.
<web-fragment> <servlet> <servlet-name>myFrameworkSpecificServlet</servlet-name> <servlet-class>myFramework.myFrameworkServlet </servlet-class> </servlet> <listener> <listener-class>myFramework.myFrameworkListener</listener-class> </listener> </web-fragment>

It is responsibility of the framework to define the web fragment with the name web-fragment.xml in its jar file. During the application startup, it is the responsibility of the Container to scan the information that is found in the /META-INF/web-fragment.xml file available in the application's classpath.

Introduces Introduced Asynchronous processing support


@WebServlet( name = "SimpleServlet", urlPatterns = {"/simple"}, initParams = { @InitParam(name = "param1", value = "value1"), @InitParam(name = "param2", value = "value2")}, asyncSupported = true, asyncTimeout = 3000 ) public class SimpleServlet { }

JAX-RS 1.1: Its REST counter part of JAX-WS


Its designed to reduce REST development to POJO programming and annotations based configurations JAX-RS is integrated with Servlets, Web Beans and EJB

import javax.ejb.EJB; import javax.ejb.Stateless; import javax.ws.rs.*; /** * REST Web Service * * @author Shreekanth Vankamamidi */ @Stateless @Path("/helloWorld") public class HelloWorldResource { @EJB private NameStorageBean nameStorage; @GET @Produces("text/html") public String getXml() { return "<html><body><h1>Hello "+nameStorage.getName()+"!</h1></body></html>"; } @PUT @Consumes("text/plain") public void putXml(String content) { nameStorage.setName(content); } }

import javax.ejb.Singleton; /** Singleton session bean * @author Shreekanth Vankamamidi */ @Singleton public class NameStorageBean { // name field private String name = " REST Web Service"; public String getName() { return name; } public void setName(String name) { this.name = name; } }

Conclusion The focus of Java EE 6 is ease of development and simplicity: that is, supporting all the technologies and frameworks from the enterprise Java community yet still continuing to simplify the platform.

It includes a rich set of innovations best reflected in the technologies that comprise the platform including brand new APIs like Web Beans 1.0 and JAX-RS 1.1 or even mature APIs like Servlet 3.0.

References: http://www.oracle.com/technetwork/java/index.html http://www.theserverside.com

Você também pode gostar