JAVA API FOR XML WEB SERVICES INTRODUCTION TO JAX-WS, THE JAVA API FOR XML BASED WEB SERVICES (SOAP, WSDL)



Similar documents
Developing Java Web Services

ITS. Java WebService. ITS Data-Solutions Pvt Ltd BENEFITS OF ATTENDANCE:

JVA-561. Developing SOAP Web Services in Java

WEB SERVICES. Revised 9/29/2015

Java Web Services Training

Module 13 Implementing Java EE Web Services with JAX-WS

Web Services Technologies Examples from the Mainstream

Developing Web Services Applications

JAVA API FOR XML WEB SERVICES (JAX-WS)

JAX-WS Developer's Guide

Web Services Development for IBM WebSphere Application Server V7.0. Version: Demo. Page <<1/10>>

Web Service Development Using CXF. - Praveen Kumar Jayaram

REST and SOAP Services with Apache CXF

Szolgáltatásorientált rendszerintegráció. WS-* standards

JBoss SOAP Web Services User Guide. Version: M5

Web Services Development In a Java Environment

NetBeans IDE Field Guide

Assessing the usefulness of the WS-I tools for interoperability testing

Web Services in Oracle Fusion Middleware. Raghu Kodali Consulting Product Manager & SOA Evangelist Oracle Fusion Middleware Oracle USA

Middleware and the Internet. Example: Shopping Service. What could be possible? Service Oriented Architecture

Reusing Existing * Java EE Applications from Oracle SOA Suite

Realtests.C questions

Improving performance for security enabled web services. - Dr. Colm Ó héigeartaigh

Middleware and the Internet

Web Services Advanced Topics

SOA Fundamentals For Java Developers. Alexander Ulanov, System Architect Odessa, 30 September 2008

JDeveloper 11g JAX-WS web services:

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR DEPARTMENT OF COMPUTER APPLICATIONS SUBJECT : MC7502 SERVICE ORIENTED ARCHITECTURE

Software Requirement Specification Web Services Security

Grid Computing. Web Services. Explanation (2) Explanation. Grid Computing Fall 2006 Paul A. Farrell 9/12/2006

rpafi/jl open source Apache Axis2 Web Services 2nd Edition using Apache Axis2 Deepal Jayasinghe Create secure, reliable, and easy-to-use web services

Web Service Technologies. Introduction, Composition and Extensions

Chapter 1: Web Services Testing and soapui

Java EE 6 Ce qui vous attends

FUSE-ESB4 An open-source OSGi based platform for EAI and SOA

Creating Web Services in NetBeans

applications. JBoss Enterprise Application Platform

GlassFish. Developing an Application Server in Open Source

Choose an IBM WebSphere Application Server configuration to suit your business needs

WCF WINDOWS COMMUNICATION FOUNDATION OVERVIEW OF WCF, MICROSOFTS UNIFIED COMMUNICATION FRAMEWORK FOR.NET APPLICATIONS

FEATURE MATRIX. ORACLE WEBLOGIC SERVER STANDARD EDITION 11g ORACLE WEBLOGIC SERVER ENTERPRISE EDITION 11g ORACLE WEBLOGIC SUITE 11g

