You are on page 1of 92

Technology Practices Group Java Competency Framework

"Incubate, Nurture and Deploy Technology Experts Innovate, Build and Deliver Technology Solutions

TPG Confidential

Introduction
Business Unit Group Practice Sub-Practices Initiative Competency Level Experience Level Pre-Requisite Version Author Total number of slides Duration of learning BFSI Technology Practices Group Java Practice Java CoE technologies Competency Framework

2.3 [Level 4] 2-3 Years


Application Server fundamentals, XML,Java programming

1.0 Java TPG 92 4 TPG Confidential Hours including coding and exercise2

Agenda
SOA Introduction & Architecture Web Services Introduction & Architecture Web Services Type Introduction to SOAP Introduction to WSDL

Introduction to UDDI
Introduction to Java WS

Principles of Service Orientation

SOA - Definition
The policies, practices and frameworks

that enable application functionality to be provided and

consumed as sets of services

published at a granularity relevant to the service consumer,

which are abstracted away from the implementation

using a single, standards based form of interface.

SOA Defined..
a service?
service orientation? A way of integrating your business as linked services and the outcomes that they bring

A repeatable business task e.g., check customer credit; open new account

service oriented architecture (SOA)?

a composite application?

An IT architectural style that supports service orientation

A set of related & integrated services that support a business process built on an SOA
More

Principles of Service Orientation - Architecture


First Order Concept: Services are an independent, first order concept Loosely Coupled: Abstracted: Services are independent of a specific software implementation Platform Independent: Services are delivered in a platform independent technology Designed and built for Agility: Services should incorporate agility into their design, not just use loosely coupled technology. Articulating: Services should be designed as points of flexibility across functional boundaries and technology layers Meaningful: Services should be delivered at a level of granularity and abstraction that is meaningful to the service consumer. Contract-Based: Services should use a design by contract approach to ensure that all participants are aware of their precise obligations when providing or consuming the Service Standards-Based: Services should comply with appropriate standards for both technology and business domains Discoverable: Services should be published in a manner by which they can be discovered and consumed without intervention of the provider

Principles of Service Orientation - Process


Federation: The SOA is a collaboration of independent components, that provide services according to contractual obligations Traceability: Service should be visible throughout life cycle, from business perspective to deployed software service Alignment of Business and IT: The SOP should ensure clear alignment and mapping between the business service, and the software service Evolutionary: SOP should be an agile process that facilitates continuous change Managed: Services should be managed as an asset throughout the service life cycle Application Neutral: The concept of SOP and SOA is applicable to all classes of interoperability

What are Services? (Technical definition)

Contracted interfaces to software functionality and data that communicate via messages Technically, a Service interface

Characteristics of Services

Services are loosely coupled making a change to a Service provider does not mandate changing any Service consumers. Business processes are composed of Services, and are in turn exposed as Services. Services are policy-driven business users can change how a Service behaves. Systems are inherently integrated by virtue of composable Services not through layers of middleware. Services leverage legacy systems SOA does not mandate replacement of runtime infrastructure, but enable migration when needed. In SOA, metadata control how the system behaves instead of code business logic trumps application logic. In SOA, its the contracted interface that matters, not the underlying runtime environment.

Service Oriented Architecture (SOA)

Architectural Scope

Some architecture is always required Focus shifts to the interfaces as scope increases How do the parts connect Role of the architect depends on scope Am I designing the building? Only care about my building External interfaces are a given cant change Or the city plan? What should the interfaces be? Need wide agreement Dont design every single building

Architecture Layers
Business Process Layer Cross Functional End-toend Sales Order Process Service Layer How do you connect sales to customers?

Product Sales Employee


Finance People Soft SAP Outlook

Customer

Dir

Siebel

Application Layer Applications, Components, Software How do you connect SAP to Siebel? Technology Layer Hardware, Network How do you connect J2EE to .NET?

Linux

MQ OS/390

.NET

J2EE

Unix

DB2

Principle Services are a First Order Concept


Services are an independent, first order concept A Service provides a view of a functional capability that is consistent across many use cases. The Service view is common to business requirements, design, deployment, assets and configured resources. A software Service might be related to a functional interface, but should not be taken as a synonym for interface. This applies to both the Business Service and Software Service. This enables: Improved alignment of business to software Service in comparison to mapping to functional interfaces A more abstract view to be taken of the service Complex mappings of software service to functional interface (e.g. many to many) Service treatment as an asset and resource

