Others Talk, We Listen. Java EE 8 and Java EE 9 - What You Need to Know! Reza Rahman Senior Architect [email protected] @reza_rahman
Jul 02, 2015
Others Talk, We Listen.
Java EE 8 and Java EE 9 - What You Need to Know!Reza RahmanSenior [email protected]@reza_rahman
CapTech
Full-service US national IT consulting firm that focuses on client best interests, trust, servant leadership, culture, professionalism and technical excellence.
#28 in Vault's Consulting Top 50
#3 Best Consulting Internship#9 Best Overall Internship
#1 in Meeting Client’s Needs
#7 Best Firm to Work For#1 in Career Development
Ranked for the 7th Consecutive Year
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
J2EE 1.3
CMP,JCA
J2EE 1.4
Web Services, Mgmt, Deplymnt
Java EE 5
Ease of Use,EJB 3, JPA, JSF, JAXB,JAX-WS
Java EE 6
Pruning,Ease of Use,JAX-RS,CDI,Bean-Validation
Web Profile
Servlet 3,EJB 3.1 Lite
Java EE 7
JMS 2, Batch, TX, Concurr,Web-Sockets,JSON
Web Profile
JAX-RS 2
J2EE 1.2
Servlet, JSP, EJB, JMS, RMI
Java EE Past, Present and Future
The Continued Importance of Java EE
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
https://javaee-guardians.io/java-ee-adoption-surveys
https://javaee-guardians.io/java-ee-adoption-stories
Java EE Ecosystem
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Microservices and Java EE
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
http://microprofile.io
Java EE 8 Community Survey
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
https://java.net/downloads/javaee-spec/JavaEE8_Community_Survey_Results.pdf
Java EE 8 Scope
• Web Standards Alignment
• HTTP/2, SSE, JSON-B, JSON-P, action-oriented web framework• CDI Alignment
• CDI 2, EJB services outside EJB, EJB pruning, JSF managed bean pruning
• Enterprise
• Security, JCache, JMS• Java SE 8 Alignment
• JSF, JPA, JAX-RS, Bean Validation
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Servlet 4
• Principal goal to support HTTP 2
• Request/response multiplexing over single connection
• Multiple streams, stream prioritization
• Server push
• Binary framing
• Header compression
• Most of it can be done without major API changes
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
• API to marshal/un-marshal POJOs to/from JSON• Very similar to JAXB in the XML world
• Default mapping of classes to JSON• Annotations to customize default mappings• @JsonbProperty, @JsonbTransient
• Provide JAX-RS a built-in way to support “application/json” for POJOs• JAX-RS currently supports JSON-P• Providers support non–standard binding APIs
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
JSON-BJava API for JSON Binding
JSON-B Example
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@Entity public class Person {
@Id String name;
String gender;
@ElementCollection
Map<String, String> phones;
...
}
Person duke = new Person();
duke.setName("Duke");
duke.setGender("Male");
phones = new HashMap<>();
phones.put("home",
"650-123-4567");
phones.put("mobile",
"650-234-5678");
duke.setPhones(phones);
{
"name":"Duke",
"gender":"Male",
"phones":{
"home":"650-123-4567",
"mobile":"650-234-5678"
}
}
• Updates to JSON parsing API added in Java EE 7• Adapt to new JSON standards
• JSON Pointer
• JSON Patch• Java SE 8 alignment
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
JSON-P 1.1
JSON-Pointer Example
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
JsonArray contacts = ...;
JsonPointer pointer =
new JsonPointer(
"/0/phones/mobile");
JsonValue value =
pointer.getValue(contacts);
[
{
"name":"Duke",
"gender":"Male",
"phones":{
"home":"650-123-4567",
"mobile":
"650-234-5678"}},
{
"name":"Jane",
"gender":"Female",
"phones":{
"mobile":
"707-555-9999"}}
]
• Modifying parts of a JSON document• Patch itself a JSON document
• add, replace, remove, move, copy, test operations
• Must have "op" field and "path" field, may have “value” field
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
JSON-Patch
[
{"op": "replace", "path":"/0/phones/mobile",
"value":"650-111-2222"},
{"op": "remove", "path":"/1"}
]
JSON-Patch Example
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
[
{
"op":"replace",
"path":"/0/phones/mobile",
"value":"650-111-2222"},
{
"op":"remove",
"path":"/1"}
]
[
{
"name":"Duke",
"gender":"Male",
"phones":{
"home":"650-123-4567",
"mobile":"650-234-5678"}},
{
"name":"Jane",
"gender":"Female",
"phones":{
"mobile":"707-555-9999"}}
]
JsonPatchBuilder builder = new JsonPatchBuilder();
JsonArray result = builder.replace("/0/phones/mobile", "650-111-2222")
.remove("/1")
.apply(target);
• Lesser known part of HTML 5• Server-to-client streaming
• “Stock tickers”, monitoring applications• Just plain long-lived HTTP
• Between the extremes of vanilla request/response and WebSocket
• Content-type ‘text/event-stream’• Support via JAX-RS 2.1
• Non-standard API in Jersey
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Server-Sent Events (SSE)
SSE on the Server-Side
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@Path("tickers")
public class StockTicker {
@Resource ManagedExecutorService executor;
@GET @Produces("text/event-stream")
public void getQuotes(
@Context SseEventSink sink,
@Context Sse sse) {
executor.execute(() -> {
...
sink.onNext(sse.newEvent(stockqoute));
...
sink.close();
...
});
}
}
• Simplify security for Java EE and improve portability• Simple security providers
• Database, LDAP• Simple pluggability• Universal security context
• Enabling existing security annotations (@RolesAllowed) for all beans• EL enabled security annotations via interceptors• OAuth, OpenID, JWT
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Java EE Security
Simple Security Providers
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@DataBaseIdentityStoreDefinition (
dataSourceLookup="java:global/MyDB",
callerQuery=
"SELECT password FROM principals WHERE username=?",
groupsQuery="SELECT role FROM roles where username=?", ...)
@LdapIdentityStoreDefinition (
url="ldap://ds.acme.com:389",
baseDn="dc=acme,dc=com", ...)
Simple Security Pluggability
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@SecurityProvider
public class MySecurityProvider {
@Inject UserService userService;
@OnAuthentication
// The parameters should suit the credentials mechanism being
// used.
public Principal getPrincipal(
String username, String password) {
// Construct the principal using the user service.
}
@OnAuthorization
public String[] getRoles (Principal principal) {
// Construct an array of roles using the principal and user
// service.
}
}
Security Context Example
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@AccessLogged @Interceptor
public class AccessLoggingInterceptor {
@Inject private SecurityContext security;
@AroundInvoke
public Object logMethodAccess(InvocationContext ctx)
throws Exception {
System.out.println("Entering method: "
+ ctx.getMethod().getName());
System.out.println("Current principal: "
+ security.getCallerPrincipal());
System.out.println("User is admin: "
+ security.isCallerInRole("admin"));
return ctx.proceed();
}
}
EL Enabled Security Annotations
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@IsAuthorized("hasRoles('Manager') && schedule.officeHours")
public void transferFunds();
@IsAuthorized(
"hasRoles('Manager') && hasAttribute('directReports', employeeId)")
public double getSalary(long employeeId);
CDI 2
• Java SE bootstrap, modularity• Asynchronous events• Portable extension SPI simplifications and enhancements• Java SE 8 alignment
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Asynchronous CDI Events
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@Inject @CargoInspected Event<Cargo> cargoInspected;
...
public void inspectCargo(TrackingId trackingId) {
...
cargoInspected.fireAsync(cargo);
}
public void onCargoInspected(
@ObservesAsync @CargoInspected Cargo cargo) {
JMS 2.1
• Declarative message listeners
• Alternative to MDB, available to all beans
• Simpler syntax
• More powerful features• More portability
• Redelivery delay, redelivery limits, dead message queues
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Declarative JMS Listeners
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@ApplicationScoped
@MaxConcurrency(10)
public class HandlingEventRegistrationAttemptConsumer {
@JmsListener(
destination="jms/HandlingEventRegistrationAttemptQueue",
selector="source = 'mobile'",
batchSize=10,
retry=5, retryDelay=7000, deadLetterQueue=“jms/DLQ”,
orderBy=TIMESTAMP)
@Transactional
public void onEventRegistrationAttempt(
HandlingEventRegistrationAttempt... attempts) {
...
}
}
• Standard action-based web framework
• JSF continues to evolve separately• Model
• CDI, Bean Validation, JPA• View
• Facelets, JSP• Controller
• Majority of work here
• Based on JAX-RS
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
MVC
MVC Example
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@Controller
@Path("/")
@View("my-index.xhtml")
public class Bookstore {
@Inject private Models model;
@GET
public void index() {
model.put(”books", books);
}
}
Adopting Java SE 8
• Most of Java SE 8 can already be used with Java EE• Some APIs should adopt features• Repeatable Annotations
• JPA, JMS, JavaMail, EJB• Date-Time API
• JSF, JPA, Bean Validation• Completable Future
• JAX-RS, EJB, WebSocket, Concurrency Utilities
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Repeatable Annotations in Java EE
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@NamedQueries({
@NamedQuery(name=SELECT_ALL, query="..."),
@NamedQuery(name=COUNT_ALL, query="...")
})
public class Customer {
...
@NamedQuery(name=SELECT_ALL, query="...")
@NamedQuery(name=COUNT_ALL, query="...")
public class Customer {
...
Date/Time API with JPA
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
@Entity
public class Accident {
@Temporal(TemporalType.TIMESTAMP)
@Past
private Instant when;
}
CompletableFuture with JAX-RS
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
CompletionStage<String> cs1 = client.target("http://partner.us/api")
.request()
.rx()
.get(String.class);
CompletionStage<String> cs2 = client.target("http://supplier.be/api")
.request()
.rx()
.get(String.class);
// Get both responses in a List (when they are available)
CompletionStage<List<String>> listCompletionStage =
cs1.thenCombine(cs2, Arrays::asList);
Some Other Changes
• JSF/WebSocket integration• JSF/CDI integration• More Bean Validation constraints
• @Email, @NotEmpty• Broadcasting SSE events
• CDI event ordering
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Java EE Guardians
http://javaee-guardians.io
@javaee_guardian
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Oracle Java EE 8/9 Survey
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
https://blogs.oracle.com/theaquarium/entry/java_ee_8_community_survey2
Java EE 8 Scope
• Web Standards Alignment
• HTTP/2, SSE, JSON-B, JSON-P, action-oriented web framework• CDI Alignment
• CDI 2, EJB services outside EJB, EJB pruning, JSF managed bean pruning
• Enterprise
• Security, JCache, JMS• Java SE 8 Alignment
• JSF, JPA, JAX-RS, Bean Validation
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Java EE 8/9 Roadmap
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Java EE 9
• OAuth, OpenID, JWT• Dynamic configuration• Fat jars, modularity• Health check/metrics• Circuit breakers
• Dynamic discovery• Client-side load-balancing• NoSQL• Multitenancy• Events
• State management• Eventual consistency
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Summary
• Java EE remains vitally important to all of us• Java EE 8 has long-awaited critical features• There have been serious concerns, but Oracle has now committed to Java EE 8 and Java EE 9• Java EE 9 ideas are preliminary, concrete work already being done in MicroProfile• The time to get involved is now!
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.