JAX-RS - Doag

JAX-RS - Doag

Java EE und Java EE 8 Eine Bestandsaufnahme Peter Doschkinow Wolfgang Weigend ORACLE Deutschland B.V. & Co. KG November 2014 Copyright © 2014, Orac...

2MB Sizes 0 Downloads 14 Views

Java EE und Java EE 8 Eine Bestandsaufnahme

Peter Doschkinow Wolfgang Weigend ORACLE Deutschland B.V. & Co. KG November 2014

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

Safe Harbor Statement 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 © 2014, Oracle and/or its affiliates. All rights reserved.

3

Agenda 1

Java EE Status

2

Java EE 8 Themes

3

Java EE 8 Roadmap

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

4

Java EE Evolution and Status • Technology – Balance innovation, standardization, compatibility

• Community – Involvement: JCP, Adopt-a-JSR HTML5, Developer Productivity Infrastructure for Cloud Deployments

• Oracle‘s stewardship – Investments and delivery Enterprise Java Platform Robustness

Ease of Development

Lightweight

Web Services

1998-2004

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

2013 - Future 5

Java EE 7 • Full implementations

MEETING ENTERPRISE DEMANDS

DEVELOPER PRODUCTIVITY

– GlassFish 4.x Java EE 7 – WildFly 8.x – TMAX JEUS 8  More annotated POJOs  Less boilerplate code – Hitachi Cosminexus 10.0  Cohesive integrated – IBM WebSphere Liberty 8.5.5.6 platform – WebLogic 12.2.1

   

JAX-RS WebSockets JSON Servlet NIO

 Batch  Concurrency  Simplified JMS

http://www.oracle.com/technetwork/java/javaee/overview/compatibility-jsp-136984.html

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

6

Industry Trends

Microservices

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

7

Java EE and Reactive Programming Message-Driven Beans

JMS

Events

CDI

EJB 3 Asynchronous Session Beans

Asynchronous

Servlet

Async on Server

JAX-RS NIO

Async Remote Endpoints

WebSocket

Observers

Async on Client

Concurrency Utilities

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

Oracle Confidential –

8

Java EE and Microservices Building blocks for pragmatic microserveces

JAX-RS

JMS

WebSocket

JSF

JSON

Bean Validation

JAXB

CDI

EJB 3

JPA

JTA

Administration Monitoring

High Availability

JCA

Resources Security

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

Java EE 8 Community Survey 4500+ respondents

https://blogs.oracle.com/ldemichiel/entry/results_from_the_java_ee https://java.net/downloads/javaee-spec/JavaEE8_Community_Survey_Results.pdf Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

10

Java EE 8 Themes • HTML5 / Web Tier Enhancements • Ease of Development / CDI alignment • Infrastructure for running in the Cloud

• Java SE 8 alignment – Utilizing Java SE 8 new features

Java SE 8

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

11

HTML5 Support and Web Tier Enhancements • HTTP/2 support • Action‐based MVC • Server‐sent events – Part of HTML5 – By extending JAX-RS (already supported by Jersey)

• JSON Binding – Similar to JAXB (already supported by MOXy, included in Jersey)

• JSON Processing enhancements – Track new standards JSON-Pointer and JSON-Patch

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

12

HTTP/2 Address the Limitations of HTTP

• HTTP/2 IETF standard finalized in May (RFC 7540) • Reduce latency – Address the Head-of-Line blocking problem

• Support parallelism – Without requiring multiple connections

• Retain semantics of HTTP 1.1 • Define interaction with HTTP 1.x

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

13

HTTP/2 • Request/Response multiplexing over single connection – Fully bidirectional – Multiple streams

• Stream prioritization • Server push • Binary framing • Header compression (RFC 7541) • Upgrade from HTTP 1.1

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

14

Servlet 4.0 HTTP/2 Features in Servlet API

• Request/response multiplexing – Servlet request as HTTP/2 message

• Stream prioritization – Add stream priority to HttpServletRequest: new class Priority

• Server push • Upgrade from HTTP 1.1 • Binary framing – Hidden from API

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

15

JAX-RS 2.1 Covers many of the new Java EE 8 API

• Reactive programming API • Non-blocking I/O in porviders

• Support for Server Sent Events • JSON-B integration • MVC support through JAX-RS ressources as controllers • Better CDI integration • Hypermedia API improvements • Most of the above already implemented in Jersey (JAX-RS 2.0 RI) Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

16

MVC 1.0 JSR 371

• Action-based Model-View-Controller architecture – vs. component-based like JSF, Wicket, Tapestry

• Glues together key Java EE technologies: – Model • CDI, Bean Validation, JPA

– View • Facelets, JSP

– Controller • JAX-RS Ressources

• https://ozark.java.net (RI) Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

17