Types of Service
Business Product Supports Business Process

Business Service

Business
Implements Application Software Service

Executes
Deployment

Software Service

Types of Service - Example


Vehicle Insurance Supports Vehicle Insurance Sales

Pay as you drive

Business
Implements Application Register Journey

Executes Deployment http://paydins.com/regjourney

Service Management

Service Providers Who is allowed in? Am I meeting Service Level Agreements? Who will get the bill? How do we route requests to different implementations Service Consumers Who used the service? Are Service Level Agreements being met? Which budget holder will pay? How do we route requests to different Service Providers The problem is the same and the solution should be symmetrical
Consuming Application Consuming Application Consuming Application Web Service Service Implementation Services Manager Service Implementation Service Implementation

C O N S U M E R

Services Manager

Web Service

Web Service

P R O V I D E R

What are Web Services?


A Web service is a software system identified by a URI whose public interfaces and bindings are defined and described using XML. Its definition can be discovered by other software systems. These systems may then interact with the Web service in a manner prescribed by its definition, using XML-based messages conveyed by Internet protocols.

- World Wide Web Consortium (W3C)

What are Web Services?


Service Consumer

Service Intermediary

Service Provider

Service Request

Service

Standards based protocols to describe


Procurement System
Message Services

format and Endpoints and Routing

Sales System

Addressing

J2EE

Secure,

Reliable Transactions Process Orchestration and Discovery

.NET

Business

Publication

Foundation for Web Services

Publish, Find, Use Services:


Formal Service Descriptions: Service Interactions: Universal Data Format:

UDDI
WSDL SOAP XML

Ubiquitous Communications: Internet

Summary

SOA is more than Web Services Service is the important concept, not Web Service SOA is not just a wiring diagram Services AND Components are required to fully deliver IT and Business Agility Component Based Service Engineering (CBSE) Service Orientation A set of principles and policies An approach Consider Service across the whole lifecycle, not just deployment Follow the Principles of Service Orientation Comprehend Agility at all stages Analysis, Design, Build, Deployment

Introduction to SOAP

Introduction to SOAP
SOAP SOAP SOAP SOAP SOAP SOAP SOAP SOAP SOAP SOAP SOAP stands for Simple Object Access Protocol is a communication protocol is for communication between applications is a format for sending messages is designed to communicate via Internet is platform independent is language independent is based on XML is simple and extensible allows you to get around firewalls will be developed as a W3C standard

Why SOAP? Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA, but HTTP was not designed for this. RPC represents a compatibility and security problem; firewalls and proxy servers will normally block this kind of traffic. A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers and servers. SOAP was created to accomplish this. SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.

XML Messaging Using SOAP

1. 2. 3. 4.

A SOAP client formats a message in XML including a SOAP envelope element describing the message The client sends the message to a SOAP server in the body of an HTTP request The server determines whether the message is valid and supported The server formats its response in XML and sends it to the client in the body of an HTTP response

What is a soap message


A SOAP message is an ordinary XML document containing the following elements: A required Envelope element that identifies the XML document as a SOAP message An optional Header element that contains header information A required Body element that contains call and response information An optional Fault element that provides information about errors that occurred while processing the message All the elements above are declared in the default namespace for the SOAP envelope:
Message Representation
<SOAP-ENV:Envelope xmlns:SOAP-ENV="SoapEnvelopeURI" SOAP-ENV:encodingStyle="SoapEncodingURI"> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="ServiceURI"> <tickerSymbol>SUNW</tickerSymbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

SOAP Message Anatomy

Syntax Rules
Here are some important syntax rules:

A A A A A

SOAP SOAP SOAP SOAP SOAP

message message message message message

MUST be encoded using XML MUST use the SOAP Envelope namespace MUST use the SOAP Encoding namespace must NOT contain a DTD reference must NOT contain XML Processing Instructions

SOAP Message Components

Envelope (required) Contains Header and Body Defines namespaces (optional) Declares encoding rules (optional) Header (optional) Contains metadata entries about message a la HTTP headers Specifies which entries must be understood and by which target actor in chain of recipients

