Presentation is loading. Please wait.

Presentation is loading. Please wait.

What Is New and Noteworthy in Jersey Miroslav Fuksa, Jakub Podlešák Software Developers Oracle, Application Server Group October 1, 2014 Copyright ©

Similar presentations


Presentation on theme: "What Is New and Noteworthy in Jersey Miroslav Fuksa, Jakub Podlešák Software Developers Oracle, Application Server Group October 1, 2014 Copyright ©"— Presentation transcript:

1

2

3 What Is New and Noteworthy in Jersey Miroslav Fuksa, Jakub Podlešák Software Developers Oracle, Application Server Group October 1, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

4 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. 4

5 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Goals of The Presentation To demonstrate some lesser-known features To show you new additions to Jersey project 5

6 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Jersey 2 Primer Jersey 2 provides reference implementation of JAX-RS 2.0 Included in GlassFish 4.x And in WebLogic 12.1.3 (Jersey 2 as a shared library) Provides ouf-the-box support for other containers 2.13 is the actual version (released this Monday) 6

7 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Agenda Async Server-Side Support Reactive/Async Client Security (OAuth 2) Light-weight Container Support Jersey Test Framework (TestNG Support ) Monitoring and Tracing 7

8 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Async Server-side Support 8

9 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. When To Go Async on The Server Side? Resource method processing takes a “long time” – Waiting for other backend resources, i/o, disk, db, … – Blocking i/o selector thread that could be utilized by other connections otherwise From a single user perspective, going from sync to async does not change anything! Async is important when concurrent clients compete for I/O threads 9

10 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Two methods to off-load I/O threads Standard JAX-RS: @Suspended AsyncResponse Jersey’s @ManagedAsync 10

11 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. JAX-RS Standard Way ExecutorService exec = Executors.newCachedThreadPool(); @GET @Path("{id}") public void getSession(@Suspended final AsyncResponse response, @PathParam("id") final String id) { exec.submit(new Runnable(){ public void run() { response.resume(db.get(id)); } }); } 11

12 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. @ManagedAsync @GET @Path("{id}") @ManagedAsync public void getSession(@Suspended final AsyncResponse response, @PathParam("id") final String id) { response.resume(db.get(id)); } 12

13 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Reactive/Async Client 13

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

15 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Example Travel agency – Travel to new destinations, get recommendations, forecast and price calculation Orchestration layer with Jersey client 15

16 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16 Orchestration layer (web app with Jersey client) Visited location Recommended locations Forecast calculation Price calculation Mobile app / Web app

17 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17 Visited Recommended destination Price calculation Forecast Recommendations Agent Response Request

18 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Reactive Approach RxJava – Observable Java 8 – CompletionStage and CompletableFuture JSR166e – CompletableFuture (JDK6, JDK7) Guava – ListenableFuture and Futures Libraries 18

19 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Resources JAX-RS Client API – https://jax-rs-spec.java.net/nonav/2.0/apidocs/overview-summary.html https://jax-rs-spec.java.net/nonav/2.0/apidocs/overview-summary.html – https://jersey.java.net/documentation/latest/client.html https://jersey.java.net/documentation/latest/client.html Jersey Rx Client – https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client – https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client-guava https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client-guava – https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client-java8 https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client-java8 – https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client-jsr166e https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client-jsr166e – https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client-rxjava https://github.com/jersey/jersey/tree/master/incubator/rx/rx-client-rxjava JAX-RS and Jersey 19

20 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Resources 3 rd party libraries – https://code.google.com/p/guava-libraries/ https://code.google.com/p/guava-libraries/ – https://github.com/ReactiveX/RxJava https://github.com/ReactiveX/RxJava – http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html – http://gee.cs.oswego.edu/dl/concurrency-interest/index.html http://gee.cs.oswego.edu/dl/concurrency-interest/index.html Example (JDK7) – https://github.com/jersey/jersey/tree/master/examples/rx-client-webapp https://github.com/jersey/jersey/tree/master/examples/rx-client-webapp Netflix blog post about RxJava – http://techblog.netflix.com/2013/02/rxjava-netflix-api.html http://techblog.netflix.com/2013/02/rxjava-netflix-api.html Example and Libraries 20

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

22 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. OAuth: introduction username/password Consumer Service Provider Resource owner username/password ?

23 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. OAuth 2: Authorization Code Grant Flow 1 Authorization Request 2 Resource owner authorization 3 Authorization Response 4 Access Token 5 Refreshing Token 1 2 3 4 Consumer Service Provider Resource owner 5, 6, …

