WebLogic Developer Webcast 4: RESTful Services with JAX-RS, JQuery and JSF 2.0
-
Upload
jeffrey-west -
Category
Documents
-
view
4.550 -
download
0
Transcript of WebLogic Developer Webcast 4: RESTful Services with JAX-RS, JQuery and JSF 2.0
1
<Insert Picture Here>
RESTful Services with JAX-RS, JQuery Bonus Content: JSF 2.0
Jeffrey WestApplication Grid Product Management
3
Questions & Discussion
4
<Insert Picture Here>
Program Agenda
JAX-RS / JQuery• JAX-RS Introduction & Overview• JAX-RS vs SOAP• JAX-RS WebLogic Configuration• JAX-RS Code Review• JQuery Application Demo• JQuery Code Review
JSF 2.0• JSF 2.0 Application Demo• JSF 2.0 Code Review
5
JAX-RS(Jersey) Programming Model
Protocol (REST/HTTP)
Server SideRuntime System
JAX-RS API
Client sideRuntime System
Stub
Service Endpoint
WADL
WADL<->Java Mapping
Dispatch
Container
Service Client
Transport
Resource
JAX-RS API
6
REST – Representational State Transfer
• JSR-311: JAX-RS
• Exposes named RESOURCES which represent DATA– Resource: POJO
– URI path template
– ID
• Uses simple Nouns (Resources) and verbs (HTTP Methods)– GET/PUT/POST/DELETE
• Emphasis on simple, stateless point-to-point communication over HTTP
• Supports multiple data formats– JSON/XML/TEXT/XHTML
– Runtime Content Negotiation
• Annotation-driven• @Path
• @Produces/Consumes
• @HEAD/PathParam/QueryParam
• @GET/POST/PUT/DELETE
7
WADL - Example<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://research.sun.com/wadl/2006/10">
<doc xmlns:jersey="http://jersey.dev.java.net/" jersey:generatedBy="Jersey: 1.1.2-ea-SNAPSHOT 07/28/2009 04:05 PM"/>
<resources base="http://localhost:7001/HelloRS"> <resource path="/helloworld"> <method name="GET" id="getClichedMessage"> <response> <representation mediaType="text/plain"/>
</response> </method> </resource> </resources></application>
WADL URL: http://host:port/root_context/application_path/application.wadl
8
Example (Resource class)
@Path("widgets")@Produces("application/xml, application/json")public class WidgetsResource { @GET public WidgetsRepresentation getWidgetList() { ... }
@GET @Path("{id}") public WidgetRespresentation getWidget( @PathParam("id") String widgetId) { ... }}
9
REST vs. SOAP
10
SOAP – Simple Object Access Protocol
• Exposes OPERATIONS that implement/represent LOGIC
• Provides loose coupling for integrating diverse systems
• Designed for distributed computing
• Designed to be extensible – WS-*
• Standard error messaging – SOAP faults with standard
Code/Subcode for error types
• Aligns with Enterprise Application needs and goals– Supports other transport protocols than HTTP – SMTP, JMS
– Supports enterprise security with WS-Security
– Supports language neutrality
– Supports ACID, Atomic transactions with WS-AT
– Supports Reliable Messaging with WS-RM
– Easy governance with strong typing
– Broad Development Tools support
11
REST vs. SOAP
REST
• Exposes RESOURCES which
represent DATA
• Uses HTTP Verbs
(GET/POST/DELETE)
• Emphasis on simple point-to-
point communication over HTTP
• Supports multiple data formats
• Emphasizes stateless
communication
SOAP
• Exposes OPERATIONS which
represent LOGIC
• Uses HTTP POST
• Emphasis on loosely coupled
distributed messaging
• Supports only XML (and
attachments)
• Supports stateless and
stateful/conversational operations
• Supports asynchronous
messaging
• Strong Typing
12
REST is better than SOAP!
• REST can be consumed by any client, even a web browser with Ajax and Javascript• REST is lightweight– REST doesn’t require XML parsing– REST consumes less bandwidth – doesn’t require a SOAP
header for every message
• SOAP is OLD! All the ‘cool kids’ are using REST!– Twitter, Google, Flickr
• I can learn to use REST very quickly– It’s just nouns and verbs, how hard can it be?
• REST is SAFE!– Aren’t all ‘GET’ operations safe?
13
SOAP is better than REST!
• Building a client for REST can be challenging– I can easily generate client-side artifacts from a WSDL
– I don’t want to write raw HTTP calls
– I don’t want to look at the HTTP response code for success/failure – I want to use my own exception
types and codes
– Many IDE’s support SOAP development – both client and server
• REST only supports HTTP/HTTPS– HTTP is synchronous and in order to scale I need to be able to have asynchronous messaging
• REST is not secure– Parameters as part of the URI
– No support for acquiring tokens
• RESTful services have no contract– I have a WADL that specifies URL’s but what about schemas for object definition
• REST is not reliable– I have to handle failures with retries – no Reliable Messaging
• REST can’t be governed– How do I know who is consuming my services without a Service Registry?
– How do I discover RESTful services?
14
Both SOAP and REST have their rightful places
REST
• Good for:– Web Services– Limited bandwidth (smaller
message size)– Limited resources (no xml
parsing required) – Exposing data over the
Internet– Combining content from many
different sources in a web browser
SOAP
• Good for:– Enterprise services• High Reliability with WS-RM• Transactions with WS-AT• Security with WS-Security
– Asynchronous processing– Contract-first development– Stateful /conversational
operations– Standards support,
interoperability with business applications
– Tooling Support
15
Oracle Parcel Service
16
Oracle Parcel Service
17
JQuery
• Client Side JavaScript designed to simplify JavaScript and create powerful & dynamic websites• Eases the:– Navigation of HTML documents– Queries to select DOM elements– Creation of Animations– Handling of Events– Development of AJAX based applications (which are aligned
with consuming RESTful services)
• JQuery is one of the most popular JavaScript libraries uses today: http://trends.builtwith.com/javascript/JQuery• Free, open-source MIT- and GNU-licensed
18
JSF 2.0
• Great Blog Post:
http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/#ajax
• Annotation-Driven– Managed Bean Annotations
– Converter Annotations
• Composite Components– Not required: UIComponent, Renderer, faces-config.xml
• Ajax support
• Navigation– Implicit Navigation
– Conditional Navigation
• Project Stage:– ‘Development’ provides more detailed error messaging (not just HTTP 500)
• Resource Libraries Loading– ‘Libraries’ for CSS, Images, Etc
19
PrimeFaces – www.primefaces.org
• “PrimeFaces is a lightweight open source component suite for Java Server Faces 2.0 featuring 100+ rich set of JSF components”• Easy to use, good looking components• Multiple themes