SOAP Message Components

Body (required) Contains application-specific message May be encoded variously Fault element (optional) Contained in Body Describes error class (version mismatch, headers not understood, client error, server error) Extensible, hierarchical fault codes, e.g. Server.Availability.NotAvailable

Example SOAP Message


<SOAP-ENV:Envelope> <SOAP-ENV:Header> <lib:PatronID SOAP-ENV:mustUnderstand=1> 007 </lib:PatronID> </SOAP-ENV:Header> <SOAP-ENV:Body> <lib:Checkout> <callNo>435.33</callNo> </lib:Checkout> </SOAP-ENV:Body> </SOAP-ENV:Envelope> header

body

Why Not Just Put Everything in the Header?

The Header is optional SOAP specializations for RPC require using the body to pass parameters and results (well get to that later) Otherwise, no reason The SOAP spec notes that a body entry is semantically-equivalent to an optional header entry (with mustUnderstand = 0)

Encoding Data in SOAP

SOAP permits arbitrary encoding styles and defines a default encoding style Based on XML-Schema Supports data types All built-in XML-Schema types (e.g. string, float, integer, date, IDREF) Derived types: enumerations, arrays, structs, generic compound types

Encoding Data in SOAP: accessors

Typed elements are called accessors Accessor types are specified in externally-referenced XML-Schema definitions Or with the xsi:type attribute, e.g. <a:uid xsi:type=xsd:integer> 4737 </a:uid>

Encoding Data in SOAP: structs

Structs are simple compound types consisting of uniquely-named accessors, e.g.


<naut:Ship> <name>Titanic</name> <length>882</length> <height>104</height> <weight>46,328 tons</weight> </naut:Ship>

Encoding Data in SOAP: arrays

Arrays can be built of any type, e.g.


<SOAP-ENC:Array SOAP-ENC:arrayType="phNo[]"> <phNo>217-435-4927</phNo> <phNo>217-957-4937</phNo> </SOAP-ENC:Array>

Array values can be of any subtype of the arrays declared type

Encoding Data in SOAP (cont.)

Values can be used in multiple places using references <e:Book> <title>My Life</title> <author href="#Person-1"/> </e:Book> <e:Person id="Person-1"> <name>Henry Ford</name> </e:Person> Including refs to external resources

Using SOAP for RPC

Methods are invoked by making a SOAP request to a URI representing the target object Method calls are represented in the Body by a struct named after the method Struct members represent in/out parameters to the method The method result is encoded similarly and returned in a SOAP response Errors are signaled with the Fault entry

RPC Example: Digital Library

Supports card catalog search and checkout Target objects / methods Catalog / search Circulation / checkout, return Security Authentication: patron ID Fault: unrecognized user

RPC Example: Digital Library

Catalog Represented by a URI, e.g. http://www.lib.org/catalog/ Supports one method: Search Find items which match a particular query Result: list of entries containing information about items Fault condition: malformed query

RPC Example: Catalog Search

POST /catalog/ HTTP/1.1 Content-type: text/xml <SOAP-ENV:Envelope> <SOAP-ENV:Body> <lib:Search> <author>Kafka</author> </lib:Search> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

RPC Example: Catalog Search Response

HTTP/1.1 200 OK Content-type: text/xml <SOAP-ENV:Envelope> <SOAP-ENV:Body> <lib:SearchResponse> <lib:Item> <callNo>473.57</callNo> </lib:Item>

Introduction to WSDL

What is WSDL?

Web Service Description Language WSDL is a document written in XML The document describes a Web service Specifies the location of the service and the methods the service exposes

Why WSDL

Without WSDL, calling syntax must be determined from documentation that must be provided, or from examining wire messages With WSDL, the generation of proxies for Web services is automated in a truly language- and platform-independent way

Where does this fit in


SOAP is the envelope containing the message WSDL describes the service UDDI is a listing of web services described by WSDL

Document Structure

