Java EE 7

Making developers' lives easier

By Denys Digtiar / @duemir

Platform in JSRs

  • 14 JSRs
    • 4 of them New
  • 9 Maintenance Releases
  • 4 Pruned JSRs

14 JSRs

Java Platform, Enterprise Edition 7 (JSR 342) Concurrency Utilities for Java EE 1.0 (JSR 236) Java Persistence 2.1 (JSR 338) JAX-RS: The Java API for RESTful Web Services 2.0 (JSR 339) Java Servlet 3.1 (JSR 340) Expression Language 3.0 (JSR 341) Java Message Service 2.0 (JSR 343) JavaServer Faces 2.2 (JSR 344) Enterprise JavaBeans 3.2 (JSR 345) Contexts and Dependency Injection for Java EE 1.1 (JSR 346) Bean Validation 1.1 (JSR 349) Batch Applications for the Java Platform 1.0 (JSR 352) Java API for JSON Processing 1.0 (JSR 353) Java API for WebSocket 1.0 (JSR 356)

9 Maintenance Releases

Web Services for Java EE 1.4 (JSR 109) Java Authorization Service Provider Contract for Containers 1.5 (JACC 1.5) (JSR 115) Java Authentication Service Provider Interface for Containers 1.1 (JASPIC 1.1) (JSR 196) JavaServer Pages 2.3 (JSR 245) Common Annotations for the Java Platform 1.2 (JSR 250) Interceptors 1.2 (JSR 318) Java EE Connector Architecture 1.7 (JSR 322) Java Transaction API 1.2 (JSR 907) JavaMail 1.5 (JSR 919)

4+ pruned JSRs

Java EE Management (JSR 77)
Application Deployment (JSR 88)
JAXR for interfacing UDDI registries (JSR 93)
JAX-RPC (JSR 101)
EJB 2.x Container Managed Persistence

Show us some new APIs!!!

Java API for WebSocket 1.0 (JSR 356)
Java API for JSON Processing 1.0 (JSR 353)
Batch Applications for the Java Platform 1.0 (JSR 352)
Concurrency Utilities for Java EE 1.0 (JSR 236)

Main Themes

  • HTML5
  • Developer Productivity
  • Meeting Enterprise Demand

HTML5

Java API for WebSocket 1.0 (JSR 356)
Java API for JSON Processing 1.0 (JSR 353)

Java API for WebSocket 1.0

Overview

  • Full support for creating WebSocket Endpoints
    • Client profile
    • Server profile
  • 2 approaches
    • Programmatic (Endpoint)
    • Annotation based (@ServerEndpoint, @ClientEndpoint)

Java API for WebSocket 1.0

Main API classes (javax.websocket.*)

  • Endpoint - Intercepts WebSocket lifecycle events
    • onOpen
    • onClose
    • onError
  • MessageHandler - Handles all incoming messages for an Endpoint
  • RemoteEndpoint - Represents the 'other end' of this conversation
  • Session - represent the active conversation

Java API for WebSocket 1.0

Message Processing

  • Send or receive text and binary messages
    • As complete messages
    • As sequence of partial messages
    • Using traditional blocking I/O
  • Send or receive WebSocket messages as any Java object
    • Using pluggable encoder/decoder components
    • Encoders and decoders for Java primitives built in
  • Send messages synchronously or asynchronously

Java API for JSON Processing 1.0

  • Streaming API to produce/consume JSON
    • Low-level, efficient way to parse/generate JSON
    • Similar to StAX API in XML world
  • Object model API to represent JSON
    • Simple, easy to use high-level API
    • Similar to DOM API in XML world

JAX-RS 2.0

What's new?

  • Client API
  • Filters & Interceptors
  • Asynchronous Processing
  • Hypermedia
  • ... some other features

Developer Productivity

Contexts and Dependency Injection for Java EE 1.1 (JSR 346)
Bean Validation 1.1 (JSR 349)
Java Transaction API 1.2 (JSR 907)
Java Message Service 2.0 (JSR 343)

