23
* * Copyright © 2012, Oracle and/or its affiliates. All rights reserved. *

Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Embed Size (px)

DESCRIPTION

This session discusses the promise of interoperability in the Java EE 7 platform and what has been done—even now, at its time of release—to maintain this. The session shows how a Java EE 7 application can be easily built using NetBeans and JBoss development tools. This application can then be deployed on JBoss, GlassFish, and Oracle WebLogic, showing the promise of interoperability. The state of Java EE 7 compliance for different application servers is discussed and demonstrated.

Citation preview

Page 1: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

** Copyright © 2012, Oracle and/or its affiliates. All rights reserved.*

Page 2: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Petr Jiricka, OracleMax Andersen, Red Hat

Page 3: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

The following 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.

Page 4: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Program Agenda

■ History of vendor-specific J2EE/Java EE■ Java EE 6■ Java EE 7■ JBoss and GlassFish interoperability

Page 5: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Remember this?

Page 6: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Maven

● Unifies dependency management● Functional Java EE 7 API’s are now available in Maven Central

● Unified build● Unified Examples

The thing to love or hate...

Page 7: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

JBoss Way - JavaEE Examples (and more)

http://www.jboss.org/developer/

Page 8: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Oracle JavaEE 7 Examples

https://github.com/arun-gupta/javaee7-samples

Page 9: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

The Example

KitchenSink - Java EE

Page 10: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Java EE 7

WebSocketJSONSimplified JMSBatchConcurrency UtilitiesCDIJAX-RSJPA...and more

Page 11: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

JPA - Persistence.xml

<persistence version="2.1" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="primary"> <!-- If you are running in a production environment, add a managed data source, this example data source is just for development and testing! --> <properties> <!-- Property for schema generation based on model --> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> <!-- Property for batch loading data into database --> <property name="javax.persistence.sql-load-script-source" value="import.sql"/> </properties> </persistence-unit></persistence>

● Default datasource● Standard schema generation configuration● sql-load scripting

Page 12: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

JSON - Parsing

URLConnection connection = new URL("https://api.github.com/search/users?q=" + member.getName()).openConnection(); try(InputStream stream = connection.getInputStream()) { JsonReader reader = Json.createReader(stream); JsonObject jsonObject=reader.readObject(); if(jsonObject.containsKey("items")) { JsonArray items = jsonObject.getJsonArray("items"); if(items.size()>0) { avatar = items.getJsonObject(0).getString("avatar_url"); } }

}

● Parsing of JSON● Navigation of JSonObjects

Page 13: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

JSON - Writing

final JsonObjectBuilder builder = Json.createObjectBuilder();

builder.add("name", m.getName()); builder.add("email", m.getEmail()); builder.add("phoneNumber", m.getPhoneNumber()); try (JsonWriter jw = factory.createWriter(writer)) { jw.writeObject(builder.build()); }

● Easily write out JSON structures

Page 14: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Batch - Background Jobs

● Long running background jobs● Fine vs Coarse grained setup● Can be suspended by the Container

Page 15: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Batch - Background Jobs

● On member registered○ Start background job○ Pull github for avatar images○ Store image in map from id to avatar used in table

META-INF/batch-jobs/lookupgithub.xml:<job id="lookupgithub" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0"> <step id="findgithub" > <batchlet ref="githubBatchlet"/> </step></job>

@Namedpublic class GithubBatchlet extends AbstractBatchlet {

@Inject private MemberRepository repository;

@Override public String process() throws Exception { ... }}

Page 16: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Batch - Background Jobs on Steroids...

● Long running background jobs● Fine vs Coarse grained setup● Can be suspended by the Container

Page 17: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

WebSocket

■ Bi-directional communication over HTTP port‒ Handshake to ensure both sides support WebSocket‒ “Protocol upgrade” from HTTP‒ Simple bidirectional messages, no headers

■ Server-side API for WebSocket in Java EE 7‒ Server endpoint: @javax.websocket.server.ServerEndpoint‒ Message encoders and decoders

■ Client-side API in JavaScript supported by modern browsers■ In the KitchenSink example

‒ When a new member is registered, the server sends a WebSocket notification about it to all clients who follow the “live log”

Page 18: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

WebSocket - Server

@ServerEndpoint( value = "/registration", encoders = {MemberEncoder.class}) public class RegistrationEndpoint {

@OnMessage public String onMessage(String message, Session s) { System.out.println("received: " + message); handleLoginRequest(s); return "received!"; }}

● ServerEndPoints registered via annotations● Methods for close, open, message etc.

Page 19: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

WebSocket - Clientself.websocket = new WebSocket("ws://localhost/app/registration"); self.websocket.onopen = function (evt) { console.log ('open'); window.mm.websocket.send("sending"); console.log('sent'); }; self.websocket.onmessage = function (evt) { console.log(evt); var m = new Member(); var dataobj = JSON.parse(evt.data); m.name(dataobj.name); m.email(dataobj.email); m.phoneNumber(dataobj.phoneNumber); window.mm.addItem(m); };

● On Member created○ receive message○ refresh table livelog

Page 20: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

*

Technology GlassFish implementation JBoss (Wildfly) implementation

JAX-RS Jersey RESTEasy

JPA EclipseLink Hibernate

Bundled database Derby H2

JSF Mojarra Mojarra

HTTP stack Grizzly Undertow

WebSocket Tyrus Undertow

Batch JBatch (IBM) JBaret

Implementation may be different...

… but both behave according to the specification

Page 21: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

*

IDE support for Java EE 7 servers

Server Eclipse IDE NetBeans IDE

GlassFish GlassFish 4 (Java EE 7) plugin by Oracle

GlassFish 4 (Java EE 7) integration built in

JBoss JBoss Tools by RedHat● JBoss 7 (Java EE 6)

supported now● Wildfly 8 (Java EE 7)

early access

JBoss integration built in● JBoss 7 (Java EE 6)

supported now● Wildfly 8 (Java EE 7)

not supported yet

Page 22: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Are we there yet ?

Java EE 7 makes it easier than ever, but…

Everything isn’t covered by spec

Software are written by humans

Page 23: Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Q & A

Example: https://github.com/maxandersen/jboss-as-quickstart/tree/j1ee7

Arun Java EE 7 examples:https://github.com/arun-gupta/javaee7-samples

JBoss Way Quickstarts:http://www.jboss.org/developer/quickstarts.htmlhttps://github.com/jboss-developer/jboss-eap-quickstarts