Written in XML Two types of sections Abstract and Concrete Abstract sections define SOAP messages in a platform- and languageindependent manner Site-specific matters such as serialization are relegated to the Concrete sections Abstract sections Types: Machine- and language-independent type definitions. Messages: Contains function parameters (inputs are separate from outputs) or document descriptions. PortTypes: Refers to message definitions in Messages section that describe function signatures (operation name, input parameters, output parameters). Concrete Descriptions Bindings: Specifies binding(s) of each operation in the PortTypes section. Services: Specifies port address(es) of each binding. Operations An operation is similar to a function in a high level programming language A message exchange is also referred to as an operation Operations are the focal point of interacting with the service

Big Picture

An Example

<?xml version="1.0" encoding="UTF-8" ?> This first line declares the document as an XML document. Not required, but helps the XML parser determine whether to parse the file or signal an error

Types Section

The type element defines the data types that are used by the web service.
<xsd:complexType name="PERSON"> <xsd:sequence> <xsd:element name="firstName type="xsd:string"/> <xsd:element name="lastName" type="xsd:string"/> <xsd:element name="ageInYears" type="xsd:int"/> </xsd:sequence> </xsd:complexType>

Messages Section

A message element defines parameters The name of an output message element ends in "Response" by convention
<message name="Simple.foo"> <part name="arg" type="xsd:int"/> </message> <message name="Simple.fooResponse"> <part name="result" type="xsd:int"/> </message>

PortTypes Section

Defines a web service, the operations that can be performed, and the messages that are involved.

<portType name="SimplePortType"> <operation name="foo" parameterOrder="arg" > <input message="wsdlns:Simple.foo"/> <outputmessage="wsdlns:Simple.fooResponse"/> </operation> </portType>

Bindings Section

The binding element defines the message format and protocol details for each port.

<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="GetLastTradePrice"> <soap:operation soapAction="http://example.com/GetLastTradePrice"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding>

The Port Element

Each <port> element associates a location with a <binding> in a one-to-one fashion <port name="fooSamplePort" binding="fooSampleBinding"> <soap:address location="http://carlos:8080/fooService/foo.asp"/> </port>

Services Section

A collection of related endpoints, where an endpoint is defined as a combination of a binding and an address
<service name="FOOSAMPLEService"> <port name="SimplePort binding="wsdlns:SimpleBinding"> <soap:address location="http://carlos:8080/FooSample/ FooSample.asp"/> </port> </service>

Namespaces

The purpose of namespaces is to avoid naming conflicts. Imagine two complimentary web services, named A and B, each with an element named foo. Each instance of foo can be referenced as A:foo and B:foo Example: "xmlns:xsd" defines a shorthand (xsd) for the namespace See http://www.w3.org/2001/XMLSchema.

WSDL: Example
<?xml version="1.0" encoding="UTF-8"?> <definitions name ="DayOfWeek" namespace="http://www.roguewave.com/soapworx/examples" targetNamespace="http://www.roguewave.com/soapworx/examples/DayOf Week.wsdl" xmlns:tns="http://www.roguewave.com/soapworx/examples/DayOfWeek.w sdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"> <message name="DayOfWeekInput"> <part name="date" type="xsd:date"/> </message> <message name="DayOfWeekResponse"> <part name="dayOfWeek" type="xsd:string"/> </message> <portType name="DayOfWeekPortType"> <operation name="GetDayOfWeek"> <input message="tns:DayOfWeekInput"/> <output message="tns:DayOfWeekResponse"/> </operation> </portType> encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> <service name="DayOfWeekService" > <documentation> Returns the day-of-week name for a given date </documentation> <port name="DayOfWeekPort" binding="tns:DayOfWeekBinding"> <soap:address location="http://localhost:8090/dayofweek/DayOfWeek"/> </port> </service> </definitions> <output> <soap:body use="encoded"

<binding name="DayOfWeekBinding" type="tns:DayOfWeekPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="GetDayOfWeek"> <soap:operation soapAction="getdayofweek"/> <input> <soap:body use="encoded" namespace="http://www.roguewave.com/soapworx/examples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input>

Sample WSDL file Describes port type, binding, input, output, Service name and URL

Source: Rogue Wave

Introduction to UDDI

Lucida Sans Unicode

UDDI is a open, cross-industry effort driven by major platform and software providers, as well as marketplace operators and e-business leaders within the OASIS standard consortium It defines a standard method for publishing and discovering the network-based software components of a service-oriented architecture UDDI creates a standard interoperable platform that enables companies and applications to quickly, easily and dynamically find and use Web services over the Internet

