Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
JAX-WS 2.x andWSIT (Project Tango)
Alexis Moussine-PouchkineSun Microsystems, Inc.
2
Agenda
• JAX-WS basics> Architecture> Annotation based programing model
• More advanced JAX-WS topics> Handlers> Dispatch / Provider
• WSIT (Project Tango)> Web Services Interop Technologies
3
JAX-WS definition
• New, easy-to-use Web Services API• Successor to JAX-RPC 1.x• JAX-WS 2.0 Part of Java EE 5• POJO – Plain Old Java Objects• Descriptor-free programing model• Layered architecture• Transport and Protocol independence• Integrated use of JAXB 2.0• JAX-WS 2.0 also part of Java SE 6
4
Standards
• JAX-WS Standards> SOAP 1.1/1.2> WSDL 1.1> WS-I Basic Profile (BP) 1.x> MTOM, ...
• Foundation for full WS-* compliant stack> WSIT / Project Tango> Tested interoperability with .Net 3.0's WCF
(Windows Communication Foundation)
5
JAX-WS 2.1 Layered Architecture
Application Logic
Strongly TypedAnnotated Classes
Messaging LayerDispatch / Provider API
6
Server-side Programming Model
• Starting from a POJO> Write a POJO implementing the service> Add @WebService annotation> Build and deploy
>WSDL file generated automatically
• Starting from a WSDL file> Generate implementation> Implement Server Endpoint Interface> Build and deploy
7
JAX-WS Web Service Implementation
package endpoint;
import javax.jws.WebService;
@WebServicepublic class Bonjour {
public String ditBonjour(String nom) {return "Bonjour " + nom;
}
}
Application Logic
Annotated Classes
Dispatch / Provider
8
How simple did it get?
• Public methods become web service operations• Default values for service name, etc.• WSDL generated automatically @
http://host/webcontext/Bonjour?wsdl
package endpoint;
import javax.jws.WebService;
@WebServicepublic class Bonjour {
public String ditBonjour(String nom) {return "Bonjour " + nom;
}
}
9
Transactional Web Service
package endpoint;
import javax.jws.WebService;import javax.ejb.Stateless;
@WebService@Statelesspublic class Bonjour {
public String ditBonjour(String name) {return "Bonjour " + name;
}
}
10
Client-side Programming Model
wsimport http://host/webcontext/Bonjour?wsdl
• No factories yet the code is fully portable• XML is completely hidden from programmer
BonjourService service = new BonjourService();
Bonjour port = service.getBonjourPort();
String nom = "Peter";
String result = port.ditBonjour(nom);
11
Demo
12
Web Service reference injection
@Stateless
public class MySessionBean implements MySessionLocal {
@WebServiceRef
private BonjourService service;
public MySessionBean() {
client.Bonjour port = service.getBonjourPort();
String nom = "Peter";
String result = port.ditBonjour(nom);
System.out.println("Result = "+result);
}
}
13
Finer-grained Annotation Attributes
@WebService(serviceName = "BonjourService", portName = "BonjourPort",endpointInterface = "Bonjour",targetNamespace = "http://endpoint/", wsdlLocation = ".../BonjourService.wsdl")
public class Bonjour {
@WebMethod(action="sayHello", operationName="OpName")
public String ditBonjour (@WebParam(name = "name") String nom) {
return "Bonjour " + name;
}
}
14
JAX-WS Handlers
• Protocol Handler> May change protocol specifics> Corner cases or specific protocol (profile)
• Logical/Message handler> Protocol agnostic> Used to access the message payload
• Chaining of handlers is possible
15
Logical/Message Handler
public class MessageHandler implements SOAPHandler<SOAPMessageContext> {
public boolean handleMessage ( SOAPMessageContext messageContext ) { SOAPMessage msg = messageContext.getMessage(); ..... return true; } public Set<QName> getHeaders() { ... } public boolean handleFault ( SOAPMessageContext messageContext ) { ... } public void close(MessageContext context) { ... }}
chaining
16
Messaging Layer
• Use-cases> Dynamic Client (management console)> Dynamic Server (gateway)> Protocol with no established service
description (RESTful Web Services)
• Server-side Provider<T>> Source for any XML messages> DataSource for MIME or binary data> SOAPMessage for SOAP-based services
• Client-side Dispatch<T>> Future<?> invokeAsync (T message, AsyncHandler<T> handler)
• More Control comes at a complexity cost
Application Logic
Annotated Classes
Dispatch / Provider
17
Web Services Recommendations
• Control your environment when possible> Use Document/Literal
>The solution going forward for interop across WS Stacks>JAX-WS 2.x does not support RPC/Encoded
> Latest “compatible” version of Web services toolkits>Things change with point releases
> Debugging, tracing and logging>Use tools to their full extent
> Thinking about exceptions>Use SOAP Fault to describe error
18
JAX-WS Summary
• Platform for WS-I BP 1.1-based WS• Annotations reduce need for descriptors• Clean integration with JAXB• Support for traditional and RESTful WS• Fully integrated into NetBeans• JAX-WS part of Java EE 5 and Java SE 6 platforms
19
What is WSIT?
• Web Services Interoperability Technologies> Also known as “Project Tango”> Build as an extension of JAX-WS 2.x
• Goals:> Implementation of WS-* specifications> Interoperability with Microsoft Windows
Communication Foundation(WCF, a .NET 3.0 component)
> Foundation for building SOA
20
Web Services Stack
21
Optimizing Communication
• Wire format optimization > MTOM/XOP (W3C)
>Avoids large binary base64 encoding>Uses MIME attachments for binary data>More interoperable
> FastInfoset (ITU-T/ISO)>Encode complete XML infosets in binary>Parsing performance: 3-10X>Compaction performance: 50% on average>Better performance
• Transparent to application
22
Optimizing Communication
• Security optimization (WS-SecureConversation)• Establish shared context on multi-message
exchange• Use context to generate derived keys on
subsequent messages• Increases security and performance• Transparent to application
23
WS-ReliableMessaging
• Before WS-ReliableMessaging:> Reliable protocols based on TCP> Point-to-point> Done at the application level
• Bring reliability to SOAP (protocol) layer• Recover from lost/mis-ordered messages• Enable use of alternate transports (i.e., non-TCP/IP)• Transparent to application
24
WS-AtomicTransaction
• Uses WS-Coordination• All operations in TX boundary succeed or rollback• New to Web Services • Same as EJB/RMI-IIOP TX
25
Transactions in Action
@j avax. j ws. WebServi ce @j avax. ej b. St at el ess @j avax. ej b. Transact i onManagement ( CONTAI NER) publ i c cl ass Wi rer {
@j avax. j ws. WebMet hod @j avax. ej b. Transact i onAt t ri but e( REQUI RED) voi d wi reFunds( . . . ) t hrows . . . { websrvc1. wi t hdrawFromBankX( . . . ) ; websrvc2. deposi t I nt oBankY( . . . ) ; } }
26
WS-Trust
• Define additional primitives and extensions on WS-Security
• Issuing, renewing, validating security tokens• Establish and broker trust relationships• Mutual trust between heterogeneous trust authorities• Transparent to application
27
Web Services Stack
28
WSIT Programming Model
• No runtime APIs for WSIT• Developer uses JAX-WS and EJB APIs• WSDL contains WS-Policy metadata
> Control use of WSIT runtime> Enables portable dynamic negotiation using WS-
MetadataExchange> WS-Policy can be generated using NetBeans WSIT
module> Also available as client WSIT config file
29
Demo
30
JAX-WSjax-ws.dev.java.net
WSIT (whiz-it)wsit.dev.java.net
WSIT NetBeans Modulewebsvc.netbeans.org/wsit
31
“The Clear Choice”
See website for latest stats
Project GlassFish v2
Simplifying Java application Development with Java EE 5 technologies
Includes JWSDP, EJB 3.0, JSF 1.2, JAX-WS and JAXB 2.0
Supports > 20 frameworks and apps
Included in Sun Java System Application Server 9.x
Free to download and free to deploy
Over 1800 members and 300,000 downloads
Integrated with NetBeans and other IDEs
http://glassfish.java.net
32
Summary
• JAX-WS 2.x is easier to use and more powerful than its predecessor JAX-RPC 1.1
• JAX-WS part of the Java EE 5 and Java SE 6 platforms• Layered design hides the complexity• Extensible at the protocol and transport level• Fully interoperable with other WS-* stacks using WSIT• Programming model ranges from simple to flexible
JAX-WS 2.x andWSIT (Project Tango)
Alexis Moussine-Pouchkinehttp://blogs.sun.com/[email protected]