MVC 1.0 Example @Path("hello") public class HelloController { @Inject private User user;

A CDI Model

@GET @Controller public String hello(@QueryParam("name") String name) { user.setName(name); return "hello.jsp"; } A JSP View } Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

18

Server-Sent Events (SSE) • Part of HTML 5 – Standard JavaScript API on the browser

• 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.next() – Already supported in Jersey JAX-RS reference implementation

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

SSE on the Server-Side @Path("tickers") public class StockTicker { @Resource ManagedExecutorService executor; @GET @Produces("text/event-stream") public EventOutput getQuotes() { EventOutput output = new EventOutput();

executor.execute(() -> { ... output.send(new StockQuote(...)); ... }); return output; } }

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

SSE on the Client-Side WebTarget target = client.target("http://example.com/tickers"); EventSource eventSource = new EventSource(target) { @Override public void onEvent(InboundEvent inboundEvent) { StockQuote quote = inboundEvent.readData(StockQuote.class); ... } }; eventSource.open();

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

JSON-P 1.1 • Updates to new API in Java EE 7 • Adapt to new JSON standards – JSON-Pointer (IETF RFC 6901) – JSON-Patch (IETF RFC 6902)

• Editing operations for JsonObject and JsonArray • Helper classes and methods to better utilize SE 8’s stream operations

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

JSON-Pointer Similar to XPATH in XML

[ { "name":"Duke",

JsonArray contacts = ...;

"gender":"Male",

JsonPointer pointer =

"phones":{

Json.createPointer(

"home":"650-123-4567",

"/0/phones/mobile");

"mobile":

JsonValue value =

"650-234-5678"}},

pointer.getValue(contacts);

{ "name":"Jane", "gender":"Female",

"phones":{ "mobile": "707-555-9999"}} ] Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

JSON-Patch Similar to HTTP PATCH

• 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