UDDI and Web Services

The UDDI protocol is another XML-based building block of the Web services stack along with SOAP (standard for invoking remote operations) and WSDL (standard for specifying what these operations look like) UDDI supplies an infrastructure for systematically addressing needs such as discovery, manageability and security of Web services beyond what is the simple organization of their interactions By addressing integration, coordination and flexibility issues of service-oriented systems, UDDI plays an important role within the service-oriented approach to enterprise software design

Accessing Web Services with UDDI

In some cases it may be that the information that are necessary to access Web services are known and thus directly stored within the applications that use them Nonetheless it is possible that the definitions and descriptions of such services (WSDL) are published to be discovered on ad hoc on-line registries UDDI defines how these registry should be designed and how to use them to describe, publish and discover services on a network Rather than forcing applications to include information about an external service's application programming interfaces, UDDI registry provide this binding information dynamically, at run-time UDDI guarantees flexibility with respect both to the dynamic run-time changes that occur during the life-cycle of web services and to the evolution of web application requirements

UDDIs Role in WS Software Development

By adopting UDDI, it turns out that convenience for developers, requirements of enterprise architects, and underlying business policies are not in opposition UDDI facilitates Web services software development by providing systematic, interoperable, standards-based: Management of the development process of web services Approach for documenting and publishing web services Organizations and managing of web services across multiple systems and development teams Documenting interface specification through teams and through time and for external applications above all in case of change UDDI help drive better code reuse and developer productivity (can help developers - across groups - find a shared service and use that service within their own applications)

UDDIs Role in SO Infrastructure

UDDI facilitates Service-Oriented Infrastructure: Insulates critical applications from changes or failures in backend services: Provides a formal layer of indirection (almost a firewall) necessary for service-oriented application development and management, useful for accommodating changes in the life cycle of specific components (updates, policy considerations, service termination) Helps an organization share information about services in a controlled way that reflects its own business rules and policies: Client authentication and publish/subscribe for peer registries satisfy operational governance needs as control of the publication and distribution of information about deployed services according to business policies Solutions are not hard-coded but takes advantage of run-time binding

UDDI from the Businesses Point of View (1/2)

The UDDI Project enables businesses to: Discover each other Define how they interact over the internet and share information in a global registry architecture Enact policy-based distribution and management of enterprise web services The UDDI project is not industry specific Any industry, of any size, worldwide, offering products and services can benefit from this open initiative because the specifications comprehensively addresses problems that limit the growth and synergies of B2B commerce and Web services. Before the UDDI project, there was no industry-wide approach for business to reach their customers and partners with information about their products and Web services, nor there was a method of how to integrate into each other's systems and processes. UDDI is the building block that enables businesses to quickly, easily and dynamically find and transact with one another via their preferred applications.

UDDI from the Businesses Point of View (2/2)

Problems solved: Makes it possible for organizations to quickly discover the right business from millions currently on line Defines how to enable commerce to be conducted once the preferred business is discovered Immediate benefits for businesses: Reaching new customers Expanding offerings Extending market reach Increasing access to current customers Solving customer-driven need to remove barriers to allow for rapid participation in the global Internet economy Describing their services and business processes programmatically in a single, open and secure environment Using a set of protocols that enables businesses to invoke services over the internet to provide additional value to their preferred customers

UDDI Features

UDDI is similar to the concepts of DNS and yellow pages In short, UDDI provides an approach to: Locate a service Invoke a service Manage metadata about a service UDDI specifies: Protocols for accessing a registry for Web services Methods for controlling access to the registry Mechanism for distributing or delegating records to other registries

UDDI Specifications

UDDI defines: SOAP APIs that applications use to query and to publish information to a UDDI registry XML Schema schemata of the registry data model and the SOAP messages format WSDL definitions of the SOAP APIs UDDI registry definitions (technical model - tModels) of various identifier and category systems that may be used to identify and categorize UDDI registrations The UDDI Specifications Technical Committee also develops Technical Notes and Best Practice documents that aid users in deploying and using UDDI registries effectively

UDDI Registry Service

