robert thornton
DESCRIPTION
Web Services with Apache CXF Part 1: SOAP Web Services. Robert Thornton. Notes. This is a training, NOT a presentation Please ask questions This is being recorded https://tech.lds.org/wiki/Java_Stack_Training Prerequisites Maven Spring Web Application Development. Objectives. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/1.jpg)
Web Services with Apache CXFPart 1: SOAP Web Services
Robert Thornton
![Page 2: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/2.jpg)
Notes
• This is a training, NOT a presentation• Please ask questions• This is being recorded• https://tech.lds.org/wiki/Java_Stack_Training• Prerequisites
– Maven– Spring– Web Application Development
![Page 3: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/3.jpg)
Objectives
At the end of this presentation, the participant will be able to:• Describe the role of Apache CXF in building SOAP web services.• Understand the basic characteristics and terminology of a SOAP
web service.• Describe the pros and cons of SOAP vs. REST.• Use Apache CXF and Spring to produce a SOAP HTTP endpoint in
a Java web application.• Be able to consume a SOAP HTTP web service within an
integration test.• Be able to identify the purpose and components of a SOAP WSDL
document.
![Page 4: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/4.jpg)
Apache CXF: What is it?
What is Apache CXF and what does it provide?• An open-source web services framework• Support for web service standards and JSR APIs.• Tooling and configuration for building and
consuming web services using the JAX-WS and JAX-RS frontend APIs.
• Spring namespace handlers for integration with the Spring Application Framework.
![Page 5: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/5.jpg)
Apache CXF: A Robust Framework
Apache CXF provides robust support for producing and consuming web services:• JSR APIs: JAX-WS, JAX-RS, JSR-181 annotations, SAAJ• WS-* specifications for web service interoperability.• A variety of message transports, protocol bindings, data bindings,
and formats.• Flexible, lightweight deployment in a variety of web application
containers or stand-alone.• Tooling for code and WSDL generation and validation.• Multiple language support.
![Page 6: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/6.jpg)
Apache CXF: Help, I’m drowning!
With all these features, how do I choose?
![Page 7: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/7.jpg)
Apache CXF: Recommendations
The Java Stack recommends the following two basic feature sets for using CXF to produce and consume web services in Java applications:• Option #1: JAX-WS, using the SOAP protocol over
HTTP transport with JAXB data binding.• Option #2: JAX-RS using REST over HTTP with
JAXB, XML, or JSON data binding.This training will focus on producing and consuming SOAP web services with JAX-WS. A future training session will cover JAX-RS.
![Page 8: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/8.jpg)
Apache CXF: Still too many choices?
Apache CXF allows JAX-WS with SOAP and JAX-RS (REST) to be used side by side.
But which is right for my project?
![Page 9: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/9.jpg)
SOAP vs. REST: An Overview
Both SOAP and REST are front-end technologies. That is, their services are exposed within the view layer of an application.SOAP• Supports a variety of transports (HTTP, JMS, etc.)• Integrates with a variety of web service standards.• Typically used to pass contractually structured data between
applications.REST• Simple point-to-point communication using well-established HTTP
verbs, protocols, and standards.• Often used to faciliate dynamic HTML page creation.
![Page 10: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/10.jpg)
SOAP: Pros and Cons
Pros:• Agnostic to language, platform, and transport.• Designed for distributed environments and applications.• Richer, more mature, standards-based support and integration.• Built-in error-handling (faults).• Extensible through integration with other transports and data
bindings.Cons:• Heavier abstraction and steep learning curve.• More verbose.• Difficult to develop without tools.
![Page 11: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/11.jpg)
REST: Pros and Cons
Pros:• Agnostic to language and platform.• Conceptually simpler to understand and develop.• Less reliance on tools• Closer in design and philosophy to the web.Cons:• Locked into the HTTP transport model. Cannot be scaled to non-HTTP
communication models.• Lack of standards support for security, policy, messaging, etc., making
apps with richer requirements harder to develop.
* For a more detailed comparison of SOAP and REST, see the following excellent article: http://ajaxonomy.com/2008/xml/web-services-part-1-soap-vs-rest or perform an internet search on “SOAP vs REST”.
![Page 12: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/12.jpg)
SOAP vs. REST: Summary
• Know your deployment environment and infrastructure.– Will your service be distributed?– Will communication need to pass through non-HTTP
boundaries?• Know your interoperability and scalability
requirements.– Who will be consuming your service?– Will you need to support non-HTTP transports (e.g.
JMS, SMTP, POP3) now or in the future?
![Page 13: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/13.jpg)
And now for a song….
¯Oh, I wish I were a little bar of …
SOAP!¯
![Page 14: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/14.jpg)
JAX-WS and SOAP
Essential Terminology:• WSDL• Web Service Namespace URI• Endpoint URL or Port• Service Endpoint Interface (SEI)• Operation• Message• Envelope
![Page 15: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/15.jpg)
JAX-WS: Defining a Service Endpoint
The JAX-WS specification uses Java annotations to define your web service endpoint.• CXF processes these annotations to produce your
WSDL• The annotations can be used to customize many
aspects of how your WSDL and web service schema are published.
![Page 16: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/16.jpg)
JAX-WS: Annotations
@javax.jws.WebService• Marks a Java interface as a Service Endpoint Interface.• Marks a Java class as a web service endpoint implementation.
@javax.jws.WebMethod• Optional annotation for customizing a SOAP web service operation
@javax.jws.WebParam• Optional annotation for customizing the mapping of an individual parameter
to a web service message part, or input parameter.
@javax.jws.WebResult• Optional annotation for customizing how SOAP treats the output of a web
operation.
![Page 17: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/17.jpg)
JAX-WS: More Annotations
@javax.jws.soap.SOAPBinding• Customizes the mapping of the web service onto
the SOAP message protocol.• Its use is optional as the default settings are the
recommended values and will make your web service the most portable.
![Page 18: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/18.jpg)
JAX-WS: Defining a Service Endpoint
A Basic Example:package org.lds.training.cxf.labs.ws;
import java.util.List;import javax.jws.*; // General web service annotationsimport javax.jws.soap.*; // SOAP-specific WS annotations
@SOAPBinding( style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)@WebService( targetNamespace = "http://schema.lds.org/cxf-labs/user/v1.0")public interface UserService {
@WebMethod(action = "CreateExample") public User getUser(@WebParam(name = "username") String username);}
![Page 19: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/19.jpg)
Web Services on the Java Stack
A Java Stack web service provider typically consists of the following Maven projects:• A parent (POM) module• An API (JAR) module
– This is where you should define your web service interface.• A web application (WAR) module
– This is where you implement your web service functionality• A QA module
– This is where your integration tests will consume your web service during development and testing.
• A deployment module
![Page 20: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/20.jpg)
Apache CXF: SOAP: Lab 1
Lab 1: An Example SOAP Web Servicehttp://tech.lds.org/wiki/Web_Services_with_Apache_CXF_-_Part_1
![Page 21: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/21.jpg)
Namespace Handlers
For Spring bean configuration, the Java Stack defines two namespace handlers for JAX-WS web services:• <stack-ws:produce/>
– Used in the web application to configure the JAX-WS web service bean.
• <stack-ws:consume/>– Used in a QA module or other application to
configure a JAX-WS client proxy bean.
![Page 22: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/22.jpg)
Configuring a Web Service Provider
Attributes to <stack-ws:produce/>• implementor
– The bean name of the endpoint implementation class• secured
– Whether to secure the web service with LDS Account.• address
– The endpoint address where the service will be published.• authentication-manager-ref
– allows customization of the authentication manager
![Page 23: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/23.jpg)
Configuring a Web Service Client
Attributes to <stack-ws:consume/>• service-class
– The bean name of the endpoint implementation class.• endpoint
– The published endpoint service address.• user, password, password-type
– For user authentication. Both plain text and digest passwords are supported.
• wam-authenticator, wam-cookie-resolver-ref– Provides authentication through WAM
• ssl-trust-server– Specifies whether the server’s SSL cert should be automatically trusted.
![Page 24: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/24.jpg)
Apache CXF: SOAP: Lab 2
Lab 2: Producing a SOAP Web Servicehttp://tech.lds.org/wiki/Web_Services_with_Apache_CXF_-_Part_1
![Page 25: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/25.jpg)
Apache CXF: SOAP: Lab 3
Lab 3: Consuming a SOAP Web Servicehttp://tech.lds.org/wiki/Web_Services_with_Apache_CXF_-_Part_1
![Page 26: Robert Thornton](https://reader036.vdocuments.site/reader036/viewer/2022081503/568163e7550346895dd54d93/html5/thumbnails/26.jpg)
Resources
On the web:• http://cxf.apache.org• http://www.w3.org/TR/soap/• http://en.wikipedia.org/wiki/Cxf• http://en.wikipedia.org/wiki/SOAP• http://ajaxonomy.com/2008/xml/web-services-part-1-soap-vs-res
tIn Print:• Developing Web Services with Apache CXF and Axis 2, Kent Kai Iok
Tong, TipTech Development, 2005-2010. ISBN: 978-0-557-25432-3