JAX-RS and Jersey Paul Sandoz

Similar documents
Developing RESTful Web services with JAX-RS. Sabyasachi Ghosh, Senior Application Engneer Oracle

<Insert Picture Here> Exploring Java EE 6 The Programming Model Explained

Short introduction to REST

Session 12. RESTful Services. Lecture Objectives

JAX-RS. Sam Guinea

REST WEB SERVICES IN JAVA EE 6 AND SPRING 3. Srini Penchikala Austin Java User Group March 30, 2010

Developing Applications for the Java EE 7 Platform 9-2

JVA-563. Developing RESTful Services in Java

Java EE 6 - Update Harpreet Singh GlassFish Portfolio Product Manager

Using the Jersey JAX-RS Reference Implementation 11g Release 1 (10.3.6)

Contents at a Glance

COMP REST Programming in Eclipse

SERVICE TECHNOLOGIES

Java EE Architecture, Part One. Java EE architecture, part one 1(104)

Seam 3. Pete Muir JBoss, a Division of Red Hat

5.1 Registration and Configuration

1 Markus Eisele, Insurance - Strategic IT-Architecture

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

J2EE - Version: 25. Developing Enterprise Applications with J2EE Enterprise Technologies

Apache OpenWebBeans and DeltaSpike Deep Dive Mark Struberg Gerhard Petracek

For this week, I recommend studying Chapter 2 of "Beginning Java EE 7".

Apache Wink User Guide

Java SE7 Fundamentals

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

Example jsf-cdi-and-ejb can be browsed at

Developing Applications with Java EE 6 on WebLogic Server 12c

V3 EJB Test One Pager

Developing RESTful Services in Java

Apache Wink 0.1 Feature Set

Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Sun Microsystems. And this is his blog!

Eclipse MicroProfile: Accelerating the adoption of Java Microservices

CO Java EE 7: Back-End Server Application Development

JavaEE.Next(): Java EE 7, 8, and Beyond

APPLICATION SECURITY ENHANCEMENTS IN JAVA EE 6

JSR 365 (CDI 2.0) Review

Hands-on Development of Web Applications with Java EE 6

What is tackled in the Java EE Security API (Java EE 8)

1Z Java EE 6 Web Services Developer Certified Expert Exam Summary Syllabus Questions

CO Java EE 6: Develop Web Services with JAX-WS & JAX-RS

Java EE 7: Back-End Server Application Development

Liberty Right Fit for MicroProfile

Mobile Computing. Logic and data sharing. REST style for web services. Operation verbs. RESTful Services

EJB 3.1 vs Contexts and Dependency Injection (CDI) and Dependency Injection for Java in Java EE 6. Jacek Laskowski.

Java Platform, Enterprise Edition 6 with Extensible GlassFish Application Server v3

Java EE 7 is ready What to do next? Peter Doschkinow Senior Java Architect

Practice 2. SOAP & REST

This is the first part of a multi-article series. For part 2 please see: Dependency Injection in Java EE 6 - Part 2

Keep Learning with Oracle University

Deployment. See Packaging and deployment processes

Oracle 1Z Java EE 7 Application Developer.

Session 13. RESTful Services Part 2. Lecture Objectives

JBoss SOAP Web Services User Guide. Version: M5

CMP 436/774. Introduction to Java Enterprise Edition. Java Enterprise Edition

Enterprise Java in 2012 and Beyond From Java EE 6 To Cloud Computing

Optimizing Enterprise Java for a Microservices Architecture Otávio

Java EE 6 & GlassFish v3 Paving the path for future. Arun Gupta Sun Microsystems, Inc.

SECTION II: JAVA SERVLETS

Refactoring to Seam. NetBeans. Brian Leonard Sun Microsystems, Inc. 14o

JSR-299 (CDI), Weld and the Future of Seam. Dan Allen Principal Software Engineer JBoss by Red Hat

JAX-RS 2.0 with Apache CXF

Oracle Corporation