The UDDI specifications define a registry service for Web services and for other electronic and non-electronic services A UDDI registry service is a Web service that support the description and discovery of service providers, service implementations, and service metadata UDDI is a meta service for locating web services by enabling robust queries against rich metadata. Service providers can use UDDI to advertise the services they offer Service consumer can use UDDI to discover services that suites their requirements and to obtain the service metadata needed to consume those services.

UDDI Registry

Functional purpose: representation of data and metadata about Web services Either for use on a public network or within on organizational internal infrastructure Offers standards-based mechanism to classify, catalog and manage Web services so that they can be discovered and consumed by other applications Implements generalized strategy of indirection amongst services based applications Offers benefits to IT managers both at design and run-time, including code reuse and improving infrastructure management

UDDI Registry Types


UDDI allows operational registries to be maintained for different purposes in different contexts A business may deploy one or more: Private registries: Isolated from the public network, firewalled Restricted access No shared data Public registries: Unrestricted open and public access Data is shared with other registries Affiliated registries Controlled environment Access limited to authorized clients Data shared in a controlled manner Private registry supports intranet applications, while a public registry support extranet applications Affiliated registries supports all other infrastructural topologies e.g., involving delegation, distribution, replication, subscription, that reflects the realities and the relationship of the underlying business processes

UDDI Registry Data Model

The core information model of UDDI registries is made of several data structures: businessEntity (info about the organization that published the service) businessService (description of a service business function) bindingTemplate (services technical details, including a reference to the API) tModel (attributes or metadata about the service such as taxonomies, transports, digital signatures) publisherAssertions (relationship among entities in the registry, v2.0) Subscription (standing request to track changes to a list of entities) Each data structure within a given registry is assigned a unique UDDI key UDDI allows users to specify different taxonomies for providing semantic structure to the information about Web services contained in a registry

UDDI Servers

UDDI specifies hierarchical relationship between a single instance of a UDDI implementation and others to which it is related UDDI Servers can be: Nodes: supports a minimum set of functionalities of the specification (they are member of exactly one registry) Registry: composed of one or more nodes; supports the complete set of functionalities of the specification Affiliated registry: registry that implements a policy-based sharing of information together with other affiliated registry Registry Affiliation is the main achievement of UDDI V3.0 Recognition that UDDI is to support the design and operations of myriads software applications within and among business organizations (not only private/public registries)

UDDI API

Features that supports core data management: Publishing information about a service to a registry Searching a UDDI registry for information about a service Features that supports registry interaction: Replicating and transferring custody of data about a service Registration key generation and management Registration subscription API set Security and authorization These are divided in Node API Sets (for UDDI Servers) and Client API Sets (for UDDI Clients)

UDDI Solutions

Several categories of product and components UDDI Registry Server, UDDI-enabled IDEs and development tools, Java and .NET client toolkits and browsers, UDDIintegrated Web services platforms Supplied by multiple vendors, consortia and also available as open source Apache.org, BEA, IBM, Microsoft, Oracle, SAP, Sun, Systinet, UDDI4J.org jUDDI is an open sourceJava based implementation of a UDDI v2 registry and a toolkit UDDI4J is a Java class library that provides an API to interact with a UDDI registry Java Web Service Developer Pack by Sun Web Application Server by SAP Webshpere UDDI Registry by IBM

Introduction to Java Web Services

Lucida Sans Unicode

Part of Java EE. New in Java SE 6. API stack for web services. Replaces JAX-RPC. New APIs: JAX-WS, SAAJ, Web Service metadata New packages: javax.xml.ws, javax.xml.soap,javax.jws

Software required.

Java WSDP 1.6 Bundle This can be downloaded from : http://java.sun.com/webservices/download/webservicespack.html

Application Server Sun Java System Application Server Platform Edition 8.1 2005Q2 UR2 may be used as the build and runtime environment. The Application Server and J2SE SDK are contained in the J2EE 1.4 SDK. you can download the Application Server from: http://java.sun.com/j2ee/1.4/download.html#sdk

What is JAX-WS
JAX-WS stands for Java API for XML Web Services. JAX-WS is a technology for building web services and clients that communicate using XML. JAX-WS allows developers to write message-oriented as well as RPCoriented web services. In JAX-WS, a remote procedure call is represented by an XML-based protocol such as SOAP. The SOAP specification defines the envelope structure, encoding rules, and conventions for representing remote procedure calls and responses. These calls and responses are transmitted as SOAP messages (XML files) over HTTP.

