Java EE 8 Presentation given at NYC Java SIG on May 4, 2017. This presentation provides the latest information on the forthcoming release of Java EE 8 in June.
2. Agenda
• Java EE 8 specification overview and current status
• Example of proposed enhancements
• JavaOne 2016 Java EE Reboot
• Java EE 9
• How to get involved and help
3. Importance of Java EE
https://javaee-guardians.io/java-ee-adoption-surveys
6. Java EE: Past, Present, Future
J2EE 1.2
Servlet,
JSP, EJB,
JMS, RMI
J2EE 1.3
CMP,
JCA
J2EE 1.4
Web
Services,
Mgmt,
Deploy
Java EE 5
Ease of
Use,
EJB 3,
JPA, JSF,
JAXB,
JAX-WS
Java EE 6
Pruning,
Ease of
Use,
JAX-RS,
CDI,
Bean-
ValidationWeb Profile
Servlet 3,
EJB 3.1 Lite
Java EE 7
JMS 2,
Batch, TX,
Concurrency
Web-
Sockets,
JSON
Java EE 8
SERVLET 4,
JSON-B,
JSON-P 1.1,
JSF 2.3, CDI
2.0, JAX-
RS 2.1,
SECURITY
7. Java EE 8 Community Survey
https://java.net/downloads/javaee-spec/JavaEE8_Community_Survey_Results.pdf
https://blogs.oracle.com/ldemichiel/entry/results_from_the_java_ee
8. Java EE 8 2016 Oracle Survey
http://tinyurl.com/jj853bm
9. Java EE 8 Overview – Original Plan
• Continued Enhancements for Web Standards Alignment
• HTTP/2, JSON Binding, JSON-P, MVC
• Cloud enhancements
• Security, RESTful Management API
• CDI Programming Model
• Ease of use, EJB via CDI
• Smaller, but Important Features
• Caching, Better Messaging
• Alignment with Java SE 8
17. Servlet 4.0
• Principal goal to support HTTP/2
• Request/response multiplexing over single connection
• Transparent to most developers, although possibly slight
changes to the Servlet API
• Most affected: frameworks
JSR 369
18. Servlet 4.0 – Exposing HTTP./2
• Stream Prioritization
• New Priority class
• Enhance HttpServletRequest and HttpServletResponse to
accommodate
• Server Push
• Frameworks can push resources to the client
• Not replacing WebSockets
JSR 369
19. JMS 2.1
• JSR 368 - In early stages
• No builds available for testing, as yet.
• Planning: https://java.net/projects/jms-
spec/pages/JMS21Planning
• Proposed to be dropped in EE 8
• New messaging service in EE 9
JSR 368
20. JMS 2.1
• JMS 2.0 was a major overhaul
• Continuation of API Modernization
• Declarative Message Listeners
• Alternative to MDB
• More Powerful Features
• Available to all Beans
• JMS Provider Portability Improvements
• Dead Message Queues
• Redelivery Behavior on JMS MDB Rollback (delays, max #
consecutive)
JSR 368
21. JMS 2.1 Asynchronous Batches
In JMS 2.0, messages delivered asynchronously by calling:
javax.jms.MessageListener onMessage(Message message)
Define new
javax.jms.BatchMessageListener onMessages(Message[] messages)
JSR 368
22. JMS 2.1 Asynchronous Batches
Example:
@MessageDriven
public class MyFlexibleMDB {
@JMSQueueListener(destinationLookup="java:global/
myQueue")
public void myMessageCallback(@Batch(maxSize=10,timeout=
1000) Message[] messages) {
...
}
JSR 368
24. JAX-RS 2.1
• JSR 370 - In Public Review
• Builds are available
• Reactive API
• Support for SSE (Server Sent Events)
• Integration with JSON-B
JSR 370
25. JAX-RS 2.1
JSR 370
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);
26. JAX-RS 2.1 – Server Sent Events
• 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
27. JAX-RS 2.1 – Server Sent Events
@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();
...
});
}
}
28. JSF 2.3
• JSR 372 - in active progress
• Milestones available for testing
• Read, Test, Supply Feedback
JSR 372
29. JSF 2.3
• Standardize Web Socket integration
• f:websocket
• Multi-field validation
• Date-time support
• Enhanced CDI Integration
• Lifecycle Enhancements
• PostRenderViewEvent
• EL API Enhancements
• Configuration Enhancements
• AJAX Enhancements
JSR 372
35. CDI 2.0 @Schedule Outside EJB
@ApplicationScoped
public class MyScheduledBean {
...
@Schedule(...)
public void myScheduledTask() { ... }
}
@ApplicationScoped
@Stereotype
@Retention(RUNTIME)
@Target(TYPE)
@Schedule(...)
public @interface MonthlyTask {}
JSR 365
36. JSON-P 1.1
• JSR 374 - In Public Draft
• More Information:
• https://json-processing-spec.java.net/
• Sources: https://java.net/projects/jsonp
JSR 374
37. JSON-P 1.1
• Updates to new API in Java EE 7
• New JSON Standards
• JSON-Pointer and JSON-Patch
• Editing Operations on JSON objects and arrays
• Helper Classes and Enhanced Java SE 8 support
JSR 374
38. JSON-P 1.1 Java SE 8 Support
• Java 8 Stream Support
• JsonArray persons;
persons.getValuesAs(JsonObject.class).stream()
.filter(x->x.getString(“age”) >= 65)
.forEach(System.out.println(x.getString(“name”)));
JSR 374
40. JSON-P 1.1: JSON-Patch
public void
shouldBuildJsonPatchExpressionUsingJsonPatchBuilder() {
JsonPatchBuilder patchBuilder = new JsonPatchBuilder();
JsonObject result = patchBuilder.add("/email",
"john@example.com")
.replace("/age", 30)
.remove("/phoneNumber")
.test("/firstName", "John")
.copy("/address/lastName", "/lastName")
.apply(buildPerson());
}
JSR 374
41. Java EE Management API 2.0
• Oracle dropping JSR from EE 8.
• Java EE Management API 1.0 – released 2002
JSR 373
42. Java EE Management API 2.0
• REST Based Interface to Supersede EJB Management
APIs of JSR 77
• Monitoring and deployment
• SSE for Event Support (WebSockets also under
consideration)
JSR 373
43. Bean Validation 2.0
• Add support for LocalTime, Optional, etc.
• Leverage type annotation, repeatable annotations,
reflective parameter name retrieval
• Potential enhancements:
• Customized constraint validations
• Object graph validation
• Example:
List<@Email String> emails;
JSR 380
46. MVC
• Model - View - Controller
• JSR 371
• Active Progress…download milestones
• Ozark: https://ozark.java.net/
JSR 371
47. MVC
• Action-Based Web Framework for Java EE
• Follows suit of Spring MVC or Apache Struts
• Does Not Replace JSF
• Model: CDI, Bean Validation, JPA
• View: Facelets, JSP (Extensible)
• Controller: Layered on top of JAX-RS
JSR 371
50. JSON-B
• Java API for JSON Binding
• JSR 367 - Public Review
• Read the spec, start testing:
https://java.net/projects/jsonb-spec/pages/Home
JSR 367
51. JSON-B Next Logical Step
• Standardize means of converting JSON to Java objects
and vice versa
• Default mapping algorithm for converting Java classes
• Draw from best of breed ideas in existing JSON binding
solutions
• Provide JAX-RS a standard way to support
“application/json” for POJOs
• JAX-RS currently supports JSON-P
JSR 367
52. JSON-B Mapping
@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"
}
}
JSR 367
53. JSON-B: Proposed Custom Mapping
• Utilization of annotations to map fields to JSON Document Elements
@JsonProperty(“poolType”)
public String poolType;
@JsonPropertyOrder(“poolType”,”shape”)
public class Pool(){
public String poolType;
public String shape;
…
}
{
poolType : “Inground”,
}
{
poolType : “Inground”,
shape : “Rectangle”
}
JSR 367
54. Java EE Security
• 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
• Proposed examples:
• https://github.com/javaee-security-spec/javaee-security-proposals
JSR 367
55. Java EE Security: Proposed Provider
@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", ...)
JSR 375
56. Simple Security Plugability
@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.
}
}
57. Security Context Example
@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();
}
}
58. EL Enabled Security Annotations
@IsAuthorized("hasRoles('Manager') && schedule.officeHours")
public void transferFunds();
@IsAuthorized(
"hasRoles('Manager') && hasAttribute('directReports', employeeId)")
public double getSalary(long employeeId);
59. JCache
• Java Temporary Caching API
• JSR 107 - Started in 2001
• Provides a common way for Java applications to create,
access, update, and remove entries from caches
JSR 197
60. JCache
• Provide applications with caching
functionality…particularly the ability to cache Java objects
• Define common set of caching concepts & facilities
• Minimize learning curve
• Maximize portability
• Support in-process and distributed cache implementations
JSR 107
63. Java EE Roadmap - JavaOne 2016
2016
• Feedback through Survey
• Launch Java EE Next JSRs
2017
• Java EE 8
• Specs, RI, TCK complete
• Initial microservices support
• Define Java EE 9
• Early access implementation
of Java EE 9
2018
• Java EE 9
• Specs, RI, TCK complete
• Modular Java EE runtime
• Enhanced microservices
support
68. Adopt-A-JSR
• Started in 2007, easy way for JUGs to get involved
• What you can do depends upon what you want to do &
what spec leads are looking for