SlideShare a Scribd company logo
Overview of Java Web Services
Sujit Kumar
Zenolocity LLC © 2013-2023
What are web services
• Reusable web application components that
provide software functions at a network
address over the web with the service always
on.
• Interoperable between heterogeneous
systems (language & platform independent)
across the network.
• Interface described by WSDL.
2 Types
• REST compliant web services.
• SOAP based web services.
WSDL
• Contract between caller and callee that
describes a web service using XML format.
• Set of operations available at a network
address using a specific protocol and data
format.
• Each operation has an input request message
and an output response message.
Analogies for a WSDL
• WSDL – interface in java.
• Operations – static methods in a java object.
• Input Message of an operation – argument
passed to a java method.
• Output Message of an operation – argument
returned from a java method.
• Types – Classes in Java, without any methods.
WSDL Elements
• Types – data type definitions
• Messages – definition of data being
exchanged.
• Port Type – set of operations exposed at a
network address.
• Binding – protocol (SOAP over http) and data
format specification.
SOAP
• XML based communication protocol for
accessing Web Services.
• Language and Platform Independent.
• SOAP provides a way for applications to
communicate with each other over HTTP. The
applications could be running on different
operating systems with different technologies
and programming languages.
SOAP XML Message Elements
• Envelope – wraps everything
• Header (optional)
• Body – appears after Header.
• Fault (optional) – part of the body
Example SOAP Message
• <?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-
encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
JAXB
• Java Architecture for XML Binding (JAXB)
• Two main features:
Marshall live java objects into XML data.
Un-marshall XML data into live java objects.
• Part of the Java SE platform.
• One of the APIs in the Java EE platform.
• Also, part of the Java Web Services
Development Pack (JWSDP).
XML, XSD & Tools for JAXB
• Analogy: XML is like an object, XSD is like a
class or a type. XML should be well formed
(syntactically correct) and valid (conform to an
XSD).
• xjc – convert xsd schemas to java classes.
Address.xsd  xjc  Address.java
• schemagen – convert annotated java classes
to schema definitions.
Address.java  schemagen  Address.xsd
JAX-WS
• Java API for creating web services.
• Part of Java EE platform.
• Defines a standard for Java-to-WSDL mapping.
• Determines how WSDL operations are bound
to Java methods.
• Determines how SOAP messages are mapped
to java method arguments and return values.
• Can be used in Java SE from version 6.0.
JAX-WS Tools
• wsimport : top-down approach. Reads WSDL
file & generates portable artifacts that
includes SEI (service endpoint
implementation), jaxb classes from schema
types and exceptions from faults.
• wsgen : bottom-up approach. Reads an SEI
class and generates the portable artifacts for
web service development and deployment.
• Both are part of JDK 6 and above.
JAX-WS Implementations
• Metro Project in Glassfish (open source)
• Apache CXF
• Apache Axis 2
• Oracle WebLogic
• IBM WebSphere
• JBossWS
• Each of the above provides a wsdltojava utility
and provide implementations for the interfaces in
the JAX-WS api.
Converting WSDL to Java
• Vendor provided wsldtojava utilitiy or wsimport
utility in JDK 6.
• Can be configured to run as an eclipse plugin, or
invoked via command line utility or as an
ANT/Maven task.
• Output of Wsdl2Java is client stubs and skeletons.
• Stubs are used to invoke the remote web
services, actual business logic is written in the
skeletons.
Comparison of JAX-WS
Implementations
• http://wiki.apache.org/ws/StackComparison
• http://predic8.com/axis2-cxf-jax-ws-
comparison.htm
• http://www.ibm.com/developerworks/java/lib
rary/j-jws19/index.html
Service Oriented Architecture (SOA)
• Software architecture design pattern.
• Based on discrete pieces of software providing application
functionality as services to other applications.
• Characteristics of a service:
• Service Contract (defined via service description
documents)
• Loose Coupling (minimize dependencies)
• Reusable
• Abstraction (hide implementation logic)
• Location transparency, discoverable, stateless &
composable.
SOA and Web Services
• Web Services are an implementation of SOA.
• SOAP & REST are implementations of Web
Services.
• Web Service contract exposed via WSDL.
Web Services Implementation
Mechanisms
• Contract First or top-down : create the WSDL
first and then generate the stubs and
skeletons. WS Consumers use the stubs to
invoke the service implemented by the WS
Provider in the skeletons.
• Contract Last or bottom-up. Implement the
business logic first in the WS Provider. Extract
WSDL after the implementation.
• Contract first is usually preferred.
Benefits of Contract First
• Looser Coupling between contract and
implementation. Implementation logic can be changed
without affecting clients.
• Easier to keep contracts constant for longer periods of
time. Contracts can be fragile and change constantly. In
order for a contract to be useful, it must remain
constant for as long as possible.
• If a contract changes, you will have to contact all of the
users of your service, and instruct them to get the new
version of the contract.
• Enables parallel development of clients and service.
RESTful Services
• Architectural Style based on HTTP.
• Client-Server : separation of responsibilities promotes
portable clients & scalable servers.
• Stateless – no client context saved on server.
• Cacheable – clients can cache responses, improves
performance & scalability.
• Uniform Interface: identification of resources using
URIs. The resources themselves are conceptually
separate from the representations that are returned to
the client. For example, the server does not send its
database, but will send XML or JSON that represents
some database records.
RESTful Services
• Uniform Interface: Manipulation of resources
through these representations held by the
client.
• Uniform Interface: Self-descriptive messages.
Each message has enough information to
describe how to process the message.
• If a service violates any of the required
constraints, it cannot be considered RESTful.
RESTful Services
• Manipulate resources (CRUD) using HTTP
methods.
• GET – Retrieve
• PUT – Create or Update
• DELETE – Remove
• POST - Create
• GET, PUT and DELETE are idempotent, POST is not
idempotent.
• Idempotent implies:
y = f(x), y = f(f(x)), y = f(f(f(x)))
Difference between PUT and POST
• POST – create a child of the resource
identified by the URI.
• PUT – create or update the resource identified
by the URI.
Considerations to use PUT vs POST
• Do you name your URL objects you create
explicitly, or let the server decide? If you name
them then use PUT. If you let the server
decide then use POST.
• PUT is idempotent, so if you PUT an object
twice, it has no effect, then use PUT when
possible.
• You can update or create a resource with PUT
with the same object URI.
RESTful Methods applied to single
resource or collection of resources
STful API HTTP methods
Resource GET PUT POST DELETE
Collection URI
tp://example.com
/resources
List the URIs and
perhaps other
details of the
collection's
members.
Replace the entire
collection with
another collection.
Create a new entry
in the collection.
The new entry's URI
is assigned
automatically and is
usually returned by
the operation.
Delete the en
collection.
Element URI
tp://example.com
resources/item17
Retrieve the specific
member of the
collection.
Replace the
addressed member
of the collection, or
if it doesn't exist,
create it.
Not generally used.
Treat the specific
member as a
collection &
create a new entry
in it.
Delete the sp
member of th
collection.
Implementations of RESTful web
services
• Use JSR 311(JAX-RS) and its reference
implementation Jersey.
• Restlet framework
• Spring MVC.
Tutorial Examples
• Spring MVC based:
IBM Developer Works Example
Code Tutor Example
• Jersey Implementation
IBM Developer Works Example
Java Web services
Considerations for SOAP & RESTful
web services
• REST - How to model operations which are verbs like login, logout, transferFunds,
etc? -- think of the resource on which you are applying these methods and use
GET/PUT/POST operations on those resources. Need to map domain operations
into CRUD.
• SOAP doesn't require you to map domain operations onto CRUD.
• SOAP is suited for complex request and responses where multiple objects may get
updated within the same operation.
• REST is particularly useful for mobiles and tablets where there may be a
performance overhead of dealing with SOAP requests.
• SOAP requires less plumbing code than REST services for things like transactions,
security, coordination, addressing, trust, etc.
• SOAP fault handling is richer, REST needs to use HTTP status codes.