Web Services Platform Architecture (WSPA)


WSPA Identifies Three Components of JWS

Invocation Proxies Represent Web Services in Java Interface to Messaging System (HTTP) QoS (Handlers) Marshalling (Impedance Matcher) Java/XML Binding Deployment Implement Web Service Endpoints (SOAP, REST) with Java

Invocation

param param

Invocation Subsystem (Client Side)


Request : SOAP

Invocation Subsystem (Server Side)


param Request : SOAP

SEI : Java Proxy

param

param

SEI : Java Proxy

param

Target : Java Object

return

Response : SOAP

Response : SOAP

return

Java Method Invocation

SOAP Message Exchange (Specified by WSDL)

Java Method Invocation

Java Proxies Represent Web Services


Java Virtual Machine SOAP Message Web Service Proxy Web Services Container <definitions ... targetNamespace="http://soabook.com" xmlns:soa="http://soabook.com" xmlns:wrapper="http://soabook.com/wrapper" ...> <types> <schema elementFormDefault="qualified" targetNamespace="http://soabook.com/wrapper" ...> <element name="customerPurchase"> <complexType> <sequence> <element ref="imported:customer"/> <element ref="imported:po"/> </sequence> </complexType> </element> ... </schema> ... </types> <message name="onCustomerPurchase"> <part element="wrapper:customerPurchase" name="purchase"/> </message> ... <portType name="CustomerPurchase"> <operation name="processCustomerPurchase"> <input message="soa:onCustomerPurchase" /> ... </operation> </portType> ... </definitions>

SOAP Endpoint

Java Interface

WSDL Interface

package com.soabook; import com.soabook.sales.Customer; import com.soabook.purchasing.PurchaseOrder; public interface PurchaseTransactions { public void newPurchase (Customer cust, PurchaseOrder po); ... }

Deployment

Web Services Platform


Web Services Directory (e.g., UDDI) Container (e.g., J5EE, Servlets, Axis)

WSDL +someOperation()

Endpoint Listener
-url WSDL Deployment WSDL/Java Mapping SOAP Handlers

Java Target
+someMethod() Binding Context Container Deployment Descriptors

Source Artifacts (e.g., EJB wrapper)

How to implement JAX-WS


The starting point for developing a JAX-WS web service is a Java class annotated with the javax.jws.WebService annotation. The WebService annotation defines the class as a web service endpoint. A service endpoint interface (SEI) is a Java interface that declares the methods that a client can invoke on the service. An SEI is not required when building a JAX-WS endpoint. The web service implementation class implicitly defines a SEI.

Steps in creating the web service and client


These are the basic steps for creating the web service and client: Code the implementation class. Compile the implementation class. Deploy the WAR file. The tie classes (which are used to communicate with clients) are generated by the Application Server during deployment. Code the client class. Use wsimport to generate and compile the stub files. Compile the client class. Run the client.

Requirements of a JAX-WS Endpoint


JAX-WS endpoints must follow these requirements: The implementing class must be annotated with either the javax.jws.WebService or javax.jws.WebServiceProvider annotation. The implementing class may explicitly reference an SEI through the endpointInterface element of the @WebService annotation, but is not required to do so. If no endpointInterface is not specified in @WebService, an SEI is implicityly defined for the implementing class. The business methods of the implementing class must be public, and must not be declared static or final.

Business methods that are exposed to web service clients must be annotated with javax.jws.WebMethod.
Business methods that are exposed to web service clients must have JAX-B-compatible parameters and return types. See Default Data Type Bindings.

Requirements of a JAX-WS Endpoint


The implementing class must not be declared final and must not be abstract. The implementing class must have a default public constructor. The implementing class must not define the finalize method. The implementing class may use the javax.annotation.PostConstruct or javax.annotation.PreDestroy annotations on its methods for lifecycle event callbacks. The @PostConstruct method is called by the container before the implementing class begins responding to web service clients. The @PreDestroy method is called by the container before the endpoint is removed from operation.

Writing a Service Endpoint Implementation Class


package helloservice.endpoint; import javax.jws.WebService;

@WebService() public class Hello { private String message = new String("Hello, ");
public void Hello() {} @WebMethod() public String sayHello(String name) { return message + name + "."; } }