24 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. OAuth 2: Authenticated Requests Access Token Consumer Service Provider Resource owner GET /api/students/mfuksa HTTP/1.1 User-Agent: curl/7.30.0 Host: example-university.com Accept: application/json Authorization: bearer jkr3ljkh3jk

25 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. OAuth support in Jersey OAuth OAuth 1 – Published in 2010 – Signatures added to requests (HMAC-SHA1, RSA-SHA1) based on secret keys OAuth 2 – Published in 2012 – Not backward compatible – Easier for implementation – OpenID connect 25

26 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. OAuth support in Jersey Jersey and OAuth OAuth in Jersey – OAuth 1 (including 2-legged OAuth support) Client Server – OAuth 2 (Authorization Code Grant Flow) Client Server [in progress] 26

27 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. OAuth support in Jersey Jersey client 27 OAuth2ClientSupport OAuth2CodeGrantFlow Authentication Feature String start(); TokenResult finish(); Client Request/Response Filter (Access Token) Registers Access Token User Authorization Authorization Flow tool Authenticated requests No Access Token yet

28 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. OAuth: demo Consumer Service Provider Resource owner Jersey sample oauth2-client-google-webapp Google APIs Access Token

29 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Jersey Test Framework 29

30 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Jersey Test Framework Based on JUnit Support for TestNG available Multiple container support – Grizzly – In memory – Java SE Http Server – Jetty – External container support 30

31 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. External Test Container You can test any (already running) REST application No need to have Jersey on the other side Use the following parameters: mvn test \ -Djersey.config.test.container.factory=org.glassfish.jersey.test.external.ExternalTestContainerFactory \ -Djersey.test.host=localhost -Djersey.config.test.container.port=8080 31

32 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. TestNG Support Predefined test types – JerseyTestNg.ContainerPerClassTest – JerseyTestNg.ContainerPerMethodTest Extend JerseyTestNg to define your own strategy 32

33 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Lightweight Container Support 33

34 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Grizzly HTTP Server Support URI AppURI = URI.create("http://localhost:8080/user-management"); HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer( AppURI, new JaxRsApplication()); 34

35 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Grizzly HTTP Server Support – Thread Pool Config HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(AppURI, new JaxRsApplication(), false); NetworkListener grizzlyListener = httpServer.getListener("grizzly"); grizzlyListener.getTransport().setSelectorRunnersCount(4); grizzlyListener.getTransport().setWorkerThreadPoolConfig( ThreadPoolConfig.defaultConfig().setCorePoolSize(16).setMaxPoolSize(16)); httpServer.start(); 35

36 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Other supported containers Simple HTTP Server Jetty HTTP Container (Jetty Server Handler) Java SE HTTP Server (HttpHandler) Other containers could be plugged in via org.glassfish.jersey.server.spi.ContainerProvider SPI 36

37 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Monitoring And Tracing 37

38 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Monitoring and Tracing of Jersey applications Default settings – Log level to INFO Jersey does not log exceptions thrown from request processing by default (FINE level) – No tracing – No monitoring 38

39 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Monitoring and Tracing of Jersey applications Logging How to change log level – JDK logging – Add jdk.logging properties – Define path to the logging.properties file as env variable java.util.logging.config.file logging.properties: 39 #All attributes details handlers=java.util.logging.ConsoleHandler java.util.logging.ConsoleHandler.level=FINE java.util.logging.SimpleFormatter.format=%4$-7s [%3$s] %5$s%6$s%n #All log level details.level=INFO org.glassfish.jersey.level=FINE org.glassfish.jersey.tracing.level=FINE

40 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Monitoring and Tracing of Jersey applications Tracing Helps to answer questions: – Why my Message Body Writer was not used? – Which Filters and Interceptors were used? – What takes too long in the processing? – Why the resource method was not matched? Levels of tracing – SUMMARY, TRACE, VERBOSE Modes – log file, HTTP response headers 40

41 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Monitoring and Tracing of Jersey applications Monitoring Event listeners – Application events (start, reload, stop) – Request events (method started, exception mapped, …) Monitoring statistics – Contains time and application statistics – Inject statistics into your resources, providers – Expose statistics as MBeans 41

42 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Q/A Visit http://jersey.java.net/ for more details!http://jersey.java.net/

43 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. THANK YOU!


Download ppt "What Is New and Noteworthy in Jersey Miroslav Fuksa, Jakub Podlešák Software Developers Oracle, Application Server Group October 1, 2014 Copyright ©"

Similar presentations


Ads by Google