What's new in Java EE 7? From HTML5 to JMS 2.0

35
What's new in Java EE 7? From HTML5 to JMS 2.0

description

Discover the new capabilities that Java EE 7 has to offer for you to build HTML5 applications. See some of the changes JMS brought to increase your Productivity! These slides were presented at JBoss Users and Developers Conference, JUDCon Brazil 2013, on April 19th.

Transcript of What's new in Java EE 7? From HTML5 to JMS 2.0

What's new in Java EE 7?From HTML5 to JMS 2.0

The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract.It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

...

Bruno Borges

● Oracle Product Manager● Java Evangelist● Developer● Gamer● Beer lover● Java Embedded newbie● GoT / TBBT / Dexter addicted

@brunoborges

http://blogs.oracle.com/brunoborges

Agenda

● Java EE 7 – What's new?● Building HTML5 Applications

– WebSockets 1.0– JAX-RS 2.0– JavaServer Faces 2.2

● Messaging with JMS 2.0● More code samples for Java EE 7● Upcoming

What's new in Java EE 7?

● Servlet 3.1● Java API for JSON Processing 1.0● Bean Validation 1.1● Batch Applications API 1.0● Java Persistence API 2.1● Concurrency Utilities for Java EE 1.0● And more... :-)

What's new in Java EE 7?

● Web Profile updated to include– JAX-RS

– WebSocket

– JSON-P

– EJB 3.2 Lite

– Others

– Batch and/or JMS maybe?

Building HTML5 Applications

● WebSocket 1.0● JAX-RS 2.0● JavaServer Faces 2.2

WebSockets 1.0

● API for WebSocket Client/Endpoints– Annotation-driven (@WebSocketEndpoint)

– Interface-driven (Endpoint)

– Client (@WebSocketClient)

● SPI for data frames– WebSocket opening handshake negotiation

● Integration with Java EE Web container

Hello WebSockets

import javax.websocket.*;import javax.websocket.server.*;

@ServerEndpoint(“/hello”)public class HelloBean {

    @OnMessage    public String sayHello(String name) {        return “Hello “ + name;    }}

Chat Server

@ServerEndpoint(“/chat”)public class ChatBean {

    @OnOpen    public void onOpen(Session peer) {        peers.add(peer);    }

    @OnClose    public void onClose(Session peer) {        peers.remove(peer);    }

    @OnMessage    public void message(String msg, Session client) {        peers.forEach(p ­> p.getRemote().sendMessage(msg));    }}

DEMO WebSockets

Maven Archetypes for Java EE 7

● Maven Archetypes for Java EE 7– http://mojo.codehaus.org

● Maven Archetype for Embedded GlassFish and Java EE 7– http://github.com/brunoborges/javaee7-archetype

– All you need is:● $ mvn package embedded-glassfish:run

JAX-RS 2.0

● Client API● Message Filters & Entity Interceptors● Asynchronous Processing – Server & Client● Hypermedia Support● Common Configuration

JAX-RS 2.0 Client

// Get instance of ClientClient client = ClientFactory.getClient();

// Get customer name for the shipped productsString name = client.target(“http://.../orders/{orderId}/customer”)                    .resolveTemplate(“orderId”, “10”)                    .queryParam(“shipped”, “true)”                    .request()                    .get(String.class);

JAX-RS 2.0 Server@Path("/async/longRunning")public class MyResource {

@GET public void longRunningOp(@Suspended AsyncResponse ar) { ar.setTimeoutHandler(new MyTimoutHandler()); ar.setTimeout(15, SECONDS); Executors.newSingleThreadExecutor().submit(new Runnable() { public void run() { ... ar.resume(result); }}); }

}

JavaServer Faces 2.2

● Flow Faces● HTML5 Friendly Markup● Cross-site Request Forgery Protection● Loading Facelets via ResourceHandler● File Upload Component● Multi-templating

DEMO JSF 2.2

Java Message Service API 2.0

● Simplified existing JMS API 1.1 without breaking compatibility

● New API requiring fewer objects– JMSContext, JMSProducer...

● In Java EE, allow JMSContext to be injected and managed by container

● JMS objects implement AutoCloseable● Async send

Java Message Service API 2.0

● JMSContext– Encapsulates Connection, Session, and

anonymous MessageProducer

● Created from a default (or specified) ConnectionFactory

● Unchecked exceptions● Supports method chaining for fluid style

Default JMS resources

● Default objects and JNDI names

@Resource(lookupName = “java:comp/defaultJMSConnectionFactory”)ConnectionFactory myJMScf;

@Resource(lookupName = “jms/inboud”)private Queue inboundQueue;

@Inject@JMSConnectionFactory(“jms/myCF”)private JMSContext context;

Easier definition of JMS resources

@JMSConnectionFactoryDefinition( name=”java:global/jms/demoCF” className = “javax.jms.ConnectionFactory”)

@JMSDestinationDefinition( name = “java:global/jms/inboudQueue” className = “javax.jms.Queue” destinationName = “inboundQueue”)

Message Driven Beans

@MessageDriven(mappedName = “jms/myQueue”, activationConfig = { @ActivationConfigProperty( propertyName = “destinationLookup”, propertyValue = “jms/myQueue”), @ActivationConfigProperty( propertyName = “connectionFactoryLookup”, propertyValue = “jms/myCF”)})

DEMO JMS 2.0

More Java EE 7 Sample Code

Can't DEMO everything...

Java API for JSON-P

● JsonParser– Processa JSON em modo “streaming”

● Similar ao XMLStreamReader do StaX

– Como criar● Json.createParser(...)● Json.createParserFactory().createParser(...)

– Eventos do processador● START_ARRAY, END_ARRAY, START_OBJECT,

END_OBJECT, ...

Java API for JSON-P

"phoneNumber": [ { "type": "home", "number": ”408-123-4567” }, { "type": ”work", "number": ”408-987-6543” }]

JsonGenerator jg = Json.createGenerator(...);jg.

.beginArray("phoneNumber")

.beginObject()

.add("type", "home")

.add("number", "408-123-4567")

.endObject()

.beginObject()

.add("type", ”work")

.add("number", "408-987-6543")

.endObject()

.endArray();

jg.close();

Bean Validation 1.1

public void placeOrder( @NotNull String productName, @NotNull @Max(“10”) Integer quantity, @Customer String customer) { //. . .}

@Futurepublic Date getAppointment() { //. . .}

Batch API 1.0<job id=“myJob”> <step id=“init”> <chunk reader=“R” writer=W” processor=“P” /> <next on=“initialized” to=“process”/> <fail on=“initError”/> </step> <step id=“process”> <batchlet ref=“ProcessAndEmail”/> <end on=”success”/> <fail on=”*” exit-status=“FAILURE”/> </step></job>

Schedule

● GlassFish 4.0 and Java EE 7 to be released almost together– this year for sure :-)

Transparency

● Most on JCP 2.8, some on JCP 2.9– Open mailing list

– Open Issue tracker

– Public access to download artifacts

Adopt a JSR

● JUGs participating actively● Promoting JSRs to

the Java community– Reviewing specs

– Trying out beta specs with samples

– Examples, docs, bugs

– Blogging, speaking at conferences, JUG meetings

Links

● Java EE 7 Expert Group Project– http://javaee-spec.java.net

● Java EE 7 Reference Implementation– http://www.glassfish.org

● Adopt a JSR– http://glassfish.org/adoptajsr

● NetBeans and Java EE 7– http://wiki.netbeans.org/JavaEE7

Thank you

Follow me on Twitter: @brunoborgeshttp://blogs.oracle.com/brunoborges