More Related Content

PPTX
Ntg web services
PDF
Java web services using JAX-WS
PDF
Introduction to SOAP/WSDL Web Services and RESTful Web Services
PDF
JDBC : Java Database Connectivity
PPTX
Soa 28 the role of wsdl, soap and java xml mapping in soa
PPTX
WSDL in Mule Esb
PDF
Xml schema
PPT
Mule web services
Ntg web services
Java web services using JAX-WS
Introduction to SOAP/WSDL Web Services and RESTful Web Services
JDBC : Java Database Connectivity
Soa 28 the role of wsdl, soap and java xml mapping in soa
WSDL in Mule Esb
Xml schema
Mule web services

What's hot (20)

PDF
Java Web Services [4/5]: Java API for XML Web Services
PDF
Java Web Services [3/5]: WSDL, WADL and UDDI
PPT
Mule enterprise service bus
PPTX
PDF
Avik_RailsTutorial
PDF
Change RelationalDB to GraphDB with OrientDB
PPTX
NiFi - First approach
PPTX
Designing REST services with Spring MVC
PDF
Java Web Services [1/5]: Introduction to Web Services
PPT
Java database connectivity
PDF
Java Web Services [2/5]: Introduction to SOAP
PPTX
Ruby on rails for beginers
PPTX
Intro To Web and Web Services (REST Series 01)
PPT
Project First presentation about introduction to technologies to be used
PPTX
Dataweave
PPTX
Soa 10 soa technology soap
PPT
Java web services
PPTX
Java architecture for xml binding
PPTX
PDF
OSOM - Ruby on Rails
Java Web Services [4/5]: Java API for XML Web Services
Java Web Services [3/5]: WSDL, WADL and UDDI
Mule enterprise service bus
Avik_RailsTutorial
Change RelationalDB to GraphDB with OrientDB
NiFi - First approach
Designing REST services with Spring MVC
Java Web Services [1/5]: Introduction to Web Services
Java database connectivity
Java Web Services [2/5]: Introduction to SOAP
Ruby on rails for beginers
Intro To Web and Web Services (REST Series 01)
Project First presentation about introduction to technologies to be used
Dataweave
Soa 10 soa technology soap
Java web services
Java architecture for xml binding
OSOM - Ruby on Rails
Ad

