red hat and oracle: delivering on the promise of interoperability in java ee 7
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.TRANSCRIPT
** Copyright © 2012, Oracle and/or its affiliates. All rights reserved.*
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Petr Jiricka, OracleMax Andersen, Red Hat
* 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.
* 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
* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Remember this?
* 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...
* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JBoss Way - JavaEE Examples (and more)
http://www.jboss.org/developer/
* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Oracle JavaEE 7 Examples
https://github.com/arun-gupta/javaee7-samples
* Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
The Example
KitchenSink - Java EE
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE 7
WebSocketJSONSimplified JMSBatchConcurrency UtilitiesCDIJAX-RSJPA...and more
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
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
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
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
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 { ... }}
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
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”
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.
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
*
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
*
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
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
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