Oracle Fusion Middleware Developing and Securing RESTful Web Services for Oracle WebLogic Server. 12c ( )

Stateless -Session Bean

[EPUB] JAVA WEB SERVICES LAB MANUAL EBOOK

open source community experience distilled

Fast Track to Java EE 5 with Servlets, JSP & JDBC


Exam Questions 1Z0-419

Courses For Event Java Advanced Summer Training 2018

Concepts: business logic and middleware

GlassFish : From the clustering to the cloud. Fabien LEROY

Chapter 1: First steps with JAX-WS Web Services

CS506 Web Design & Development Final Term Solved MCQs with Reference

PATTERNS & BEST PRACTICES FOR CDI

Introduction to CDI Contexts and Dependency Injection

Lessons learned from real-world deployments of Java EE 7. Arun Gupta, Red

RESTful Java with JAX-RS

Adopt-a-JSR Panel for 16 October 2014

Seam & Web Beans. Pete Muir JBoss, a division of Red Hat.

Enterprise Development

Java EE 6: Develop Business Components with JMS & EJBs

web.xml Deployment Descriptor Elements

Migrating traditional Java EE applications to mobile

Java Training Center, Noida - Java Expert Program

JakartaEE and the road ahead An ASF View. Mark Struberg, RISE GmbH, Apache Software Foundation, INSO TU Wien

Oracle Fusion Middleware

Rest Client for MicroProfile. John D. Ament

Migration Cheat Cheet for Java EE 5 to Java EE 6

Session 8. Reading and Reference. en.wikipedia.org/wiki/list_of_http_headers. en.wikipedia.org/wiki/http_status_codes

Java EE 6: Develop Web Applications with JSF

Meet. Brian Stansberry Principal Software Engineer, Red Hat, Inc. June 10, Friday, June 14, 13

Java EE 7 Recipes for Concurrency. Presented By: Josh Juneau Author and Application Developer

A Gentle Introduction to Java Server Pages

Using SMI-S with the Cloud Data Management Interface Scott Baker September 21th, 2010

Specialized - Mastering JEE 7 Web Application Development

JBoss WS User Guide. Version: CR1

Big Modular Java with Guice

The Next Generation. Prabhat Jha Principal Engineer

Portlet Standard JSR 168 / JSR 286

Improve and Expand JavaServer Faces Technology with JBoss Seam

Transcription:

JAX-RS and Jersey Paul Sandoz JAX-RS co-spec lead and Jersey lead mailto:paul.sandoz@sun.com http://blogs.sun.com/sandoz https://twitter.com/paulsandoz/ 1

Overview Terminology Information & Status Integration with Java EE 6 Q/A 2

REST style Set of constraints you apply to the architecture of a distributed system 3

RESTful Web services REST constraints applied to the Web and construction of web services 4

JAX-RS A Java API for helping build RESTful Web services 5

Jersey The production quality Reference Implementation of JAX-RS... and more 6

JAX-RS: http://jsr311.dev.java.net JAX-RS 1.1 is final and part of EE 6 > Not in Web profile, but included with GlassFish v3 Web profile JCP > http://jcp.org/en/jsr/detail?id=311 API > https://jsr311.dev.java.net/nonav/releases/1.1/index.html Spec > https://jsr311.dev.java.net/nonav/releases/1.1/spec/spec.html JAX-RS 2.0? > Hypermedia, client API 7