Similar to Java Web services (20)

PPTX
Soap and restful webservice
PDF
Web Services Training in Noida
PDF
Web Services
PDF
Rest web service
DOCX
Web services Concepts
PPT
15376199.ppt
PPTX
Web-Services-web services-20052025-051043pm.pptx
PPT
java-webservices introduction ppt for beginners
PPTX
Web Services
PPT
Reusing Existing Java EE Applications from SOA Suite 11g
PPTX
Web services for banks
PPTX
An Overview of Web Services: SOAP and REST
PPT
web services-May 25.ppt
PPTX
Jax ws
 
PPT
webservices overview
ODP
Web service Introduction
DOC
Web services soap rest training
PPTX
API-Testing-SOAPUI-1.pptx
PDF
Secc tutorials development and deployment of rest web services in java_v2.0
Soap and restful webservice
Web Services Training in Noida
Web Services
Rest web service
Web services Concepts
15376199.ppt
Web-Services-web services-20052025-051043pm.pptx
java-webservices introduction ppt for beginners
Web Services
Reusing Existing Java EE Applications from SOA Suite 11g
Web services for banks
An Overview of Web Services: SOAP and REST
web services-May 25.ppt
Jax ws
 
webservices overview
Web service Introduction
Web services soap rest training
API-Testing-SOAPUI-1.pptx
Secc tutorials development and deployment of rest web services in java_v2.0
Ad

More from Sujit Kumar (20)

PPTX
Introduction to OOP with java
PPTX
SFDC Database Basics
PPTX
SFDC Database Security
PPTX
SFDC Social Applications
PPTX
SFDC Other Platform Features
PPTX
SFDC Outbound Integrations
PPTX
SFDC Inbound Integrations
PPTX
SFDC UI - Advanced Visualforce
PPTX
SFDC UI - Introduction to Visualforce
PPTX
SFDC Deployments
PPTX
SFDC Batch Apex
PPTX
SFDC Data Loader
PPTX
SFDC Advanced Apex
PPTX
SFDC Introduction to Apex
PPTX
SFDC Database Additional Features
PPTX
Introduction to SalesForce
PPTX
More about java strings - Immutability and String Pool
PPTX
Hibernate First and Second level caches
PPTX
Java equals hashCode Contract
PPTX
Java Comparable and Comparator
Introduction to OOP with java
SFDC Database Basics
SFDC Database Security
SFDC Social Applications
SFDC Other Platform Features
SFDC Outbound Integrations
SFDC Inbound Integrations
SFDC UI - Advanced Visualforce
SFDC UI - Introduction to Visualforce
SFDC Deployments
SFDC Batch Apex
SFDC Data Loader
SFDC Advanced Apex
SFDC Introduction to Apex
SFDC Database Additional Features
Introduction to SalesForce
More about java strings - Immutability and String Pool
Hibernate First and Second level caches
Java equals hashCode Contract
Java Comparable and Comparator

