SlideShare a Scribd company logo
Topic 4

  Java API for XML Web Services



Assoc.Prof. Dr. Thanachart Numnonda
       www.imcinstitute.com
            August 2010
Agenda
ïŪ Java APIs   for Web Services
ïŪ JAX-RPC

ïŪ JAX-WS




                                 2
Java APIs for Web Services




                             3
JWSDP
ïŪ   Java Web Services Development Pack (JWSDP) is a free
    software development kit (SDK) for developing Web
    Services
ïŪ   JWSDP has been replaced by GlassFish and WSIT and
    several components are in Java SE 6.
ïŪ   JWSDP APIs
       ïŪ   Java API for XML Processing (JAXP), v 1.3
       ïŪ   Java Architecture for XML Binding (JAXB), v 1.0 and 2.0
       ïŪ   JAX-RPC v 1.1
       ïŪ   JAX-WS v 2.0
       ïŪ   SAAJ (SOAP with Attachments API for Java)
       ïŪ   Java API for XML Registries (JAXR)
                                                                     4
Java API for XML Processing (JAXP)
â€Ē JAXP enables applications to parse, validate and
  transform XML documents.
â€Ē Java developers can invoke
   â€Ē SAX parser
   â€Ē DOM parser
â€Ē The main JAXP APIs are defined in the
  javax.xml.parsers package
   â€Ē SAXParserFactory
   â€Ē DocumentBuilderFactory



                                                     5
Java API for XML Binding (JAXB)
â€Ē JAXB allows Java developers to access and process XML data
  without having to know XML or XML processing.
â€Ē JAXB is a Java technology that enables you to generate Java
  classes from XML schemas by means of a JAXB binding
  compiler.
â€Ē unmarshalling
   â€Ē XML instance documents into Java content trees
â€Ē marshalling
   â€Ē Java content trees back into XML instance documents.

                                                                6
SAAJ (SOAP with Attachments
         API for Javaâ„Ē)
â€Ē SAAJ provides a convenient API for constructing
and sending SOAP messages without having to
directly create the XML yourself.
â€Ē SAAJ was originally part of the Java API
for XML Messaging (JAXM) Separated out from
 JAXM 1.0 into JAXM 1.1 and SAAJ 1.1
 (SAAJ 1.3 (Java EE 5))
                                                    7
JAXR
â€Ē Standard Java API for performing registry operations
  over diverse set of registries
     Web service publication & discovery

â€Ē A unified information model for describing business
  registry content
â€Ē Provides multi-layered API abstractions
     Level 0: for UDDI
     Level 1: for ebXML registry/repository
                                                         8
JAX-RPC

â€Ē XML data types to/from Java types mapping
â€Ē SOAP Message Handler framework
â€Ē WSDL to/from Java mapping
â€Ē Servlet-based Web service endpoint model
â€Ē JAX-RPC Client Programming Models
â€Ē Extensible type mapping

                                              9
JAX-WS (JAX-RPC 2.0)
â€Ē   New handler framework
â€Ē   Metadata-based Web services
â€Ē   Operational style improvement
â€Ē   Asynchronous Web services
â€Ē   Support for non-HTTP transport
â€Ē   Interoperable attachments (as part of WS-I)
â€Ē   Secure Web services (as part of Security)


                                                  10
JAXM

â€Ē JAXM is not part of Java EE 5
â€Ē JAXM-based asynchronous messaging on Java EE 5
  is supported via
     Message-driven Bean (MDB) in EJB 3 can receive
    both JMS and JAXM message types
     Connector 1.5 allows pluggability of various types
    message providers (JAXM provider and JMS
    provider)

                                                          11
Java APIs for Web Services Protocols
ïŪ   SOAP
    ïŪ   JAXM 1.0 (JSR 67), SAAJ
    ïŪ   JAX-RPC => JAX-WS 2.0 (JSR 224)
ïŪ   WSDL
    ïŪ   JAX-RPC => JAX-WS 2.0 (JSR 224)
ïŪ   UDDI
    ïŪ   JAXR 1.0 (JSR 93)




                                          12
Sun’s Web Services Stack




                           13
JAX-RPC




          14
Remote Procedure Call (RPC)
                             Request

                            Response
        Client System                          Server System

ïŪ   RPC, COM, CORBA, RMI:
    
        Synchronous communication: calling process blocks until
        there is a response
    
        More tightly coupled (than non-RPC model): client must
        find recipients and know method and its arguments
    
        Non persistent
Remote Procedure Calls

Client       Interface                  Interface         Servant

               Stub                     Skeleton



             Run Time      Protocol     Run Time

         
           Common Interface between client and Server
         
           Stub for client, Skeleton/Tie for server
         
           On-the-wire protocol needs to be agreed upon
RPC Example – Java RMI
                     <<Interface>>
                     Java Remote
                       Interface


                     rmic compiler

  Client                               Remote Object
                                       Implementation



RMI Client                               RMI Server
  Stub                                    Skeleton

           Java Remote Method Protocol (JRMP) is
                   On-the-wire protocol
RPC Example - JAX-RPC
Common Interface
ïŪ   Service is described in IDL (Interface Description
    Language)
      IDL ofCORBA service
      Java RMI interface in RMI (Language specific)
      WSDL for Web service