How To Develop A Web Service In A Microsoft J2Ee (Java) 2.5 (Oracle) 2-Year Old (Orcient) 2Dj (Oracles) 2E (Orca) 2Gj (J

Author: Gennaro Frazzingaro Universidad Rey Juan Carlos campus de Mostòles (Madrid) GIA Grupo de Inteligencia Artificial

Building and Using Web Services With JDeveloper 11g

Web Services and their support in Java

Open ESB. Sang Shin Java Technology Evangelist Sun Microsystems, Inc. Raffaele Spazzoli Imola Informatica 1

Service Oriented Computing: SOAP, WSDL and UDDI. Dr. Cristian Mateos Diaz ( ISISTAN - CONICET

Building Web Services with Apache Axis2

Oracle Application Server 10g Web Services Frequently Asked Questions Oct, 2006

SW : : Introduction to Web Services with IBM Rational Application Developer V6

Motivation Definitions EAI Architectures Elements Integration Technologies. Part I. EAI: Foundations, Concepts, and Architectures

STAR Web Services. Quick Start Guide 2011v1

Service Oriented Architecture

Apache CXF Web Services

WA2087 Programming Java SOAP and REST Web Services - WebSphere 8.0 / RAD 8.0. Student Labs. Web Age Solutions Inc.

Oracle WebLogic Server

Comparing Web service development with J2EE and Microsoft.NET

EAI OVERVIEW OF ENTERPRISE APPLICATION INTEGRATION CONCEPTS AND ARCHITECTURES. Enterprise Application Integration. Peter R. Egli INDIGOO.

RPC over XML. Web services with Java. How to install it? Reference implementation. Setting the environment variables. Preparing the system

XML in Programming 2, Web services

Developing Web Services with Apache CXF and Axis2

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

T Network Application Frameworks and XML Web Services and WSDL Tancred Lindholm

An Introduction to Globus Toolkit 3

Consuming and Producing Web Services with Web Tools. Christopher M. Judd. President/Consultant Judd Solutions, LLC

Developing Web Services with Eclipse

Building SOA Applications with JAX-WS, JAX- RS, JAXB, and Ajax

Introduction into Web Services (WS)

Invocación remota (based on M. L. Liu Distributed Computing -- Concepts and Application

A standards-based approach to application integration

How To Create A C++ Web Service

Outline SOA. Properties of SOA. Service 2/19/2016. Definitions. Comparison of component technologies. Definitions Component technologies

Using mobile phones to access Web Services in a secure way. Dan Marinescu

Consuming and Producing Web Services with WST and JST. Christopher M. Judd. President/Consultant Judd Solutions, LLC

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

SOA using Open ESB, BPEL, and NetBeans. Sang Shin Java Technology Evangelist Sun Microsystems, Inc.

Web Services. Distributed Object Systems 11. Web Services, SOAP and NET. Web Applications. Web Services. Web services vs Distributed Objects

Java EE 7: Back-End Server Application Development

WS4D: SOA-Toolkits making embedded systems ready for Web Services

What Is NetBeans? Free and open-source based > Open source since June, 2000 > Large community of users and developers

Learning GlassFish for Tomcat Users

Distribution and Integration Technologies

2. Define Contemporary SOA. Contemporary SOA represents an architecture that promotes service orientation through the use of web services.

This project was supported by Grant No DB-BX-K105 awarded by the Bureau of Justice, Office of Justice Programs in collaboration with the U.S.

An introduction to SOA and the HP NonStop server environment

ActiveVOS Server Architecture. March 2009

Introduction to Oracle WebLogic. Presented by: Fatna Belqasmi, PhD, Researcher at Ericsson

Introduction to WebSphere Process Server and WebSphere Enterprise Service Bus

Web services can convert your existing applications into web applications.

Transcription:

JAX-WS JAX-WS - Java API for XML Web Services JAVA API FOR XML WEB SERVICES INTRODUCTION TO JAX-WS, THE JAVA API FOR XML BASED WEB SERVICES (SOAP, WSDL) Peter R. Egli INDIGOO.COM 1/20

Contents 1. What is JAX-WS? 2. Glassfish = Reference implementation for JAX-WS 3. Glassfish projects, Java packages 4. POJO / Java bean as web service class 5. JAX-WS JavaBeans versus provider endpoint 6. JAX-WS dispatch client versus dynamic client proxy API 7. JAX-WS development / deployment 8. JAXB Binding XML documents to Java objects 9. JAXR JAVA API for XML Registries 10. WSIT Web Service Interoperability Technologies 11. Short comparison of important Java WS stacks 2/20

1. What is JAX-WS? JAX-WS is the core Java web service technology (standard for Java EE): JAX-WS is the standard programming model / API for WS on Java (JAX-WS became a standard part of Java as of version 1.6). JAX-WS is platform independent (many Java platforms like Glassfish, Axis2 or CXF support JAX-WS). Services developed on one platform can be easily ported to another platform. JAX-WS makes use of annotations like @WebService. This provides better scalability (no central deployment descriptor for different WS classes is required). JAX-WS uses the POJO concept (use of plain Java classes to define web service interfaces). JAX-WS replaces / supersedes JAX-RPC (= old Java web services, basically RMI over web service). JAX-WS is more document orientiented instead of RPC-oriented. Glassfish is the JAX-WS reference implementation (RI, see https://jax-ws.java.net/). 3/20

2. Glassfish = Reference implementation for JAX-WS Glassfish: Java EE reference implementation (RI), reference Java application server. Metro: WS stack as part of Glassfish (consists of JAX-WS and WSIT components). JAXB: Data binding (bind objects to XML documents or fragments). SAAJ: SOAP with Attachments API for Java. JAX-WS: Java core web service stack. WSIT: Web Services Interoperability Technologies (enables interop with.net). JAXR: Java API for XML Registries (WS registry). StaX: Streaming API for XML. Details see https://glassfish.java.net/downloads/3.1.1-final.html Glassfish JEE app. server RI WSIT JAX-WS Trans- Security RM actions Metro stack JAX-WS (core WS) JSR-224 Metadata WSDL Policy Jersey (JAX-RS) CORBA Grizzly / COMET OpenMQ JAXR EJB 1) XML JAXB JSR-222 JAXP StaX JSR-173 SAAJ Transports HTTP TCP JMS SMTP 1) Local container only 4/20

3. Glassfish projects, Java packages (selection) Glassfish is developed in various independent projects. Together, they build the Glassfish service platform. Parent project Project Description Java package Glassfish GF-CORBA CORBA com.sun.corba.se.* Glassfish OpenMQ JMS javax.jms.* Glassfish WADL IDL for REST services org.vnet.ws.wadl.* org.vnet.ws.wadl2java.* Glassfish JAX-RS, Jersey (=RI) REST services javax.ws.rs.* jax-ws-xml, jwsdp JAXB Java API for XML Binding javax.xml.bind.* jax-ws-xml, jwsdp JAX-RPC Java API for XML RPC Old Java WS (superseded by JAX-WS) java.xml.rpc.* Metro (Glassfish) JAX-WS Java API for XML Web Services javax.jws.* javax.xml.ws.* Metro (Glassfish) SAAJ SOAP attachments javax.xml.soap.* Metro (Glassfish) WSIT (previously Tango) Web Services Interoperability Technologies (WS-Trust etc.) Various 5/20

4. POJO / Java bean as web service class (1/2) Web services through simple annotations: The programming model of JAX-WS relies on simple annotations. This allows to turn existing business classes (POJOs) into web services with very little effort. Web service endpoints are either explicit or implicit, depending on the definition or absence of a Java interface that defines the web service interface. Implicit SEI (Service Endpoint Interface): Service does not have an explicit service interface, i.e. the class itself is the service interface. @WebService public class HelloWorld { @WebMethod public String sayhello() {...} Through @WebService annotation, the class HelloWorld becomes an SEI (Service Endpoint Interface) and all public methods are exposed. Annotation for individual method to be exposed as a web service method. } public HelloWorld() {...} @PostConstruct public void init() {...} @PreDestroy public void teardown() {...} The SEI implementing class must have a public default ctor. Called by container before the implementing class is called the first time. Called by container before the implementing class goes out of operation. 6/20

4. POJO / Java bean as web service class (2/2) Explicit SEI: The service bean has an associated service endpoint interface (reference to interface). public interface IHello { @WebMethod public String sayhello() {...} } @WebService(endpointInterface=IHello) public class HelloWorld { public String sayhello() {...} } Explicit endpoint interface. Reference to explicit service endpoint interface. 7/20

5. JAX-WS JavaBeans versus provider endpoint (1/3) Web services on the service provider side can be defined at 2 levels: The annotation @WebService is a high-level annotation to turn a POJO into a web service. The @WebServiceProvider is lower-level and gives more control over the web service. Service consumer Service provider Application Application @WebService RPC call (API) Procedure (marshaling) Application @WebServiceProvider SOAP engine SOAP engine HTTP engine HTTP engine 8/20

5. JAX-WS JavaBeans versus provider endpoint (2/3) A. JavaBeans endpoints (@WebService annotation): JavaBeans as endpoints allow to expose Java classes (actually methods) as web services. This hides most of the WS complexity to the programmer. JavaBeans endpoint example: @WebService public class HelloWorld { @WebMethod public String sayhello() {...} } 9/20

5. JAX-WS JavaBeans versus provider endpoint (3/3) B. Provider endpoints (@WebServiceProvider annotation): Provider endpoints are more generic, message-based service implementations. The service operates directly on (SOAP) message level. The service implementation defines 1 generic method "invoke" that accepts a SOAP message and returns a SOAP result. The provider interface allows to operate a web service in payload mode (service method directly receives XML messages). Provider endpoint example: The web service class has only a single method invoke. This method receives the SOAP messages. Decoding of the message takes place in this method. @WebServiceProvider( portname="helloport", servicename="helloservice", targetnamespace="http://helloservice.org/wsdl", wsdllocation="web-inf/wsdl/helloservice.wsdl" ) @BindingType(value="http://schemas.xmlsoap.org/wsdl/soap/http") @ServiceMode(value=javax.xml.ws.Service.Mode.MESSAGE) public class HelloProvider implements Provider<SOAPMessage> { } private static final String helloresponse =... public SOAPMessage invoke(soapmessage req) {... } 10/20

6. JAX-WS dispatch client versus dynamic client proxy API (1/3) Similar to the server APIs, JAX-WS clients may use 2 different APIs for sending web service requests. A dispatch client gives direct access to XML / SOAP messages. A dynamic proxy client provides an RPC-like interface to the client application. Service consumer Service provider Dynamic proxy client API Dispatch client API Application RPC call (API) SOAP engine Application Procedure (marshaling) SOAP engine HTTP engine HTTP engine 11/20

6. JAX-WS dispatch client versus dynamic client proxy API (2/3) A. Dispatch client (dynamic client programming model): The dispatch client has direct access to XML (SOAP) messages. The dispatch client is responsible for creating SOAP messages. It is called dynamic because it constructs SOAP messages at runtime. Dispatch client example (source: axis.apache.org): String endpointurl =...; QName servicename = new QName("http://org/apache/ws/axis2/sample/echo/", "EchoService"); QName portname = new QName("http://org/apache/ws/axis2/sample/echo/", "EchoServicePort"); /** Create a service and add at least one port to it. **/ Service service = Service.create(serviceName); service.addport(portname, SOAPBinding.SOAP11HTTP_BINDING, endpointurl); /** Create a Dispatch instance from a service.**/ Dispatch<SOAPMessage> dispatch = service.createdispatch(portname, SOAPMessage.class, Service.Mode.MESSAGE); /** Create SOAPMessage request message. **/ MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); // Create a message. This example works with the SOAPPART. SOAPMessage request = mf.createmessage(); SOAPPart part = request.getsoappart(); // Obtain the SOAPEnvelope and header and body elements. SOAPEnvelope env = part.getenvelope(); SOAPHeader header = env.getheader(); SOAPBody body = env.getbody(); // Construct the message payload. SOAPElement operation = body.addchildelement("invoke", "ns1", "http://org/apache/ws/axis2/sample/echo/"); SOAPElement value = operation.addchildelement("arg0"); value.addtextnode("ping"); request.savechanges(); /** Invoke the service endpoint. **/ SOAPMessage response = dispatch.invoke(request); 12/20

6. JAX-WS dispatch client versus dynamic client proxy API (3/3) B. Dynamic proxy client (static client programming model): A dynamic proxy client is similar to a stub client in the JAX-RPC programming model (=RPC model). A dynamic proxy client uses a service endpoint interface (SEI) which must be provided. The dynamic proxy client classes are generated at runtime (by the Java dynamic proxy functionality). Dynamic proxy client example: EchoService port = new EchoService().getEchoServicePort(); String echo = port.echo("hello World"); 13/20

7. JAX-WS development / deployment (1/2) 1. Start with POJO / bean class as service class (bottom-up development): Server stub files and (optionally) WSDL files are created from Java class file(s). The deployment descriptor web.xml is optional (JAX-WS defaults are sufficient for many / most applications, "configuration by exception" principle). web.xml (deployment descriptor, optional) *.java javac.exe *.class wsgen.exe Code Code JAXB classes Platform specific packaging and deployment WAR, AAR etc. Annotated Service Endpoint Interface / Implementation (POJO). Portable JAXB classes for marshalling / unmarshalling messages Public methods are web (exposed) methods or use @WebMethod annotation. SEI (Service Endpoint Interface) = Java class with methods that can be called by client. WSDL file Service description as WSDL file 14/20

7. JAX-WS development / deployment (2/2) 2. Start with WSDL file (top-down development): Server stub files are created from an existing WSDL file. web.xml (deployment descriptor, optional) WSDL file wsimport.exe Code Server Code stub classes Platform specific packaging and deployment WAR, AAR etc. 3. Creation of client stub files from a WSDL file (dynamic proxy client): Portable artefacts for client & server: Service class SEI class Exception class JAXB classes for marshalling messages WSDL file wsimport.exe Code client Code stub files 15/20

8. JAXB Binding XML documents to Java objects JAX-WS uses JAXB for the binding between Java objects and XML documents. The binding / JAXB details are hidden from the JAX-WS programmer. Schema bind JAXB JAXB mapped JAXB mapped classes mapped classes classes Relationship between schema, document, Java objects and classes with JAXB: follows Document (XML) unmarshal (validate) Objects Objects Objects instances of marshal (validate) JAXB mapping of XML schema built-in types to Java built-in types (selection): XML schema type xsd:string xsd:integer xsd:int xsd:long xsd:short Java data type java.lang.string java.math.biginteger int long short 16/20

9. JAXR JAVA API for XML Registries JAXR is a uniform and standard API for accessing different kinds of XML registries. XML registries are used for registering (by server / service) and discovering (by client) web services. JAXR follows the well-known pattern in Java with a service provider interface (SPI for registering XML metadata) and a client interface (see also JMS or JNDI). JAXR Client ebxml Provider JAXR API Capability-Specific Interfaces UDDI Provider Other Provider Registry-specific JAXR provider ebxml / SOAP UDDI / SOAP Other ebxml UDDI Other Registries Source: docs.oracle.com 17/20

10. WSIT Web Service Interoperability Technologies (1/2) Interoperability is crucial for web services (web services in general claim platform independence and interoperability). WSIT is the standard Java WS protocol stack beyond basic WS functionality (SOAP, WSDL) to achieve interoperability between Java and.net (for more complex applications that go beyond simple WS requests). JAX-WS defines the WS core stack while WSIT provides many of the WS-* standards required for interoperability. WSIT is an open source project started by Sun Microsystems to promote WS-interoperability with.net 3.0 (WCF). WSIT is bundled inside the Metro WS stack. The Metro stack in turn is bundled inside Glassfish (see Slide 2). WS-I (Web Service Interoperability) defines profiles (sets of WS standards, see www.oasis-ws-i.org/) for which WS stacks can claim compatibility such as: WS-I Basic Profile 1.1: SOAP 1.1 + HTTP 1.1 + WSDL 1.1 WS-I Basic Profile 1.2: SOAP 1.1 + HTTP 1.1 + WSDL 1.1 + WS-Addressing 1.0 + MTOM 1.0 WS-I Simple SOAP Binding Profile 1.0: SOAP 1.1 + HTTP 1.1 + WSDL 1.1 + UDDI WSIT versus WS-I? WS-I defines profiles while WSIT implements them. 18/20

10. WSIT Web Service Interoperability Technologies (2/2) Overview of WS-standards compliance by JAX-WS / Metro-stack and WCF: Standard JAX-WS (Metro@Glassfish) Microsoft WCF Description WS-I Basic Profile Yes (JAX-WS) Yes SOAP 1.1 + HTTP 1.1 + WSDL 1.1. WS-MetadataExchange Yes (WSIT) Yes Exchange of web service meta-data files. WS-Transfer Yes (WSIT) Yes Protocol for accessing XML-representations of WS resources. WS-Policy Yes (WSIT) Yes XML-representations of WS policies (security, QoS). WS-Security Yes (WSIT) Yes Framework protocol for applying security to web services. WS-SecureConversation Yes (WSIT) Yes Protocol for sharing security contexts between sites. WS-Trust Yes (WSIT) Yes Protocol for establishing trust between WS provider and consumer. WS-SecurityPolicy Yes (WSIT) Yes Set of security policy assertions to be used with WS-Policy. WS-ReliableMessaging Yes (WSIT) Yes Protocol for reliable WS message delivery (in-order, exactly-once). WS-RMPolicy Yes (WSIT) Yes XML-representations of WS policies of RM-WS-endpoints. WS-Coordination Yes (WSIT) Yes Protocol for coordinating web service participants (providers, consumers). WS-AtomicTransaction Yes (WSIT) Yes Protocol for atomic transactions with groups of web services. WS-BusinessActivity No Yes (.Net 4.0) Business activity coordination to be used in the WS-Coordination framework. WS-Eventing No No Protocol for subscribe / publish to WS for receiving notifications. WS-Notification No No Protocol for subscribe / publish to topic-based WS for receiving notifications. 19/20

11. Short comparison of important Java WS stacks 1. JAX-WS (Glassfish RI): JAX-WS compliant (the reference implementation defines the standard). Supported by many WS frameworks. 2. Apache CXF framework: Easy to use, slim. 3. Apache Axis2: Features-rich, but also high complexity. Not (fully) JAX-WS compliant (not JAX-WS technology compatibility kit compliant). Support for different XML-Java binding frameworks (XMLBeans etc.). 4. JBoss: Actually uses Glassfish / Metro as WS-stack (http://jbossws.jboss.org/). 5. Spring WS: Contract-first development (first WSDL, then code). Support for different XML-Java binding frameworks (XMLBeans, JiXB etc.). Comparison of Java WS stacks se also http://wiki.apache.org/ws/stackcomparison. 20/20