Contexts and Dependency Injection for Java EE 1.1

  • CDI is ON by default
    • "beans.xml" is optional
  • Bean discovery mode
    • all
    • annotated
    • none
  • @Vetoed
  • Global ordering/priority of interceptors and decorators

Bean Validation 1.1

  • Dependency injection and CDI
  • Method Validation
  • Integration with JAX-RS
  • Error message using EL expressions

Java Transaction API 1.2

Feature Summary

  • @Transactional: declarative transaction demarcation for CDI
  • @TransactionScoped: new CDI scope

Java Message Service 2.0

Get More from Less

  • New JMSContext interface
  • AutoCloseable: JMSContext, Connection, Session,...
  • Use of runtime exceptions
  • Method chaining on JMSProducer
  • Simplified message sending
  • Default ConnectionFactory

Java Message Service 2.0

Sending a Message using JMS 1.1


@Resource(lookup = "jms/myConnectionFactory")
ConnectionFactory connectionFactory;

@Resource(lookup = "jms/myQueue")
Queue myQueue;

public void sendMessage(String payload) {
    Connection connection = null;
    try {
        connection = connectionFactory.createConnection);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer messageProducer = session.createProducer(myQueue);
        TextMessage textMessage = session.createTextMessage(payload);
        messageProducer.send(textMessage);
    } catch (JMSException ex) {
        // ...
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException ex) { /* ... */ }
        }
    }
}
					

Java Message Service 2.0

Sending a Message using JMS 2.0


@Resource(lookup = "jms/myConnectionFactory")
ConnectionFactory connectionFactory;

@Resource(lookup = "jms/myQueue")
Queue myQueue;

public void sendMessage(String payload) {
    try (JMSContext context = connectionFactory.createContext();) {
        context.createProducer().send(myQueue, payload);
    }
}
					

Java Message Service 2.0

Sending a Message using JMS 2.0 and DI


@Inject @JMSConnectionFactory(lookup = "jms/myConnectionFactory")
JMSContext context;

@Resource(lookup = "jms/myQueue")
Queue myQueue;

public void sendMessage(String payload) {
    context.createProducer().send(myQueue, payload);
}
					

Meeting Enterprise Demand

Concurrency Utilities for Java EE 1.0 (JSR 236)
Batch Applications for the Java Platform 1.0 (JSR 352)

Concurrency Utilities for Java EE 1.0

javax.enterprise.concurrent.*

  • Extension of Java SE Concurrency Utilities API
  • 4 types of managed objects
    • ManagedExecutorService
    • ManagedScheduledExecutorService
    • ManagedThreadFactory
    • ContextService
  • Context Propagation (classloading, JNDI, security)
  • Event Notification (ManagedTask, ManagedTaskListener)

Concurrency Utilities for Java EE 1.0


class SomeBean {
    @Resource    /*(name="java:comp/DefaultManagedExecutorService")*/
    ManagedExecutorService executor;

    public void execute() {
        Future<String> result = executor.submit(new Callable<String>() {
            // callable implementation here
        });
        // do something else
    }
}
					

Batch Applications for the Java Platform 1.0

Feature Summary

  • Batch Programming Artifacts
  • Job Specification Language (JSL)
  • JobOperator Interface

Batch Applications for the Java Platform 1.0

Batch Programming Artifact overview

  • Codifies key batch programming constructs
    • Reader, Processor, Writter, Batchlet, Listerens, PartionPlan, ...
    • Batch runtime orchestrates flow based on well known patterns, e.g chunked (Reader, Processor, Writer)

Batch Applications for the Java Platform 1.0

Job Specification Language (JSL)

  • XML document
  • Defines a "job"
  • "Scripts" batch execution sequence
  • "Step" oriented
  • Conditional step execution
  • Supports parameterization and substitution

Batch Application for Java Platform 1.0

JobOperator Interface

  • Interface to the Batch Runtime
  • Defines operations to act on jobs
    • Start, stop, restart, job repository retrieval
  • "The" interface for applications to interact with jobs

What does the future hold for us?

  • JSON-B
  • JCache
  • NoSQL
  • Cloud (multi-tenancy, elasticity)
  • Jigsaw