ïŪ   Used by tools to statically or dynamically generate
    and/or configure interfaces, proxies, and ties in a
    network technology specific environment
What is JAX-RPC?
ïŪ   Javaâ„Ē API for XML-based RPC
    ïŪ   Web Services operations are performed by exchanging
        SOAP 1.1 messages
ïŪ   Services are described using WSDL
    â€Ē   WSDL is the contract between service provider and
        client (only contract needed)
ïŪ   Web service endpoints and clients use JAX-RPC
    programming model
ïŪ   Key technology for Web Services in the J2EE 1.4
    platform
JAX-RPC Design Goals
ïŪ   Easy to use programming model
    â€Ē   For both defining & using a service
ïŪ   Hides all the plumbing
    â€Ē   You don't have to create SOAP messages yourself
ïŪ   SOAP and WSDL-based interoperability
    â€Ē   Interoperate with any SOAP 1.1 compliant peers
ïŪ   Extensibility and Modularity
    â€Ē   Support new versions of XML specification, i.e. SOAP 1.2
        and beyond
    â€Ē   Message handler architecture
JAX-RPC Architecture
    JAX-RPC                                             JAX-RPC
      Client                WSDL Document            Service Endpoint
 Generated        JavaïƒŊWSDL             WSDLïƒģJava
   Code

Container                                                   Container


      Client-side JAX-RPC                   Server-side JAX-RPC
        Runtime System                        Runtime System


                                SOAP

                                HTTP
JAX-RPC Runtime System
ïŪ   Core of a JAX-RPC implementation:
    â€Ē Library that provides runtime services
      for JAX-RPC mechanisms
    â€Ē Implements some of the JAX-RPC APIs
ïŪ   Client side:
    â€Ē Can be implemented over J2SEâ„Ē, J2EEâ„Ē or J2MEâ„Ē
      platforms
ïŪ   Server-side:
    â€Ē J2EE 1.3 or 1.4 Containers: EJBâ„Ē or Servlet
Developing a Web Service
       Interfaces (java.rmi.Remote type)
       Must follow JAX-RPC conventions


       Implementation classes
       Servlet-based endpoint model
       Optional handler and serializer classes

tool
               WSDL      Service contract

       Packaged application (war file)
JAX-RPC : Web Service Endpoint
                                  JAX-RPC
                               Service Endpoint
          WSDL<-->Java


  WSDL Document           Container


                         Server-Side
                          JAX-RPC
                           Runtime
                           System
             SOAP

             HTTP
JAX-WS




         26
Quick overview of JAX-WS
ïŪ   Easy way to use Java API for XML Web Services
    ïŪ   Replace JAX-RPC
ïŪ   Just add @annotation to POJO
    ïŪ   XML Descriptor free programming
ïŪ Layer architecture
ïŪ SOAP 1.2 (Document/Literal)
ïŪ Use JAXB for data binding
ïŪ Protocol and transport independence
ïŪ Part of Java SE6 and Java EE 5 Platform
                                                    27
JAX-WS Layered Architecture




                              28
What Does It Mean?
â€Ē Upper layer uses annotations extensively
     â€Ē Easy to use
     â€Ē Great toolability
     â€Ē Fewer generated classes
â€Ē Lower layer is more traditional
     â€Ē API-based
     â€Ē For advanced scenarios
â€Ē Most application will use the upper layer only
â€Ē Either way, portability is guaranteed

                                                   29
Two ways to create a Web Service
â€Ē Starting from a WSDL file
  > Generate classes using wsimport (=> xjc)
    > WS interface
    > WS implementation skeleton class
  > Implement WS interface
  > Build and deploy
â€Ē Starting from a Java class (POJO)
  > Annotate POJO
  > Build and deploy
    > WSDL file generated automatically

                                               30
Start with a Java Class




                          31
Server-Side Programming Model: POJO

1    Write a POJO implementing the service
2    Add @WebService annotation to it
3    Build and Deploy the application
    WSDL is automatically generated at runtime
1    Point your clients at the WSDL
    e.g. http://myserver/myapp/MyService?WSDL




                                                 32
Example 1: Servlet-Based Endpoint
@WebService
public class Calculator {
    public int add( int a, int b) {
        return a + b;
    }
}



â€Ē @WebService annotation
  â€Ē All public methods become web service operations
â€Ē WSDL/Schema generated automatically
  â€Ē Default values are used
                                                       33
Service Description Default Mapping
â€Ē Java mapping => WSDL




                                       34
Example 2: EJB-Based Endpoint
@WebService
@Stateless
public class Calculator {
    public int add( int a, int b) {
        return a + b;
    }
}



â€Ē It’s a regular EJB 3.0 component, so it can use any
  EJB features
   > Transactions, security, interceptors...

                                                        35