Recently uploaded (20)

PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Pre independence Education in Inndia.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Institutional Correction lecture only . . .
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
master seminar digital applications in india
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Week 4 Term 3 Study Techniques revisited.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Abdominal Access Techniques with Prof. Dr. R K Mishra
Renaissance Architecture: A Journey from Faith to Humanism
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pre independence Education in Inndia.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
TR - Agricultural Crops Production NC III.pdf
Microbial disease of the cardiovascular and lymphatic systems
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Institutional Correction lecture only . . .
FourierSeries-QuestionsWithAnswers(Part-A).pdf
master seminar digital applications in india
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

Java Web services

  • 1. Overview of Java Web Services Sujit Kumar Zenolocity LLC © 2013-2023
  • 2. What are web services • Reusable web application components that provide software functions at a network address over the web with the service always on. • Interoperable between heterogeneous systems (language & platform independent) across the network. • Interface described by WSDL.
  • 3. 2 Types • REST compliant web services. • SOAP based web services.
  • 4. WSDL • Contract between caller and callee that describes a web service using XML format. • Set of operations available at a network address using a specific protocol and data format. • Each operation has an input request message and an output response message.
  • 5. Analogies for a WSDL • WSDL – interface in java. • Operations – static methods in a java object. • Input Message of an operation – argument passed to a java method. • Output Message of an operation – argument returned from a java method. • Types – Classes in Java, without any methods.
  • 6. WSDL Elements • Types – data type definitions • Messages – definition of data being exchanged. • Port Type – set of operations exposed at a network address. • Binding – protocol (SOAP over http) and data format specification.
  • 7. SOAP • XML based communication protocol for accessing Web Services. • Language and Platform Independent. • SOAP provides a way for applications to communicate with each other over HTTP. The applications could be running on different operating systems with different technologies and programming languages.
  • 8. SOAP XML Message Elements • Envelope – wraps everything • Header (optional) • Body – appears after Header. • Fault (optional) – part of the body
  • 9. Example SOAP Message • <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap- encoding"> <soap:Body xmlns:m="http://www.example.org/stock"> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
  • 10. JAXB • Java Architecture for XML Binding (JAXB) • Two main features: Marshall live java objects into XML data. Un-marshall XML data into live java objects. • Part of the Java SE platform. • One of the APIs in the Java EE platform. • Also, part of the Java Web Services Development Pack (JWSDP).
  • 11. XML, XSD & Tools for JAXB • Analogy: XML is like an object, XSD is like a class or a type. XML should be well formed (syntactically correct) and valid (conform to an XSD). • xjc – convert xsd schemas to java classes. Address.xsd  xjc  Address.java • schemagen – convert annotated java classes to schema definitions. Address.java  schemagen  Address.xsd
  • 12. JAX-WS • Java API for creating web services. • Part of Java EE platform. • Defines a standard for Java-to-WSDL mapping. • Determines how WSDL operations are bound to Java methods. • Determines how SOAP messages are mapped to java method arguments and return values. • Can be used in Java SE from version 6.0.
  • 13. JAX-WS Tools • wsimport : top-down approach. Reads WSDL file & generates portable artifacts that includes SEI (service endpoint implementation), jaxb classes from schema types and exceptions from faults. • wsgen : bottom-up approach. Reads an SEI class and generates the portable artifacts for web service development and deployment. • Both are part of JDK 6 and above.
  • 14. JAX-WS Implementations • Metro Project in Glassfish (open source) • Apache CXF • Apache Axis 2 • Oracle WebLogic • IBM WebSphere • JBossWS • Each of the above provides a wsdltojava utility and provide implementations for the interfaces in the JAX-WS api.
  • 15. Converting WSDL to Java • Vendor provided wsldtojava utilitiy or wsimport utility in JDK 6. • Can be configured to run as an eclipse plugin, or invoked via command line utility or as an ANT/Maven task. • Output of Wsdl2Java is client stubs and skeletons. • Stubs are used to invoke the remote web services, actual business logic is written in the skeletons.
  • 16. Comparison of JAX-WS Implementations • http://wiki.apache.org/ws/StackComparison • http://predic8.com/axis2-cxf-jax-ws- comparison.htm • http://www.ibm.com/developerworks/java/lib rary/j-jws19/index.html
  • 17. Service Oriented Architecture (SOA) • Software architecture design pattern. • Based on discrete pieces of software providing application functionality as services to other applications. • Characteristics of a service: • Service Contract (defined via service description documents) • Loose Coupling (minimize dependencies) • Reusable • Abstraction (hide implementation logic) • Location transparency, discoverable, stateless & composable.
  • 18. SOA and Web Services • Web Services are an implementation of SOA. • SOAP & REST are implementations of Web Services. • Web Service contract exposed via WSDL.
  • 19. Web Services Implementation Mechanisms • Contract First or top-down : create the WSDL first and then generate the stubs and skeletons. WS Consumers use the stubs to invoke the service implemented by the WS Provider in the skeletons. • Contract Last or bottom-up. Implement the business logic first in the WS Provider. Extract WSDL after the implementation. • Contract first is usually preferred.
  • 20. Benefits of Contract First • Looser Coupling between contract and implementation. Implementation logic can be changed without affecting clients. • Easier to keep contracts constant for longer periods of time. Contracts can be fragile and change constantly. In order for a contract to be useful, it must remain constant for as long as possible. • If a contract changes, you will have to contact all of the users of your service, and instruct them to get the new version of the contract. • Enables parallel development of clients and service.
  • 21. RESTful Services • Architectural Style based on HTTP. • Client-Server : separation of responsibilities promotes portable clients & scalable servers. • Stateless – no client context saved on server. • Cacheable – clients can cache responses, improves performance & scalability. • Uniform Interface: identification of resources using URIs. The resources themselves are conceptually separate from the representations that are returned to the client. For example, the server does not send its database, but will send XML or JSON that represents some database records.
  • 22. RESTful Services • Uniform Interface: Manipulation of resources through these representations held by the client. • Uniform Interface: Self-descriptive messages. Each message has enough information to describe how to process the message. • If a service violates any of the required constraints, it cannot be considered RESTful.
  • 23. RESTful Services • Manipulate resources (CRUD) using HTTP methods. • GET – Retrieve • PUT – Create or Update • DELETE – Remove • POST - Create • GET, PUT and DELETE are idempotent, POST is not idempotent. • Idempotent implies: y = f(x), y = f(f(x)), y = f(f(f(x)))
  • 24. Difference between PUT and POST • POST – create a child of the resource identified by the URI. • PUT – create or update the resource identified by the URI.
  • 25. Considerations to use PUT vs POST • Do you name your URL objects you create explicitly, or let the server decide? If you name them then use PUT. If you let the server decide then use POST. • PUT is idempotent, so if you PUT an object twice, it has no effect, then use PUT when possible. • You can update or create a resource with PUT with the same object URI.
  • 26. RESTful Methods applied to single resource or collection of resources STful API HTTP methods Resource GET PUT POST DELETE Collection URI tp://example.com /resources List the URIs and perhaps other details of the collection's members. Replace the entire collection with another collection. Create a new entry in the collection. The new entry's URI is assigned automatically and is usually returned by the operation. Delete the en collection. Element URI tp://example.com resources/item17 Retrieve the specific member of the collection. Replace the addressed member of the collection, or if it doesn't exist, create it. Not generally used. Treat the specific member as a collection & create a new entry in it. Delete the sp member of th collection.
  • 27. Implementations of RESTful web services • Use JSR 311(JAX-RS) and its reference implementation Jersey. • Restlet framework • Spring MVC.
  • 28. Tutorial Examples • Spring MVC based: IBM Developer Works Example Code Tutor Example • Jersey Implementation IBM Developer Works Example
  • 30. Considerations for SOAP & RESTful web services • REST - How to model operations which are verbs like login, logout, transferFunds, etc? -- think of the resource on which you are applying these methods and use GET/PUT/POST operations on those resources. Need to map domain operations into CRUD. • SOAP doesn't require you to map domain operations onto CRUD. • SOAP is suited for complex request and responses where multiple objects may get updated within the same operation. • REST is particularly useful for mobiles and tablets where there may be a performance overhead of dealing with SOAP requests. • SOAP requires less plumbing code than REST services for things like transactions, security, coordination, addressing, trust, etc. • SOAP fault handling is richer, REST needs to use HTTP status codes.