25
JAX-RS 2.1 AND BEYOND ANDY MCCRIGHT – IBM [email protected] @ANDREWMCCRIGHT

JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

JAX-RS2.1ANDBEYONDANDYMCCRIGHT– IBM

[email protected]

@ANDREWMCCRIGHT

Page 2: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

• What’sInJAX-RS2.1?

• ReactiveClient

• ServerSentEvents

• OtherNewAPIs

• BeyondJAX-RS2.1…

• JAX-RSinJavaSE

• Type-safeClientAPIs

• BetterCDIintegration

Page 3: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

JAX-RSREFRESHER

• JAX-RSprovidesRESTfulservicesviaResourcesandProviders.

• ResourcesimplementthebusinesslogicofaRESTfulrequest.

• Providershandleinfrastructuretasks,likeconvertingHTTPentitydataintoobjectsandvice-versa(MessageBodyReaders/Writers),convertingexceptionsintoHTTPresponses(ExceptionMappers),filteringrequests/responses(Filters),etc.

Page 4: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

JAX-RSREFRESHER

AppendixCfromtheJAX-RS2.1Specification

Page 5: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

REACTIVECLIENT

• Introducesreactiveprogrammingmodel.

• BuiltonJava8’sjava.util.concurrent.CompletionStage

• Allowsmultiplestagestobeinvokedinaparticularorder.

• Allowshandlingofexceptionsin-line.

• Async-ready.

• ThespecallowsforoptionalsupportofotherreactiveplatformssuchasRxJava andFlow– notportable…

Page 6: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

REACTIVE CLIENTDEMO

• Scenario:Userrunsaconsultantshopandneedstoscheduleconsultantsbasedontheirskilllevelsandavailability.

• Twomicroservices apps:

• Skills– organizesexpertsbytheirskill(rated1=lowestto5=highest).

• Scheduling– organizestheschedulesoftheexperts.

• Requirement:Weneedtoleveragethesetwomicroservices toprovideaschedulingmechanismthatfindsthemostqualifiedconsultantavailable.

Page 7: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

SERVERSENTEVENTS

• PartoftheHTML5Spec.

• JAX-RS2.1providesAPIsforSSEserverandclient.

• Canbroadcasteventstoallregisteredclientsorcansendspecificeventstospecificclients.

Page 8: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

SSEDEMO

• Chatapplication– UsersregisterwiththechatroomandcanPOSTmessagesthatarethenbroadcasttoallregisteredclientsintheroom.

Page 9: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

OTHERNEWAPIS

• NewconnectTimeout(…)andreadTimeout(…)methodsinClientAPIallowsmoreportabletimeoutcode.

• New@PATCHannotation.

• Orderingofprovidersisnowpossibleusing@Priorityannotations– notethatproviderswillbeinvokedinascendingorder(i.e.@Priority(5)willbeinvokedbefore@Priority(10)).

• Sub-resourcelocatorscannowreturnClassobjectsinsteadofonlyinstanceobjects.

• JSON-B1.0Providersoutofthebox*- ifthevendorprovidesJSON-B.

Page 10: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

BEYONDJAX-RS2.1…

• Disclaimer:Nopromises!AnythinginthefollowingslidesaresubjecttochangepriortothefinalreleaseofJAX-RSv.Next.

• JavaEE(Oracle)isnowJakartaEE(Eclipse/EE4J)

• ManymembersoftheJAX-RS2.1ExpertGrouparenowcommittersintheJakartaJAX-RSproject.Newmembershavealsojoinedthecommunity.

• Currentreleaseplanning:

• ThefirstreleaseofJakartaEEwillbe100%compatiblewithJavaEE8– thismeansJAX-RS2.1.

• ThenextreleaseofJAX-RSistentativelycalledJAX-RS2.2– somenewfunction,butnobreakingchanges.

• Thenextmajor releaseofJAX-RSistentativelycalled3.0– expectsomebreakingchanges.

Page 11: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

JAX-RSINJAVASE

• Thepopularityof“micro”(MicroProfile,SpringBoot,etc.)isnotlostontheJAX-RScommunity.