In this example, the implementation class, Hello, is annotated as a web service endpoint using the @WebService annotation. Hello declares a single method named sayHello, annotated with the @WebMethod annotation. @WebMethod exposes the annotated method to web service clients. sayHello returns a greeting to the client, using the name passed to sayHello to compose the greeting. The implementation class also must define a default, public, no-argument constructor

Building the Service


To build HelloService, in a terminal window go to the <INSTALL>//examples/jaxws/helloservice/ directory and type the following:

The build task command executes these subtasks:

compile-service

The compile-service Task Thisasant task compiles Hello.java, writing the class files to the build subdirectory. It then calls the wsgen tool to generate JAX-WS portable artifacts used by the web service. The equivalent command-line command is as follows: wsgen -d build -s build -classpath build helloservice.endpoint.Hello The -d flag specifies the output location of generated class files. The -s flag specifies the output location of generated source files. The -classpath flag specifies the location of the input files, in this case the endpoint implmentation class, helloservice.endpoint.Hello.

Packaging and Deploying the Service

You

package and deploy the service using asant.

Upon

deployment, the Application Server and the JAX-WS runtime generate any additional artifacts required for web service invocation, including the WSDL file.

Generate Stub Code


Packaging and Deploying the Service with asant To package and deploy the helloservice example, follow these steps:

In a terminal window, go to <INSTALL>/javaeetutorial5/examples/jaxws/helloservice/. Run asant create-war. Make sure the Application Server is started. Set your admin username and password in <INSTALL>/javaeetutorial5/examples/common/build.properties. Run asant deploy. You can view the WSDL file of the deployed service by requesting the URL http://localhost:8080/helloservice/hello?wsdl in a web browser. Now you are ready to create a client that accesses this service.

Undeploying the Service

you can undeploy the service by typing this command:

asant undeploy

Testing the Service Without a Client


The Application Server Admin Console allows you to test the methods of a web service endpoint. To test the sayHello method of HelloService, do the following:

Open the Admin Console by opening the following URL in a web browser: http://localhost:4848/

Enter the admin username and password to log in to the Admin Console. Click Web Services in the left pane of the Admin Console. Click Hello. Click Test. Under Methods, enter a name as the parameter to the sayHello method. Click the sayHello button. This will take you to the sayHello Method invocation page.
Under Method returned, you'll see the response from the endpoint.

A Simple JAX-WS Client


Coding the Client When invoking the remote methods on the stub, the client performs these steps:

Uses the javax.xml.ws.WebServiceRef annotation to declare a reference to a web service. WebServiceRef uses the wsdlLocation element to specify the URI of the deployed service's WSDL file. @WebServiceRef(wsdlLocation="http://localhost:8080/ helloservice/hello?wsdl") static HelloService service;

Retrieves a proxy to the service, also known as a port, by invoking getHelloPort on the service. Hello port = service.getHelloPort(); The port implements the SEI defined by the service. Invokes the port's sayHello method, passing to the service a name. String response = port.sayHello(name);

A simple WS client - Example


package simpleclient;

import javax.xml.ws.WebServiceRef; import helloservice.endpoint.HelloService; import helloservice.endpoint.Hello;


public class HelloClient { @WebServiceRef(wsdlLocation="http://localhost:8080/ helloservice/hello?wsdl") static HelloService service; public static void main(String[] args) { try { HelloClient client = new HelloClient(); client.doTest(args); } catch(Exception e) { e.printStackTrace(); } }

A simple WS client Example (contd)


public void doTest(String[] args) { try { System.out.println("Retrieving the port from the following service: " + service); Hello port = service.getHelloPort(); System.out.println("Invoking the sayHello operation on the port."); String name; if (args.length > 0) { name = args[0]; } else { name = "No Name"; } String response = port.sayHello(name); System.out.println(response); } catch(Exception e) { e.printStackTrace(); } }

A simple WS client Example (contd)

Building and Running the Client To build the client, you must first have deployed HelloServiceApp, as described in "Packaging and Deploying the Service with asant." Then navigate to <JAVA_EE_HOME>/examples/jaxws/simpleclient/ and do the following:

asant build

The run the client, do the following:

asant run

Thank You

You might also like