Customizing through Annotations
@WebService(name=”CreditRatingService”,
            targetNamespace=”http://example.org”)
public class CreditRating {

     @WebMethod(operationName=”getCreditScore”)
     public Score getCredit(
         @WebParam(name=”customer”)
         Customer c) {
         // ... implementation code ...
    }
}




                                                    36
Start with a WSDL file




                         37
Generating an interface from WSDL
â€Ē WSDL => Java generation




                                      38
Implementing a Web Service from
     a Generated Interface




                                  39
Server Side Web Service




                          40
JAX-WS uses JAXB for Data Binding




                                    41
add() Parameter : Example




                            42
JAXB XML Schema to Java Mapping




                                  43
Client Side Programming




                          44
Java SE Client Side Programming

â€Ē   Point a tool (NetBeans or wsimport) at the WSDL
    for the service
       wsimport http://example.org/Calculator.wsdl
â€Ē    Generate annotated classes and interfaces
â€Ē    Call new on the service class
â€Ē    Get a proxy using a get<ServiceName>Port method
â€Ē    Invoke any remote operations


                                                       45
Example : Java SE-Based Client

CalculatorService svc = new CalculatorService();
Calculator proxy = svc.getCalculatorPort();
int answer = proxy.add(35, 7);




â€Ē No need to use factories
â€Ē The code is fully portable
â€Ē XML is completely hidden from programmer



                                                   46
Java EE Client Side Programming

â€Ē   Point a tool (NetBeans or wsimport) at the WSDL
    for the service
    wsimport http://example.org/calculator.wsdl
â€Ē   Generate annotated classes and interfaces
â€Ē   Inject a @WebServiceReference of the
    appropriate type
â€Ē   No JNDI needed
â€Ē   Invoke any remote operations
                                                      47
Example : Java EE-Based Client

@Stateless
public class MyBean {
   // Resource injection
   @WebServiceRef(CalculatorService.class)
   Calculator proxy;

    public int mymethod() {
       return proxy.add(35, 7);
}




                                             48
Client Side




              49
Annotations Used in JAX-WS
â€Ē JSR 181: Web Services Metadata for the
  Java Platform
â€Ē JSR 222: Java Architecture for XML
  Binding (JAXB)
â€Ē JSR 224: Java API for XML Web Services
  (JAX-WS)
â€Ē JSR 250: Common Annotations for the
  Java Platform
@WebService
â€Ē Marks a Java class as implementing a
  Web Service, or a Java interface as
  defining a Web Service interface.
â€Ē Attributes
  > endpointInterface
  > name
  > portName
  > serviceName
  > targetNamespace
  > wsdlLocation
@WebMethod
â€Ē Customizes a method that is exposed as
  a Web Service operation
â€Ē The method is not required to throw
  java.rmi.RemoteException.
â€Ē Attributes
 > action
 > exclude
 > operationName
@WebParam
â€Ē Customizes the mapping of an individual
  parameter to a Web Service message
  part and XML element.
â€Ē Attributes
  > header
  > mode
  > name
  > partName
  > targetNamespace
@WebResult
â€Ē Customizes the mapping of the return
  value to a WSDL part and XML element.
â€Ē Attributes
 >   header
 >   name
 >   partName
 >   targetNamespace
JAX-WS - Provider
â€Ē Web Service endpoints may choose to work at
  the XML message level by implementing the
  Provider interface.
â€Ē The endpoint accesses the message or
  message payload using this low-level, generic
  API
â€Ē Implement one of the following
  > Provider<Source>
  > Provider<SOAPMessage>
  > Provider<DataSource>
JAX-WS - Provider
JAX-WS - Dispatch
â€Ē Web service client applications may choose to
  work at the XML message level by using the
  Dispatch<T> APIs.
â€Ē The javax.xml.ws.Dispatch<T> interface
  provides support for the dynamic invocation of
  service endpoint operations.
â€Ē Similar to Provider on server side
JAX-WS - Dispatch
Resources
 Some contents are borrowed from the presentation
  slides of Sang Shin, Javaâ„Ē Technology Evangelist,
  Sun Microsystems, Inc.
 Web Services and Java, Elsa Estevez, Tomasz
  Janowski and Gabriel Oteniya, UNU-IIST, Macau




                                                      59
Thank you

   thananum@gmail.com
www.facebook.com/imcinstitute
   www.imcinstitute.com



                                60

More Related Content

What's hot (20)

PPT
Using Java to implement SOAP Web Services: JAX-WS
Katrien Verbert
 
PDF
Introduction to Node.js
Rob O'Doherty
 
PDF
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
Edureka!
 
PPT
Understanding REST
Nitin Pande
 
PPTX
Spring Web MVC
zeeshanhanif
 
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
PDF
REST API and CRUD
Prem Sanil
 
PDF
Expressjs
Yauheni Nikanovich
 
PPTX
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
PDF
Web Services (SOAP, WSDL, UDDI)
Peter R. Egli
 
PPT
Node.js Express Framework
TheCreativedev Blog
 
PDF
[Webinar]: Working with Reactive Spring
Knoldus Inc.
 
PPTX
Local storage
Adam Crabtree
 
PDF
Cloud Migration ęģž Modernization ė„ ėœ„í•œ 30氀맀 ė•„ėī디ė–ī-박ęļ°íĨ, AWS Migrations Specialist...
Amazon Web Services Korea
 
PPTX
Enterprise java unit-1_chapter-2
sandeep54552
 
PPSX
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
PDF
Microservices Design Patterns | Edureka
Edureka!
 
PPTX
Microservices Architecture Part 2 Event Sourcing and Saga
Araf Karsh Hamid
 
PDF
AWS ë„ĪíŠļė›ŒíŽ ëģīė•ˆė„ ėœ„í•œ ęģ„ėļĩëģ„ ëģīė•ˆ ęĩŽė„ą ëŠĻëē” ė‚ŽëĄ€ – ėĄ°ėīė •, AWS 놔ëĢĻė…˜ė͈ ė•„í‚Ī텍íŠļ:: AWS ė˜Ļ띞ėļ ėīëēĪíŠļ – íīëžėš°ë“œ ëģīė•ˆ íŠđė§‘
Amazon Web Services Korea
 
Using Java to implement SOAP Web Services: JAX-WS
Katrien Verbert
 
Introduction to Node.js
Rob O'Doherty
 
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
Edureka!
 
Understanding REST
Nitin Pande
 
Spring Web MVC
zeeshanhanif
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
Introduction Node.js
Erik van Appeldoorn
 
REST API and CRUD
Prem Sanil
 
Expressjs
Yauheni Nikanovich
 
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
Web Services (SOAP, WSDL, UDDI)
Peter R. Egli
 
Node.js Express Framework
TheCreativedev Blog
 
[Webinar]: Working with Reactive Spring
Knoldus Inc.
 
Local storage
Adam Crabtree
 
Cloud Migration ęģž Modernization ė„ ėœ„í•œ 30氀맀 ė•„ėī디ė–ī-박ęļ°íĨ, AWS Migrations Specialist...
Amazon Web Services Korea
 
Enterprise java unit-1_chapter-2
sandeep54552
 
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
Microservices Design Patterns | Edureka
Edureka!
 
Microservices Architecture Part 2 Event Sourcing and Saga
Araf Karsh Hamid
 
AWS ë„ĪíŠļė›ŒíŽ ëģīė•ˆė„ ėœ„í•œ ęģ„ėļĩëģ„ ëģīė•ˆ ęĩŽė„ą ëŠĻëē” ė‚ŽëĄ€ – ėĄ°ėīė •, AWS 놔ëĢĻė…˜ė͈ ė•„í‚Ī텍íŠļ:: AWS ė˜Ļ띞ėļ ėīëēĪíŠļ – íīëžėš°ë“œ ëģīė•ˆ íŠđė§‘
Amazon Web Services Korea
 

Viewers also liked (20)

PDF
Java Web Services
Jussi Pohjolainen
 
PPTX
XML, DTD & XSD Overview
Pradeep Rapolu
 
PDF
Scalable JavaScript Application Architecture
Nicholas Zakas
 
PDF
Javascript Best Practices
Christian Heilmann
 
PDF
Java Web Services [3/5]: WSDL, WADL and UDDI
IMC Institute
 
PPT
Hacking Web 2.0 - Defending Ajax and Web Services [HITB 2007 Dubai]
Shreeraj Shah
 
PPTX
Writing simple web services in java using eclipse editor
Santosh Kumar Kar
 
PDF
Restful Web Services
Angelin R
 
PDF
Web Services Tutorial
Lorna Mitchell
 
PPT
Web Service Presentation
guest0df6b0
 
PDF
Web Services PHP Tutorial
Lorna Mitchell
 
PPTX
Testing web services
Taras Lytvyn
 
PPTX
Spring database - part2
Santosh Kumar Kar
 
PPTX
Springs
Santosh Kumar Kar
 
PPT
Java Web Service - Summer 2004
Danny Teng
 
PDF
Jaxp Xmltutorial 11 200108
nit Allahabad
 
PPT
Simple API for XML
guest2556de
 
PPTX
Spring transaction part4
Santosh Kumar Kar
 
PDF
Java Web Services [2/5]: Introduction to SOAP
IMC Institute
 
Java Web Services
Jussi Pohjolainen
 
XML, DTD & XSD Overview
Pradeep Rapolu
 
Scalable JavaScript Application Architecture
Nicholas Zakas
 
Javascript Best Practices
Christian Heilmann
 
Java Web Services [3/5]: WSDL, WADL and UDDI
IMC Institute
 
Hacking Web 2.0 - Defending Ajax and Web Services [HITB 2007 Dubai]
Shreeraj Shah
 
Writing simple web services in java using eclipse editor
Santosh Kumar Kar
 
Restful Web Services
Angelin R
 
Web Services Tutorial
Lorna Mitchell
 
Web Service Presentation
guest0df6b0
 
Web Services PHP Tutorial
Lorna Mitchell
 
Testing web services
Taras Lytvyn
 
Spring database - part2
Santosh Kumar Kar
 
Java Web Service - Summer 2004
Danny Teng
 
Jaxp Xmltutorial 11 200108
nit Allahabad
 
Simple API for XML
guest2556de
 
Spring transaction part4
Santosh Kumar Kar
 
Java Web Services [2/5]: Introduction to SOAP
IMC Institute
 
Ad

Similar to Java Web Services [4/5]: Java API for XML Web Services (20)

PPT
15376199.ppt
abdulbasetalselwi
 
PPTX
Jax ws
F K
 
PPTX
Ntg web services
Farag Zakaria
 
PPTX
Java Web services
Sujit Kumar
 
PDF
Rest web service
Hamid Ghorbani
 
PPT
java-webservices introduction ppt for beginners
VasantPrasad
 
PPTX
Java Web services
vpulec
 
PPS
Deawsj 7 ppt-2_a
Niit Care
 
PPT
ghfghg
hoefo
 
DOC
Web services soap rest training
FuturePoint Technologies
 
DOCX
Web services in java
maabujji
 
PPT
jkljklj
hoefo
 
DOCX
Web services Concepts
pasam suresh
 
PDF
Lecture 7 Web Services JAX-WS & JAX-RS
Fahad Golra
 
PDF
Web Services Training in Noida
Tech Mentro
 
PPT
Reusing Existing Java EE Applications from SOA Suite 11g
Guido Schmutz
 
PPTX
Web services
smitha273566
 
PDF
JAX-RS Creating RESTFul services
Ludovic Champenois
 
PPTX
Soap and restful webservice
Dong Ngoc
 
PDF
Java EE 6 workshop at Dallas Tech Fest 2011
Arun Gupta
 
15376199.ppt
abdulbasetalselwi
 
Jax ws
F K
 
Ntg web services
Farag Zakaria
 
Java Web services
Sujit Kumar
 
Rest web service
Hamid Ghorbani
 
java-webservices introduction ppt for beginners
VasantPrasad
 
Java Web services
vpulec
 
Deawsj 7 ppt-2_a
Niit Care
 
ghfghg
hoefo
 
Web services soap rest training
FuturePoint Technologies
 
Web services in java
maabujji
 
jkljklj
hoefo
 
Web services Concepts
pasam suresh
 
Lecture 7 Web Services JAX-WS & JAX-RS
Fahad Golra
 
Web Services Training in Noida
Tech Mentro
 
Reusing Existing Java EE Applications from SOA Suite 11g
Guido Schmutz
 
Web services
smitha273566
 
JAX-RS Creating RESTFul services
Ludovic Champenois
 
Soap and restful webservice
Dong Ngoc
 
Java EE 6 workshop at Dallas Tech Fest 2011
Arun Gupta
 
Ad

More from IMC Institute (20)

PDF
āļ™āļīāļ•āļĒāļŠāļēāļĢ Digital Trends āļ‰āļšāļąāļšāļ—āļĩāđˆ 14
IMC Institute
 
PDF
Digital trends Vol 4 No. 13 Sep-Dec 2019
IMC Institute
 
PDF
āļšāļ—āļ„āļ§āļēāļĄ The evolution of AI
IMC Institute
 
PDF
IT Trends eMagazine Vol 4. No.12
IMC Institute
 
PDF
āđ€āļžāļĢāļēāļ°āđ€āļŦāļ•āļļāđƒāļ” Digitization āđ„āļĄāđˆāļ•āļ­āļšāđ‚āļˆāļ—āļĒāđŒ Digital Transformation
IMC Institute
 
PDF
IT Trends 2019: Putting Digital Transformation to Work
IMC Institute
 
PDF
āļĄāļđāļĨāļ„āđˆāļēāļ•āļĨāļēāļ”āļ”āļīāļˆāļīāļ—āļąāļĨāđ„āļ—āļĒ 3 āļ­āļļāļ•āļŠāļēāļŦāļāļĢāļĢāļĄ
IMC Institute
 
PDF
IT Trends eMagazine Vol 4. No.11
IMC Institute
 
PDF
āđāļ™āļ§āļ—āļēāļ‡āļāļēāļĢāļ—āļģ Digital transformation
IMC Institute
 
PDF
āļšāļ—āļ„āļ§āļēāļĄ The New Silicon Valley
IMC Institute
 
PDF
āļ™āļīāļ•āļĒāļŠāļēāļĢ IT Trends āļ‚āļ­āļ‡ IMC Institute āļ‰āļšāļąāļšāļ—āļĩāđˆ 10
IMC Institute
 
PDF
āđāļ™āļ§āļ—āļēāļ‡āļāļēāļĢāļ—āļģ Digital transformation
IMC Institute
 
PDF
The Power of Big Data for a new economy (Sample)
IMC Institute
 
PDF
āļšāļ—āļ„āļ§āļēāļĄ Robotics āđāļ™āļ§āđ‚āļ™āđ‰āļĄāđƒāļŦāļĄāđˆāļŠāļđāđˆāļšāļĢāļīāļāļēāļĢāđ€āļ‰āļžāļēāļ°āļ—āļēāļ‡
IMC Institute
 
PDF
IT Trends eMagazine Vol 3. No.9
IMC Institute
 
PDF
Thailand software & software market survey 2016
IMC Institute
 
PPTX
Developing Business Blockchain Applications on Hyperledger
IMC Institute
 
PDF
Digital transformation @thanachart.org
IMC Institute
 
PDF
āļšāļ—āļ„āļ§āļēāļĄ Big Data āļˆāļēāļāļšāļĨāđ‡āļ­āļ thanachart.org
IMC Institute
 
PDF
āļāļĨāļĒāļļāļ—āļ˜āđŒ 5 āļ”āđ‰āļēāļ™āļāļąāļšāļāļēāļĢāļ—āļģ Digital Transformation
IMC Institute
 
āļ™āļīāļ•āļĒāļŠāļēāļĢ Digital Trends āļ‰āļšāļąāļšāļ—āļĩāđˆ 14
IMC Institute
 
Digital trends Vol 4 No. 13 Sep-Dec 2019
IMC Institute
 
āļšāļ—āļ„āļ§āļēāļĄ The evolution of AI
IMC Institute
 
IT Trends eMagazine Vol 4. No.12
IMC Institute
 
āđ€āļžāļĢāļēāļ°āđ€āļŦāļ•āļļāđƒāļ” Digitization āđ„āļĄāđˆāļ•āļ­āļšāđ‚āļˆāļ—āļĒāđŒ Digital Transformation
IMC Institute
 
IT Trends 2019: Putting Digital Transformation to Work
IMC Institute
 
āļĄāļđāļĨāļ„āđˆāļēāļ•āļĨāļēāļ”āļ”āļīāļˆāļīāļ—āļąāļĨāđ„āļ—āļĒ 3 āļ­āļļāļ•āļŠāļēāļŦāļāļĢāļĢāļĄ
IMC Institute
 
IT Trends eMagazine Vol 4. No.11
IMC Institute
 
āđāļ™āļ§āļ—āļēāļ‡āļāļēāļĢāļ—āļģ Digital transformation
IMC Institute
 
āļšāļ—āļ„āļ§āļēāļĄ The New Silicon Valley
IMC Institute
 
āļ™āļīāļ•āļĒāļŠāļēāļĢ IT Trends āļ‚āļ­āļ‡ IMC Institute āļ‰āļšāļąāļšāļ—āļĩāđˆ 10
IMC Institute
 
āđāļ™āļ§āļ—āļēāļ‡āļāļēāļĢāļ—āļģ Digital transformation
IMC Institute
 
The Power of Big Data for a new economy (Sample)
IMC Institute
 
āļšāļ—āļ„āļ§āļēāļĄ Robotics āđāļ™āļ§āđ‚āļ™āđ‰āļĄāđƒāļŦāļĄāđˆāļŠāļđāđˆāļšāļĢāļīāļāļēāļĢāđ€āļ‰āļžāļēāļ°āļ—āļēāļ‡
IMC Institute
 
IT Trends eMagazine Vol 3. No.9
IMC Institute
 
Thailand software & software market survey 2016
IMC Institute
 
Developing Business Blockchain Applications on Hyperledger
IMC Institute
 
Digital transformation @thanachart.org
IMC Institute
 
āļšāļ—āļ„āļ§āļēāļĄ Big Data āļˆāļēāļāļšāļĨāđ‡āļ­āļ thanachart.org
IMC Institute
 
āļāļĨāļĒāļļāļ—āļ˜āđŒ 5 āļ”āđ‰āļēāļ™āļāļąāļšāļāļēāļĢāļ—āļģ Digital Transformation
IMC Institute
 

Recently uploaded (20)

PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Kit-Works Team Study_20250627_í•œë‹Žë§Œė—ë§Œë“ ė‚Žë‚īė„œëđ„ėŠĪí‚Ī링(ė–‘ë‹Īėœ—).pdf
Wonjun Hwang
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Kit-Works Team Study_20250627_í•œë‹Žë§Œė—ë§Œë“ ė‚Žë‚īė„œëđ„ėŠĪí‚Ī링(ė–‘ë‹Īėœ—).pdf
Wonjun Hwang
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 

Java Web Services [4/5]: Java API for XML Web Services

  • 1. Topic 4 Java API for XML Web Services Assoc.Prof. Dr. Thanachart Numnonda www.imcinstitute.com August 2010
  • 2. Agenda ïŪ Java APIs for Web Services ïŪ JAX-RPC ïŪ JAX-WS 2
  • 3. Java APIs for Web Services 3
  • 4. JWSDP ïŪ Java Web Services Development Pack (JWSDP) is a free software development kit (SDK) for developing Web Services ïŪ JWSDP has been replaced by GlassFish and WSIT and several components are in Java SE 6. ïŪ JWSDP APIs ïŪ Java API for XML Processing (JAXP), v 1.3 ïŪ Java Architecture for XML Binding (JAXB), v 1.0 and 2.0 ïŪ JAX-RPC v 1.1 ïŪ JAX-WS v 2.0 ïŪ SAAJ (SOAP with Attachments API for Java) ïŪ Java API for XML Registries (JAXR) 4
  • 5. Java API for XML Processing (JAXP) â€Ē JAXP enables applications to parse, validate and transform XML documents. â€Ē Java developers can invoke â€Ē SAX parser â€Ē DOM parser â€Ē The main JAXP APIs are defined in the javax.xml.parsers package â€Ē SAXParserFactory â€Ē DocumentBuilderFactory 5
  • 6. Java API for XML Binding (JAXB) â€Ē JAXB allows Java developers to access and process XML data without having to know XML or XML processing. â€Ē JAXB is a Java technology that enables you to generate Java classes from XML schemas by means of a JAXB binding compiler. â€Ē unmarshalling â€Ē XML instance documents into Java content trees â€Ē marshalling â€Ē Java content trees back into XML instance documents. 6
  • 7. SAAJ (SOAP with Attachments API for Javaâ„Ē) â€Ē SAAJ provides a convenient API for constructing and sending SOAP messages without having to directly create the XML yourself. â€Ē SAAJ was originally part of the Java API for XML Messaging (JAXM) Separated out from JAXM 1.0 into JAXM 1.1 and SAAJ 1.1 (SAAJ 1.3 (Java EE 5)) 7
  • 8. JAXR â€Ē Standard Java API for performing registry operations over diverse set of registries Web service publication & discovery â€Ē A unified information model for describing business registry content â€Ē Provides multi-layered API abstractions Level 0: for UDDI Level 1: for ebXML registry/repository 8
  • 9. JAX-RPC â€Ē XML data types to/from Java types mapping â€Ē SOAP Message Handler framework â€Ē WSDL to/from Java mapping â€Ē Servlet-based Web service endpoint model â€Ē JAX-RPC Client Programming Models â€Ē Extensible type mapping 9
  • 10. JAX-WS (JAX-RPC 2.0) â€Ē New handler framework â€Ē Metadata-based Web services â€Ē Operational style improvement â€Ē Asynchronous Web services â€Ē Support for non-HTTP transport â€Ē Interoperable attachments (as part of WS-I) â€Ē Secure Web services (as part of Security) 10
  • 11. JAXM â€Ē JAXM is not part of Java EE 5 â€Ē JAXM-based asynchronous messaging on Java EE 5 is supported via Message-driven Bean (MDB) in EJB 3 can receive both JMS and JAXM message types Connector 1.5 allows pluggability of various types message providers (JAXM provider and JMS provider) 11
  • 12. Java APIs for Web Services Protocols ïŪ SOAP ïŪ JAXM 1.0 (JSR 67), SAAJ ïŪ JAX-RPC => JAX-WS 2.0 (JSR 224) ïŪ WSDL ïŪ JAX-RPC => JAX-WS 2.0 (JSR 224) ïŪ UDDI ïŪ JAXR 1.0 (JSR 93) 12
  • 14. JAX-RPC 14
  • 15. Remote Procedure Call (RPC) Request Response Client System Server System ïŪ RPC, COM, CORBA, RMI:  Synchronous communication: calling process blocks until there is a response  More tightly coupled (than non-RPC model): client must find recipients and know method and its arguments  Non persistent
  • 16. Remote Procedure Calls Client Interface Interface Servant Stub Skeleton Run Time Protocol Run Time  Common Interface between client and Server  Stub for client, Skeleton/Tie for server  On-the-wire protocol needs to be agreed upon
  • 17. RPC Example – Java RMI <<Interface>> Java Remote Interface rmic compiler Client Remote Object Implementation RMI Client RMI Server Stub Skeleton Java Remote Method Protocol (JRMP) is On-the-wire protocol
  • 18. RPC Example - JAX-RPC
  • 19. Common Interface ïŪ Service is described in IDL (Interface Description Language)  IDL ofCORBA service  Java RMI interface in RMI (Language specific)  WSDL for Web service ïŪ Used by tools to statically or dynamically generate and/or configure interfaces, proxies, and ties in a network technology specific environment
  • 20. What is JAX-RPC? ïŪ Javaâ„Ē API for XML-based RPC ïŪ Web Services operations are performed by exchanging SOAP 1.1 messages ïŪ Services are described using WSDL â€Ē WSDL is the contract between service provider and client (only contract needed) ïŪ Web service endpoints and clients use JAX-RPC programming model ïŪ Key technology for Web Services in the J2EE 1.4 platform
  • 21. JAX-RPC Design Goals ïŪ Easy to use programming model â€Ē For both defining & using a service ïŪ Hides all the plumbing â€Ē You don't have to create SOAP messages yourself ïŪ SOAP and WSDL-based interoperability â€Ē Interoperate with any SOAP 1.1 compliant peers ïŪ Extensibility and Modularity â€Ē Support new versions of XML specification, i.e. SOAP 1.2 and beyond â€Ē Message handler architecture
  • 22. JAX-RPC Architecture JAX-RPC JAX-RPC Client WSDL Document Service Endpoint Generated JavaïƒŊWSDL WSDLïƒģJava Code Container Container Client-side JAX-RPC Server-side JAX-RPC Runtime System Runtime System SOAP HTTP
  • 23. JAX-RPC Runtime System ïŪ Core of a JAX-RPC implementation: â€Ē Library that provides runtime services for JAX-RPC mechanisms â€Ē Implements some of the JAX-RPC APIs ïŪ Client side: â€Ē Can be implemented over J2SEâ„Ē, J2EEâ„Ē or J2MEâ„Ē platforms ïŪ Server-side: â€Ē J2EE 1.3 or 1.4 Containers: EJBâ„Ē or Servlet
  • 24. Developing a Web Service Interfaces (java.rmi.Remote type) Must follow JAX-RPC conventions Implementation classes Servlet-based endpoint model Optional handler and serializer classes tool WSDL Service contract Packaged application (war file)
  • 25. JAX-RPC : Web Service Endpoint JAX-RPC Service Endpoint WSDL<-->Java WSDL Document Container Server-Side JAX-RPC Runtime System SOAP HTTP
  • 26. JAX-WS 26
  • 27. Quick overview of JAX-WS ïŪ Easy way to use Java API for XML Web Services ïŪ Replace JAX-RPC ïŪ Just add @annotation to POJO ïŪ XML Descriptor free programming ïŪ Layer architecture ïŪ SOAP 1.2 (Document/Literal) ïŪ Use JAXB for data binding ïŪ Protocol and transport independence ïŪ Part of Java SE6 and Java EE 5 Platform 27
  • 29. What Does It Mean? â€Ē Upper layer uses annotations extensively â€Ē Easy to use â€Ē Great toolability â€Ē Fewer generated classes â€Ē Lower layer is more traditional â€Ē API-based â€Ē For advanced scenarios â€Ē Most application will use the upper layer only â€Ē Either way, portability is guaranteed 29
  • 30. Two ways to create a Web Service â€Ē Starting from a WSDL file > Generate classes using wsimport (=> xjc) > WS interface > WS implementation skeleton class > Implement WS interface > Build and deploy â€Ē Starting from a Java class (POJO) > Annotate POJO > Build and deploy > WSDL file generated automatically 30
  • 31. Start with a Java Class 31
  • 32. Server-Side Programming Model: POJO 1 Write a POJO implementing the service 2 Add @WebService annotation to it 3 Build and Deploy the application WSDL is automatically generated at runtime 1 Point your clients at the WSDL e.g. http://myserver/myapp/MyService?WSDL 32
  • 33. Example 1: Servlet-Based Endpoint @WebService public class Calculator { public int add( int a, int b) { return a + b; } } â€Ē @WebService annotation â€Ē All public methods become web service operations â€Ē WSDL/Schema generated automatically â€Ē Default values are used 33
  • 34. Service Description Default Mapping â€Ē Java mapping => WSDL 34
  • 35. Example 2: EJB-Based Endpoint @WebService @Stateless public class Calculator { public int add( int a, int b) { return a + b; } } â€Ē It’s a regular EJB 3.0 component, so it can use any EJB features > Transactions, security, interceptors... 35
  • 36. Customizing through Annotations @WebService(name=”CreditRatingService”, targetNamespace=”http://example.org”) public class CreditRating { @WebMethod(operationName=”getCreditScore”) public Score getCredit( @WebParam(name=”customer”) Customer c) { // ... implementation code ... } } 36
  • 37. Start with a WSDL file 37
  • 38. Generating an interface from WSDL â€Ē WSDL => Java generation 38
  • 39. Implementing a Web Service from a Generated Interface 39
  • 40. Server Side Web Service 40
  • 41. JAX-WS uses JAXB for Data Binding 41
  • 42. add() Parameter : Example 42
  • 43. JAXB XML Schema to Java Mapping 43
  • 45. Java SE Client Side Programming â€Ē Point a tool (NetBeans or wsimport) at the WSDL for the service wsimport http://example.org/Calculator.wsdl â€Ē Generate annotated classes and interfaces â€Ē Call new on the service class â€Ē Get a proxy using a get<ServiceName>Port method â€Ē Invoke any remote operations 45
  • 46. Example : Java SE-Based Client CalculatorService svc = new CalculatorService(); Calculator proxy = svc.getCalculatorPort(); int answer = proxy.add(35, 7); â€Ē No need to use factories â€Ē The code is fully portable â€Ē XML is completely hidden from programmer 46
  • 47. Java EE Client Side Programming â€Ē Point a tool (NetBeans or wsimport) at the WSDL for the service wsimport http://example.org/calculator.wsdl â€Ē Generate annotated classes and interfaces â€Ē Inject a @WebServiceReference of the appropriate type â€Ē No JNDI needed â€Ē Invoke any remote operations 47
  • 48. Example : Java EE-Based Client @Stateless public class MyBean { // Resource injection @WebServiceRef(CalculatorService.class) Calculator proxy; public int mymethod() { return proxy.add(35, 7); } 48
  • 50. Annotations Used in JAX-WS â€Ē JSR 181: Web Services Metadata for the Java Platform â€Ē JSR 222: Java Architecture for XML Binding (JAXB) â€Ē JSR 224: Java API for XML Web Services (JAX-WS) â€Ē JSR 250: Common Annotations for the Java Platform
  • 51. @WebService â€Ē Marks a Java class as implementing a Web Service, or a Java interface as defining a Web Service interface. â€Ē Attributes > endpointInterface > name > portName > serviceName > targetNamespace > wsdlLocation
  • 52. @WebMethod â€Ē Customizes a method that is exposed as a Web Service operation â€Ē The method is not required to throw java.rmi.RemoteException. â€Ē Attributes > action > exclude > operationName
  • 53. @WebParam â€Ē Customizes the mapping of an individual parameter to a Web Service message part and XML element. â€Ē Attributes > header > mode > name > partName > targetNamespace
  • 54. @WebResult â€Ē Customizes the mapping of the return value to a WSDL part and XML element. â€Ē Attributes > header > name > partName > targetNamespace
  • 55. JAX-WS - Provider â€Ē Web Service endpoints may choose to work at the XML message level by implementing the Provider interface. â€Ē The endpoint accesses the message or message payload using this low-level, generic API â€Ē Implement one of the following > Provider<Source> > Provider<SOAPMessage> > Provider<DataSource>
  • 57. JAX-WS - Dispatch â€Ē Web service client applications may choose to work at the XML message level by using the Dispatch<T> APIs. â€Ē The javax.xml.ws.Dispatch<T> interface provides support for the dynamic invocation of service endpoint operations. â€Ē Similar to Provider on server side
  • 59. Resources  Some contents are borrowed from the presentation slides of Sang Shin, Javaâ„Ē Technology Evangelist, Sun Microsystems, Inc.  Web Services and Java, Elsa Estevez, Tomasz Janowski and Gabriel Oteniya, UNU-IIST, Macau 59
  • 60. Thank you [email protected] www.facebook.com/imcinstitute www.imcinstitute.com 60