• Formanyusecases,aJAX-RSenvironmentwithoutallofthe“extras”inafullprofileapplicationservercanhavealotofbenefits.

• ThisproposalintendstoallowdeveloperstostartandstopaJAX-RSapplicationwithafewkeybootstrapAPIs.

• ConsiderMarkusKarg’s minimalexample(https://gist.github.com/mkarg/a38a68f6025f1ef6ddb4916022bd150d):

• https://github.com/eclipse-ee4j/jaxrs-api/issues/509

Page 12: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

TYPE-SAFECLIENTAPIS

• CurrentJAX-RSClientAPIsareverysimilartolow-levelframeworks– likeApacheCommonsHTTPClient.

• ManyJAX-RSimplementations(CXF,Jersey,RESTEasy,etc.)haveatype-safe,proxy-basedclientAPIthatallowsdeveloperstocodeclientsthatbetterintegratewiththeirbusinesslogic.

• https://github.com/eclipse-ee4j/jaxrs-api/issues/598

• PossiblymovingEclipseMicroProfile RestClienttoJakartaEE…

Page 13: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

TYPE-SAFECLIENTAPIS– THEJAX-RS2.0/2.1WAY

Page 14: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

TYPE-SAFECLIENTAPIS– THEMPRESTCLIENTWAY

Page 15: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

BETTERCDIINTEGRATION

• CurrentlyCDIintegrationinJAX-RS2.1issomewhatlimited– seesection11.2.3.

• DeveloperscanuseinjectionofotherCDI-managedbeansintoresource,providerandapplicationinstances.

• Mostvendorsprovideintegrationaboveandbeyondthespec– forexample,allowingnon-standardlifecycles(i.e.@ApplicationScoped resourceclasses,orper-requestscopedproviders,etc.),butthisisnotstandardized– andthusnotportable.

• JAX-RSsupportsmultipleinjectionmechanisms- @Contextvs@Inject

• https://github.com/eclipse-ee4j/jaxrs-api/issues/569

Page 16: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

BETTERCDIINTEGRATION- PROPOSALS

• InJAX-RS2.2,deprecate@Contextinfavorof@Inject– @Injectdoesnotworkonmethodparameters,sotherecommendationwouldbetoput@Context-basedinjectiontargetsintofields.

•Becomes:

• OtherthingslikeRuntimeDelegate couldalsobecomeCDI-managedbeans.

Page 17: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

BETTERCDIINTEGRATION- PROPOSALS

• Theintentistoremove@ContextasaninjectionmechanisminJAX-RS.Ifwedeprecate@ContextinJAX-RS2.2,expectthatitwillberemovedinJAX-RS3.0.

• Otherpossibilitieswouldbetostandardizenon-defaultlifecycles– allowingresourcestobesingletonsandproviderstobeper-request,etc.

Page 18: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

SUMMARY

• JAX-RS2.1

• ReactiveClient– usesCompletionStage toenablereactiveprogrammingontheclientside.

• ServerSentEvents– pub/subforRESTfulservices.

• Checkthejavadoc foradditionalchanges:https://jax-rs.github.io/apidocs/2.1/

• JAX-RSFuture

• Morecommunityinvolvement– getinvolvedat:https://projects.eclipse.org/proposals/eclipse-project-jax-rs

• Lotsofnewfeaturescoming– staytuned!

Page 19: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

QUESTIONS?

Page 20: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

BACKUPSLIDES

Page 21: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

RXCLIENT– EXAMPLERESOURCE.JAVA

Page 22: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

RXCLIENT – EXAMPLERESOURCE.JAVA (CONTINUED)

Page 23: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

SSE CHATRESOURCE.JAVA

Page 24: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

SSEINDEX.HTML

Page 25: JAX-RS 2.1 AND BEYOND - EclipseCon Europe 2019€¦ · JAX-RS IN JAVA SE • The popularity of “micro” (MicroProfile, Spring Boot, etc.) is not lost on the JAX-RS community. •

SSEINDEX.HTML (CONTINUED)