• JsonObject and JsonArray are immutable – Utilize Builder pattern for editing API? [ {"op": "replace", "path":"/0/phones/mobile", "value":"650-111-2222"}, {"op": "remove", "path":"/1"}

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

JSON-Patch Possibilities [ {

"name":"Duke",

[

"gender":"Male",

{

"phones":{

"op":"replace",

"home":"650-123-4567",

"path":"/0/phones/mobile",

"mobile":

"value":"650-111-2222"},

"650-234-5678"}},

{

{

"op":"remove",

"name":"Jane",

"path":"/1"}

"gender":"Female",

]

"phones":{ "mobile": "707-555-9999"}} ]

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

JSON Query using Lambda Operations JsonArray contacts = ...; List femaleNames = contacts.getValuesAs(JsonObject.class).stream() .filter(x->"Female".equals(x.getString("gender"))) .map(x->(x.getString("name")) .collect(Collectors.toList());

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

JSON Query Collecting Results in JsonArray JsonArray contacts = ...; JsonArray femaleNames = contacts.getValuesAs(JsonObject.class).stream() .filter(x->"Female".equals(x.getString("gender"))) .map(x->(x.getString("name")) .collect(JsonCollectors.toJsonArray());

• Using specialized collectors we can retrieve JSON-P API objects like JsonArray that can be directly manipulated further Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Ease of Development and CDI alignment • EJB services outside EJB • Simplified messaging through CDI-based “MDBs” • CDI improvements – Events: async, ordering, range (war, ear, server, cluster) – WebSocket scopes

• Pruning of EJB 2.x client view and IIOP interoperability

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

28

EJB Services outside EJB @ApplicationScoped public class MyScheduledBean { ...

@Schedule(...) public void myScheduledTask() { ... } }

@ApplicationScoped @Stereotype @Retention(RUNTIME) @Target(TYPE) @Schedule(...) public @interface MonthlyTask {}

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

29

Simplified messaging with CDI beans JMS 2.1

• New API to receive messages asynchronously

@RequestScoped

public class MyListenerComponent { @JMSListener(destinationLookup="myQueue") @Transactional public void myCallback(Message message) { ... ... }

• Alternative to message driven beans • Simpler JMS annotations – Usable by any CDI bean – No need for MessageListener implementation

}

• Planning https://java.net/projects/jms-spec/pages/JMS21Planning Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

30

CDI 2.0 • Specification modularization – CDI full with Java EE support, CDI full, CDI light (no support for contexts and AOP)

• Observer ordering – priority annotation

• Asynchronous events • Java SE bootstrap • Improvements for interceptors and decorators – Repeatable annotations for qualifiers and interceptor bindings

• Extension SPI simplification

• EJB annotation usage in CDI beans Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

31

CDI 2.0 Asynchronous events – alternative implementations for sender and receiver? @Inject @CargoInspected Event cargoInspected; ...

public void inspectCargo(TrackingId trackingId) { ... cargoInspected.fireAsync(cargo); }

public void onCargoInspected(

@Observes(async=true) @CargoInspected Cargo cargo) {

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

32

Infrastructure Modernization For Cloud and on-premise

• Java EE Management 2.0 – REST-based APIs for Management and Deployment

• Java EE Security 1.0: enhance portability, flexibility, ease-of-use – Password aliasing – Security interceptor annotations – User management and simple security providers – Role mapping – Authentication – REST authentication (Oauth/OpenID) Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

33

Java EE Management 2.0 • Update of JSR 77 (J2EE Management) – J2EE management is based on EJB2 remoting and CORBA – Released in 2002, last update 2006

• Define RESTful API to replace and augment current Management EJB APIs to manage a Java EE platform – Define CRUD operations for individual managed object – Server-sent events used for event support

• Define RESTful API for application deployment – Focus on simple cases first

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

34

Java EE Security 1.0 Password aliasing

• Standardized syntax for password aliases – Avoids storing passwords in clear text in code, deployment descriptors and files @DataSourceDefinition( name="java:app/MyDataSource", className="com.example.MyDataSource", ... user="duke", password="${ALIAS=dukePassword}")

• Standardized secure credentials archive for bundling alias and password with the application – Used by platform as credential store for resolving alias Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

35

CDI Interceptor for Authorization EL eanbled annotations @IsAuthorized("hasRoles('Manager') && schedule.officeHrs") void transferFunds(); @IsAuthorized("hasRoles('Manager') && hasAttribute('directReports', employee.id)")

double getSalary(long employeeId); @IsAuthorized(ruleSourceName="java:app/payrollAuthRules", rule="report") void displayReport(); Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

36

Java EE Security 1.0 User Management

• Allow application to manage its own user and groups – Without need to access server configuration

• Users stored in application-specified repository (e.g., LDAP) – Simple security providers

• User service manipulates users from user source

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

37

Java EE Security 1.0 Simple security providers @EmbedddedSecurityProvider({ @Credentials(username="reza", password="secret", roles="dad"), @Credentials(username="nicole", password="secret", roles="mom"), @Credentials(username="zehra", password="secret", roles="daughter"), @Credentials(username="xavier", password="secret", roles="son")}) @DatabaseSecurityProvider( lookup="java:global/MyDB", userQuery="SELECT password FROM principals WHERE username=?", rolesQuery="SELECT role FROM roles where username=?", ...) @LdapSecurityProvider(url="...", dnPrefix="...", dnSuffix="...", ...)

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

38

Adopting Java SE 8 • Most of Java SE 8 can already be used with Java EE – GlassFish, WildFly and WebLogic support JDK 8

• Some APIs could adopt features – CompletableFuture – Lambda expressions, streams – Default methods – Repeatable Annotations – Date-Time API/JDBC 4.2

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

Java EE 8 JSR Status Submitted

More To Come

 Java EE 8 Platform

 JCache

 CDI 2.0

 Concurrency Utilities

 JSON Binding 1.0  JAX-RS 2.1  MVC 1.0  Java Servlet 4.0

 WebSockets  JPA  And more to follow…

 JSF 2.3  JMS 2.1  JSON-P 1.1  Java EE Security 1.0  Java EE Management 2.0 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

40

Java EE 8 Roadmap Expert groups up and running (JavaOne)

JSR Submissions

Final Drafts Submitted

Public Review Draft

Proposed Final Draft

Early Drafts

2015

2014

2016

GlassFish 4.1 Open Source Edition

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

Final Release • Reference Implementation/GlassFish 5 Open Source Edition • JavaOne 2016

2017

Continue to participate

Java EE 7

Java EE 8

14 adopted JSRs

New JSRs

19 Java User Groups

New Opportunities

Thank You!

Get Involved!

Participate with us! http://glassfish.org/contribute Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

42

Adopt-a-JSR for Java EE 8 • Grassroots participation to shape Java EE • Launched in Java EE 7 time-frame, key community element for Java EE 8 – 30 Java user groups participating!

https://java.net/projects/adoptajsr Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Java EE 8 JSRs Already Adopted! User Group

Java EE 8.0

CDI 2.0

JSON-B 1.0

JMS 2.1

Servlet 4.0

London Java Community Morocco JUG Egypt JUG Hellenic Java User Group Santa Catarina Java User Group Japan Java User Group

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

JAX-RS 2.1

MVC 1.0

JSF 2.3

Links • Java EE Tutorials – http://docs.oracle.com/javaee/7/tutorial/doc/home.htm

• Java EE Transparent Expert Groups – http://javaee-spec.java.net

• Adopt a JSR – https://java.net/projects/adoptajsr

• The Aquarium Blog – http://blogs.oracle.com/theaquarium

• Java EE 8 reference implementation – http://glassfish.org Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

45

Copyright © 2015 Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal

80