1 What’s new in J2EE 1.4? Erin Mulder – PhillyJUG – October 2002.
-
Upload
marybeth-howard -
Category
Documents
-
view
212 -
download
0
Transcript of 1 What’s new in J2EE 1.4? Erin Mulder – PhillyJUG – October 2002.
1
What’s new in J2EE 1.4?Erin Mulder – PhillyJUG – October 2002
Copyright © 2002 - Chariot Solutions, LLC 2
Tonight, we’ll cover…
• Quick History of J2EE
• What’s new in J2EE 1.4?
• Where to go from here…
Copyright © 2002 - Chariot Solutions, LLC 3
J2EE Timeline
1997 20031998 1999 2000 2001 2002
(All dates are approximate. Many of these technologies were hyped long before they were actually released.)
JNDI
JMSEJB
JSPServlets
EJB 1.0
J2EE
Servlets 2.1
JSP 1.0
Servlets 2.2
JSP 1.1
J2EE 1.2
EJB 1.1
JCA 1.0
J2EE 1.3
EJB 2.0
JMS 1.0
Servlets 2.3
JSP 1.2
XML Support JAX Pack WS Pack
JMS 1.1
Web Services
J2EE 1.4
EJB 2.1
JCA 1.5
Servlets 2.4
JSP 2.0
Copyright © 2002 - Chariot Solutions, LLC 4
How the spec evolves…
• Java Community Process (www.jcp.org)
– Java Specification Request (JSR) submitted to community
– Expert Group formed of interested companies and individuals
– Draft specification submitted for public review and eventual vote
• JSR 151 produced the J2EE 1.4 specification
• Currently a Proposed Final Draft
• Includes more than 12 other specifications
Copyright © 2002 - Chariot Solutions, LLC 5
What’s in J2EE 1.4?
JSR 109 Web Services
JSR 153 Enterprise Java Beans (EJB) 2.1
JSR 154 Java Servlets 2.4
JSR 152 Java Server Pages (JSP) 2.0
JSR 112 Java Standard Tag Library (JSTL) 1.0
JSR 914 Java Message Service (JMS) 1.1
JSR 112 J2EE Connector Architecture (JCA) 1.5
JSR 77 J2EE Management
JSR 88 J2EE Deployment
More than a dozen specifications, including…
Copyright © 2002 - Chariot Solutions, LLC 6
J2EE 1.4 Highlights
• Web Services
• EJB Timer Services
• More flexible Message-Driven Beans
• EJB-QL Enhancements
• New Servlet Listeners
• JSP Expression Language
• Easier JSP custom tag development
• Standard Tag Library
• Simpler JMS interface
• JCA Enhancements
• Cross-vendor J2EE management
• Cross-vendor J2EE application deployment
Copyright © 2002 - Chariot Solutions, LLC 7
Web Services: Overview
• Stateless RPC protocol for cross-platform integration
• Based on Simple Object Access Protocol (SOAP)
• Similarities to CORBA and other integration technologies
• Wide industry support (Microsoft, IBM, etc.)
• Web Service Endpoints publish a Web Services Description Language (WSDL) file describing their services to clients
• JAX-RPC hides implementation details for Java clients/endpoints
Copyright © 2002 - Chariot Solutions, LLC 8
Web Services: Server View
Three main options for implementing a web service endpoint in J2EE:
Stateless Session EJB Servlet w/JAX-RPC Servlet w/direct SOAPDefine service endpoint interface (SEI) with matching methods in bean implementation class
Create WS descriptor:
META-INF/webservices.xml
Declare SEI in ejb-jar.xml
Container manages JAX-RPC translation
Define service endpoint interface with subset of servlet’s public methods
Create WS descriptor:
WEB-INF/webservices.xml
Container manages JAX-RPC translation
Filters, etc. still allowed
Process SOAP messages directly using normal Servlet interface
Much more tedious, complex
Much more flexible for dynamic queries, non-HTTP protocols, etc.
No container interaction
Copyright © 2002 - Chariot Solutions, LLC 9
Web Services: Using JAX-RPC
• Web Service interfaces are defined in WSDL documents
• Tools can generate Java interface based on WSDL
• Tools can generate WSDL based on Java interface
• JAX-RPC restricts method params and return types to:
• Also allows arrays and beans composed of only those types
• Containers handle translation at runtime, based on descriptors
boolean
byte
double
float
int
long
java.lang.String
java.lang.Boolean
java.lang.Byte
java.lang.Double
java.lang.Float
java.lang.Integer
java.lang.Long
java.lang.Short
java.lang.BigDecimal
java.lang.BigInteger
java.lang.Calendar
java.lang.Date
Copyright © 2002 - Chariot Solutions, LLC 10
EJB 2.1: Web Service Endpoints
• A stateless session bean can be exposed as web service endpoint
• Define and implement a additional Service Endpoint Interface using only allowable data types
• Declare Service Endpoint Interface in ejb-jar.xml
• Create META-INF/webservices.xml descriptor
• The container handles everything else!
Copyright © 2002 - Chariot Solutions, LLC 11
EJB 2.1: Web Service Endpoints
Sample Service Endpoint Interface (SEI)
Sample EJB Implementation
public interface StockQuoteProvider extends javax.rmi.Remote {
public float getLastTradePrice(String symbol) throws javax.rmi.RemoteException;
}
public class StockManagerBean implements StockQuoteProvider, javax.ejb.SessionBean {
public float getLastTradePrice(String symbol) { … }
public void ejbCreate() throws CreateException { … } etc.
}
Copyright © 2002 - Chariot Solutions, LLC 12
EJB 2.1: Web Service Endpoints
Sample ejb-jar.xml<session> <ejb-name>StockManager</ejb-name> <session-type>Stateless</session-type> <ejb-class>com.acme.ejb.StockManagerBean</ejb-class> <home>com.acme.ejb.StockManagerHome</ejb-class> <remote>com.acme.ejb.StockManager</ejb-class> <service-endpoint>
com.acme.ws.StockQuoteProvider </service-endpoint>
…
Copyright © 2002 - Chariot Solutions, LLC 13
EJB 2.1: Web Service Endpoints
Sample webservices.xml<webservices> <web-services-description> <webservice-description-name>StockQuoteService</webservice-description-name> <port-component> <port-component-name>StockQuoteProvider</port-component-name> <service-endpoint-interface> com.acme.StockQuoteProvider </service-endpoint-interface> <service-impl-bean> <ejb-link>StockManagerBean</ejb-link> </service-impl-bean> …
Copyright © 2002 - Chariot Solutions, LLC 14
Web Services: Client View
• WS references can be placed in environment, just like other references:
• References are mapped to actual servers/ports in webservicesclient.xml
• Located and used at run-time through JNDI:
<session> <ejb-name>Portfolio</ejb-name> <ejb-class>com.acme.ejb.PortfolioBean</ejb-class> <service-ref> <description>Cool stock quote service</description> <service-ref-name>service/StockQuoteService</service-ref-name> <service-interface>com.acme.StockQuoteService</service-interface> </service-ref>
StockQuoteService sqs = (StockQuoteService) new InitialContext().lookup("java:comp/env/service/StockQuoteService");StockQuoteProvider sqp = sqs.getStockQuoteProviderPort();float quotePrice = sqp.getLastTradePrice(...);
Copyright © 2002 - Chariot Solutions, LLC 15
EJB 2.1: Timer Service
• Provides both single-action and interval-based callbacks
• Individual entities (e.g. “Invoice 63455”) can now manage their own time-dependent processes, e.g.– Holding a check for 7 days before posting payment
– Setting a document status to expired on its expiration date
• Stateless session beans and message-driven beans can use Timers to schedule batch processes
• Timers are persistent and survive server crashes
Copyright © 2002 - Chariot Solutions, LLC 16
EJB 2.1: Using Timers
Using Timers from an EJB:
– EJB implementation class must implement javax.ejb.TimedObject which requires an ejbTimeout() method
– During any normal invocation, the bean can obtain the TimerService from its ejbContext
– Calls TimerService.createTimer() to request a future notification
– When the Timer expires, the TimerService locates/creates the bean and calls ejbTimeout()
– If configured, ejbTimeout() can use container-demarcated transactions
Copyright © 2002 - Chariot Solutions, LLC 17
EJB 2.1: Timer Example
public class InvoiceBean implements javax.ejb.TimedObject, javax.ejb.EntityBean {
…
public void ejbPostCreate(…) {TimerService timerService = ejbContext.getTimerService();
timerService.createTimer(expirationDate, “Expiration”); }
public void ejbTimeout(Timer timer){String info = (String) timer.getInfo();if (info != null && info.equals(“Expiration”)){ setStatus(“Expired”);}
}}
Copyright © 2002 - Chariot Solutions, LLC 18
EJB 2.1: Timer Shortfalls
• Must be configured programatically from within bean instance
• No group management of timers
• No way to find instances with active timers
• Not as flexible as cron
• No support for custom intervals (e.g. avoiding holidays)
Copyright © 2002 - Chariot Solutions, LLC 19
EJB 2.1: Other Updates
• Message-Driven Beans no longer restricted to JMS– Can be invoked by JCA resource adapters– Must implement appropriate message listener interface
• EJB-QL Enhancements– Aggregate functions (avg, count, max, min, sum)– Additional scalar function (mod)– Ordering of results– Clarification of treatment of null values
Copyright © 2002 - Chariot Solutions, LLC 20
Servlet 2.3: Overview
• Defines web.xml deployment descriptor in XML Schema
• Adds request and request attribute listeners
• Allows finer control of filter invocation on calls to RequestDispatcher’s include() or forward()
• Requires HTTP 1.1 support
• Allows mapping of servlets as welcome files
• Adds lots of clarifications, e.g.:– Relationship between session and authentication
– Listener exception handling
– When listeners are called with respect to init() and destroy()
Copyright © 2002 - Chariot Solutions, LLC 21
JSP 2.0: Overview
• Focused on improving speed/ease of development
• Introduces Expression Language
• Allows custom tag development without Java code
• Makes tag library descriptors more self-documenting
• Works well with new Java Standard Tag Library
Copyright © 2002 - Chariot Solutions, LLC 22
JSP 2.0: Expression Language
• Allows cleaner, more concise expressions
• Scriptlets can now be disabled in page directive
<foo:add id=“sum” x=“${acct1.balance}” y=“${acct2.balance}”/>
Together, ${acct1.name} and ${acct2.name} have ${sum} dollars.
(Which should equal: ${acct1.balance + acct2.balance})
<%@ page isScriptingEnabled=”false” %>
Copyright © 2002 - Chariot Solutions, LLC 23
JSP 2.0: EL Functions
• Custom functions can be defined in a TLD
• Easily used inside EL expressions
<function> <name>getName</name> <function-class>com.acme.FooFunctions</function-class> <function-signature>String getName(String)</function-signature></function>
<p align=“center”> Welcome, ${foo:getName(username)}!</p>
Copyright © 2002 - Chariot Solutions, LLC 24
JSP 2.0: Codeless TagLibs
• Define custom tags in .tag files using only JSP syntax
• Can be packaged in jar with TLD like normal tags
• Or store under WEB-INF/tags and use implicit TLD like this:
<%@ taglib tagdir=“WEB-INF/tags/foo” prefix=”foo” %>…<foo:highlight hex=“ff0000”>some text</foo:highlight>
<%@ tag description=”Highlights text in specified color” %><%@ attribute name=“hex” required=“true” %>
<font color=“${hex}”><jsp:body/></font>
WEB-INF/tags/foo/highlight.tag
some.jsp
Copyright © 2002 - Chariot Solutions, LLC 25
JSP 2.0: Other TLD Updates
• Defined in schema, extensible (only for tools)
• New documentation elements
• More user-friendly for developers!
<tag> <name>add</name> <description>Adds two numbers</description> <display-name>add</display-name> <example>give usage example here<example> <tag-class>com.foobar.tags.AddTag</tag-class> …
Copyright © 2002 - Chariot Solutions, LLC 26
Java Standard Tag Library
• Provides useful standard tags for:
• Gives JSP developers a common, portable toolset
• Allows vendors to use optimized implementations
- Scoped attributes
- Exception handling
- Conditionals
- Iterations- URL translation- Resource imports
- Internationalization
- Formatting
- SQL Database Access
- XPath
- XSLT
Copyright © 2002 - Chariot Solutions, LLC 27
JSTL 1.0 – Core TLD
Attributes:
<c:out>
<c:set>
<c:remove>
Loops:
<c:foreach>
<c:forTokens>
Exceptions:
<c:catch>
Conditions:
<c:if>
<c:choose>
<c:when>
<c:otherwise>
URLs:
<c:import>
<c:url>
<c:redirect>
<c:param>
Copyright © 2002 - Chariot Solutions, LLC 28
JSTL 1.0 – Format TLD
Basic Formatting:
<fmt:timeZone>
<fmt:setTimeZone>
<fmt:formatNumber>
<fmt:parseNumber>
<fmt:formatDate>
<fmt:parseDate>
Internationalization:
<fmt:setLocale>
<fmt:bundle>
<fmt:setBundle>
<fmt:message>
<fmt:param>
<fmt:requestEncoding>
Copyright © 2002 - Chariot Solutions, LLC 29
JSTL 1.0 – SQL and XML TLDs
Database access:
<sql:query>
<sql:update>
<sql:transaction>
<sql:setDataSource>
<sql:param>
<sql:dateParam>
XML:
<x:parse>
<x:out>
<x:set>
<x:if>
<x:choose>
<x:when>
<x:otherwise>
<x:foreach>
<x:transform>
<x:param>
Copyright © 2002 - Chariot Solutions, LLC 30
Simplified JMS 1.1 API
• Used to have to use domain-specific interfaces to do anything useful
• Now the common interfaces provide everything you need
• Nice side effect: Queues and Topics can be obtained in the same session and thus used in same transaction
Common Point-to-Point Publish/Subscribe
ConnectionFactory QueueConnectionFactory TopicConnectionFactory
Connection QueueConnection TopicConnection
Destination Queue Topic
Session QueueSession TopicSession
MessageProducer QueueSender TopicPublisher
MessageConsumer QueueReceiver TopicSubscriber
Copyright © 2002 - Chariot Solutions, LLC 31
Connectors 1.5
• Used in systems integration (particularly w/legacy apps)
• Connectors 1.0 spec provided basic architecture:– Connection Management
– Transaction Management
– Security
• Connectors 1.5 spec adds:– Resource Lifecycle Management
– Work Management (using container-managed threads)
– Asynchronous communication
Copyright © 2002 - Chariot Solutions, LLC 32
Management Specification
• Will be implemented by J2EE Platform Vendors (BEA, IBM, Oracle, etc.)
• Provides common interface for cross-vendor tools to:
– Manage server resources
– Manage application life-cycle
– Monitor performance
• Specifies common JMX model, SNMP MIB, CIM, etc.
Copyright © 2002 - Chariot Solutions, LLC 33
Deployment Specification
• Will be implemented by J2EE Platform Vendors (BEA, IBM, Oracle, etc.)
• Single tool will be able to integrate with any J2EE Platform and:
– Configure applications
– Deploy applications
– Undeploy applications
• Great for IDEs, Network management tools, etc.
Copyright © 2002 - Chariot Solutions, LLC 34
Where to go from here…
• Think about Web Services when designing interfaces
• Embrace Model 2 web architecture
• Start using the Java Standard Tag Library (JSTL)
• Learn XML Schema
• Check the 1.4 spec for clarifications to murky issues
• Defer problems solved by 1.4 (for long-term projects)
• Keep an eye on Java Server Faces (JSF), Portlets
Copyright © 2002 - Chariot Solutions, LLC 35
Questions?
Java Community Process (www.jcp.org)
Erin Mulder ([email protected])
JSR 109 Web Services
JSR 153 Enterprise Java Beans (EJB) 2.1
JSR 154 Java Servlets 2.4
JSR 152 Java Server Pages (JSP) 2.0
JSR 112 Java Standard Tag Library (JSTL) 1.0
JSR 914 Java Message Service (JMS) 1.1
JSR 112 J2EE Connector Architecture (JCA) 1.5
JSR 77 J2EE Management
JSR 88 J2EE Deployment