Resource classes @Path( root ) public class RootResource { // Per-request scope @Context UriInfo ui; @GET Public String get() { return GET ; @Path( sub-resource ) public SubResource sub() { return new SubResource(); public class SubResource { 8

Jersey: http://jersey.dev.java.net Open source: CDDL/lGPLv2 license Version 1.1.4.1 implements JAX-RS 1.1 > Distributed with GlassFish v3 Version 1.0.3.1 implements JAX-RS 1.0 > Distributed with GlassFish v2.1.1 Stable releases ~ every 6 to 8 weeks > Published to GlassFish update center Support for JAX-RS 1.1 in NetBeans 6.8 Send feedback to > mailto:users@jersey.dev.java.net 9

Integration with Java EE 6 Servlet 3.0 EJB 3.1 Managed beans CDI managed beans 10

Servlet 3.0 integration No Web.xml! 11

Servlet 3.0 integration No Web.xml! Or portable web.xml 12

Before <web-app> <servlet> <servlet-name>jersey Web Application</servlet-name> <servlet-class> com.sun.jersey.spi.container.servlet.servletcontainer </servlet-class> <init-param> <param-name>javax.ws.rs.application</param-name> <param-value>com.foo.myapplication</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>jersey Web Application</servlet-name> <url-pattern>/resources/*</url-pattern> </servlet-mapping> </web-app> 13

Before package com.foo; import javax.ws.rs.core.application; Import java.util.*; public class MyApplication { @Override public Set<Class<?>> getclasses() { return new HashSet<Class<?>( Arrays.asList( AResource.class, AnotherResource.class)); @Path( one ) public class Aresource { @Path( two ) public class AnotherResource { 14

After: no web.xml package com.foo; import javax.ws.rs.applicationpath; import javax.ws.rs.core.application; Import java.util.*; @ApplicationPath("resources") public class MyApplication { @Override public Set<Class<?>> getclasses() { return new HashSet<Class<?>( Arrays.asList( AResource.class, AnotherResource.class)); @Path( one ) public class Aresource { @Path( two ) public class AnotherResource { 15

Register all root resource and provider classes in war package com.foo; import javax.ws.rs.applicationpath; import javax.ws.rs.core.application; Import java.util.*; @ApplicationPath("resources") public class MyApplication { @Path( one ) public class Aresource { @Path( two ) public class AnotherResource { 16

Portable web.xml <web-app> <servlet> <servlet-name>com.foo.myapplication</servlet-name> </servlet> <servlet-mapping> <servlet-name>com.foo.myapplication</servlet-name> <url-pattern>/resources/*</url-pattern> </servlet-mapping> <security-constraint> <web-resource-collection> <web-resource-name>protected</web-resource-name> <url-pattern>/resources/*</url-pattern> <http-method>get</http-method> </web-resource-collection>... </security-constraint> </web-app> 17

EJB 3.1 integration Use stateless or singleton beans in the WAR as resource and provider classes 18

EJB 3.1 integration @Path( stateless ) @Stateless public class MyStatelessRootResource { @Context UriInfo ui; @GET Public String get() { return GET ; @EJB MyStatelessResource subresource; @Path( sub-resource ) public MyStatelessResource sub() { return subresource; @Singleton public class MyStatelessResource { @Context UriInfo ui; 19

Managed beans integration Annotate with @ManagedBean to inject EEbased dependencies (or CDI dependencies, if CDI is enabled) 20

Managed beans integration @Path( root ) @ManagedBean // Instantiated by EE container or CDI container // Managed by JAX-RS container in the per-request scope public class RootResource { @Context UriInfo ui; @Resource(name="pi") double pi; 21

Managed beans integration Require a no arg constructor > Constructor injection is not supported Require empty beans.xml in WEB-INF to enable CDI 22

CDI managed beans integration Annotate with CDI scope annotations, such as @RequestScoped 23

CDI managed beans integration @Path( root ) @ApplicationScoped // Instantiated and managed by the CDI container public class RootResource { @Context UriInfo ui; @Inject double pi; @Inject Provider<SubResource> subresource; @Path( sub-resource ) public SubResource sub() { return subresource.get(); @RequestScoped public class SubResource { @Context UriInfo ui; 24

CDI managed beans integration @Inject does not work with JAX-RS/Jersey artifacts If JSR 330/299 had been around in late 2007 early 2008 then @Context might not exist! A general point on CDI: beware of client proxies and constructor injection @RequestScoped public class Foo { // no arg constructor required for client proxy public Foo() { this.mp = null; private final MyDep mp; @Inject public Foo(MyDep mp) { this.mp = mp; 25

Q&A 26