SlideShare a Scribd company logo
Java web services using JAX-
                    WS




Speaker Name Lalit Mohan Chandra Bhatt
Company Name Crayom Engineering Services
Scope
•   Understanding how JAX-WS can be used
    to implement SOAP based web services
    both at server and client side.
Are webservices hard !
    Dave Podnar's Five Stages of Dealing with Web Services


●
    Denial - It's Simple Object Access Protocol, right?
●
    Over Involvement - OK, I'll read the SOAP, WSDL, WS-I BP, JAX-RPC,
    SAAJ, JAX-P... specs. next, I'll check the Wiki and finally follow an example
    showing service and client sides.
●
    Anger - I can't believe those #$%&*@s made it so difficult!
●
    Guilt - Everyone is using Web Services, it must be me, I must be missing
    something.
●
    Acceptance - It is what it is, Web Services aren't simple or easy
Jargons Jargons
             XML XSD
         XSLT Xpath JAXP
        SAX DOM JAXB StaX
         SOAP WSDL UDDI
      JAX-RPC JAX-WS JAX-RS
           SAAJ WS* BP
            Axis Metro
               ESB
               SOA
Webservice
                                                    Invoked initially




          Web service details – WSDL on XML

                Request - SOAP on XML                         Server
 Client
                Reposnse – SOAP on XML




                                   Invoked whenever message
                                       exchange happens
Webservice – JAX-WS way
Plain old Java Object (POJO) can be easily exposed as
●


web service.
●
    Annotation driven
●
    Data binding through JAXB
●
    Server Independent
JAX-WS


         Demo
JAX-WS – Servlet Way
●
    Write the class
●
    Annotate
●
    Register in web.xml
●
    Deploy – The server runtime will
    ➢
      Generate and publish WSDL.
    ➢
      Map SOAP request to a Java method invocation.
    ➢
      Translate method return into a SOAP response.
JAX-WS – Servlet Way
@WebService
public class TemperatureConverter {

    @WebMethod
    public double celsiusToFarenheit(double temp){
      ...
    }

    @WebMethod
    public double farenheitToCelsius(double temp){
      ...
    }

}
JAX-WS – Servlet Way
<servlet>
   <servlet-name>tempConv</servlet-name>
   <servlet-class>
       com.lalit.TemperatureConverter
   </servlet-class>
</servlet>


<servlet-mapping>
   <servlet-name>tempConv</servlet-name>
   <url-pattern>/tempConv</url-pattern>
</servlet-mapping>
JAX-WS Servlet Way
            1. Get WSDL
                             WSDL Published
                               On Server


          2. SOAP request              3                 4                    5                      6
                                                                 Handler




                                                                                      JAXB Mapping
                                                                  Chain




                                                                                                         Java endpoint
                                                                                                          Web Service
                                            Dispatcher
Clientt

                            Endpoint
                            Listener
                                                                   SOAP
          11. SOAP resp                10                    9      Fault         8                  7
                                                                 Processing
JAX-WS           EJB 3.0 way
Annotate
●




Deploy ejb jar
●
JAX-WS – EJB 3.0 way
@Stateless
@WebService
public class TemperatureConverter {

//Rest code remains same.
JAX-WS                –     JavaSE Endpoint
●
    Starting Java 6
●
    Generate the artifact using wsgen tool.
●
    wsgen tool generates JAXB mapped classes
●
    Use embedded HttpServer to deploy the webservice
JAX-WS – JavaSE Endpoint
public static void main(String[] args) {
   TemperatureConverter tc= new
                     TemperatureConverter();

          //Java comes with an embedded Http server
          //which is used to host the service
          Endpoint endpoint = Endpoint.publish
    ("http://localhost:8080/tempConv", tc);

          //Keeping commented, keeps the server running
          /*endpoint.stop();*/
      }
}
JAX-WS –                   Client side
●
    Generate artifact using wsimport pointing to WSDL
●
 wsimport generates JAXB binding classes and service
endpoint
●
    Call the web service using service end point
JAX-WS              –    Client side
//Make the instance of service class
TemperatureConverterService service =
              new TemperatureConverterService();

//Get port to invoke webservice
TemperatureConverter port =
      service.getPort
            (TemperatureConverter.class);

//Call the web service.
double fahr = port.celsiusToFarenheit(100);
JAX-WS - start from WSDL
●
    JAX-WS supports start from WSDL approach

@WebService(name = "TemperatureConvertor",
endpointInterface="com.crayom.ws.TemperatureConvertor",
targetNamespace = "http://ws.crayom.com/",
wsdlLocation = "WEB-INF/TemperatureConvertorDocStyle.wsdl")
public class TemperatureConvertorService implements
TemperatureConvertor {
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
@WebServiceProvider(serviceName = "TempConvProvider",
    portName="TempConvPort",
    targetNamespace = "http://www.crayom.com/om",
    wsdlLocation="WEB-INF/wsdl/TempConvProvider.wsdl")
@ServiceMode(value=Service.Mode.PAYLOAD)
public class TempConvProvider implements Provider<Source>{

    public Source invoke(Source request) {
        …
        return resp;                                  Provide WSDL
    }                                                    yourself

}
                PAYLOAD gives the body of message.
               MESSAGE will give whole SOAP Message
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
Service service = Service.create(url, serviceName);

Dispatch<Source> sourceDispatch =
     service.createDispatch(portQName,
                              Source.class,
                      Service.Mode.PAYLOAD);
//request is a XML which is put into SOAP payload
 StreamSource streamSource = new StreamSource
           (new StringReader(request));

Source result = sourceDispatch.invoke(streamSource);
JAX-WS - Apart from this
●
 JAX-WS provides support for SOAP fault handling in terms of
exceptions.
●
 JAX-WS supports handlers both on client and server side ,
which can process SOAP headers. SOAP headers are used to
build Quality of services (QOS).
●
    JAX-WS supports asynchronous communication
Thank you

More Related Content

PPTX
Rest assured
PDF
Java Web Services [4/5]: Java API for XML Web Services
PPTX
Web services SOAP
PPTX
Introduction to Node.js
PPT
Automation testing
PDF
Automate REST API Testing
Rest assured
Java Web Services [4/5]: Java API for XML Web Services
Web services SOAP
Introduction to Node.js
Automation testing
Automate REST API Testing

What's hot (20)

PDF
Google Web Toolkit
PPTX
JSON: The Basics
PPT
Eclipse IDE
PPT
Introduction to VoiceXml and Voice Web Architecture
PDF
Flutter state management from zero to hero
PPTX
Laravel overview
PDF
A Basic Django Introduction
PPTX
Spring boot
PPT
Using Java to implement SOAP Web Services: JAX-WS
PPTX
Introduction to React JS
PPTX
Progressive Web App
PPSX
JDBC: java DataBase connectivity
PPT
PPT
Ppt of soap ui
PPTX
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
PDF
Spring Framework - AOP
PPT
Understanding REST
PPTX
Presentation on Core java
PPTX
Spring boot Introduction
Google Web Toolkit
JSON: The Basics
Eclipse IDE
Introduction to VoiceXml and Voice Web Architecture
Flutter state management from zero to hero
Laravel overview
A Basic Django Introduction
Spring boot
Using Java to implement SOAP Web Services: JAX-WS
Introduction to React JS
Progressive Web App
JDBC: java DataBase connectivity
Ppt of soap ui
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Spring Framework - AOP
Understanding REST
Presentation on Core java
Spring boot Introduction
Ad

Similar to Java web services using JAX-WS (20)

PPTX
Jax ws
 
PDF
Java API for XML Web Services (JAX-WS)
PPTX
Ntg web services
PPT
java-webservices introduction ppt for beginners
PPTX
Java Web services
PDF
Web Services Training in Noida
DOCX
Web services Concepts
PDF
April 2010 - JBoss Web Services
PDF
JBossWS Project by Alessio Soldano
PPTX
Java Web services
PPTX
Web service- Guest Lecture at National Wokshop
PDF
SOAP-based Web Services
PPTX
Soap and restful webservice
PDF
Rest web service
PPT
15376199.ppt
PPTX
Webservices
PDF
Integration of Web Service Stacks in an Esb
PPT
Soap and Rest
ODP
SCDJWS 5. JAX-WS
PPTX
Web services - A Practical Approach
Jax ws
 
Java API for XML Web Services (JAX-WS)
Ntg web services
java-webservices introduction ppt for beginners
Java Web services
Web Services Training in Noida
Web services Concepts
April 2010 - JBoss Web Services
JBossWS Project by Alessio Soldano
Java Web services
Web service- Guest Lecture at National Wokshop
SOAP-based Web Services
Soap and restful webservice
Rest web service
15376199.ppt
Webservices
Integration of Web Service Stacks in an Esb
Soap and Rest
SCDJWS 5. JAX-WS
Web services - A Practical Approach
Ad

More from IndicThreads (20)

PPTX
Http2 is here! And why the web needs it
ODP
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
PPT
Go Programming Language - Learning The Go Lang way
PPT
Building Resilient Microservices
PPT
App using golang indicthreads
PDF
Building on quicksand microservices indicthreads
PDF
How to Think in RxJava Before Reacting
PPT
Iot secure connected devices indicthreads
PDF
Real world IoT for enterprises
PPT
IoT testing and quality assurance indicthreads
PPT
Functional Programming Past Present Future
PDF
Harnessing the Power of Java 8 Streams
PDF
Building & scaling a live streaming mobile platform - Gr8 road to fame
PPTX
Internet of things architecture perspective - IndicThreads Conference
PDF
Cars and Computers: Building a Java Carputer
PPTX
Scrap Your MapReduce - Apache Spark
PPT
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
PPTX
Speed up your build pipeline for faster feedback
PPT
Unraveling OpenStack Clouds
PPTX
Digital Transformation of the Enterprise. What IT leaders need to know!
Http2 is here! And why the web needs it
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Go Programming Language - Learning The Go Lang way
Building Resilient Microservices
App using golang indicthreads
Building on quicksand microservices indicthreads
How to Think in RxJava Before Reacting
Iot secure connected devices indicthreads
Real world IoT for enterprises
IoT testing and quality assurance indicthreads
Functional Programming Past Present Future
Harnessing the Power of Java 8 Streams
Building & scaling a live streaming mobile platform - Gr8 road to fame
Internet of things architecture perspective - IndicThreads Conference
Cars and Computers: Building a Java Carputer
Scrap Your MapReduce - Apache Spark
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Speed up your build pipeline for faster feedback
Unraveling OpenStack Clouds
Digital Transformation of the Enterprise. What IT leaders need to know!

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
cuic standard and advanced reporting.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Big Data Technologies - Introduction.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Understanding_Digital_Forensics_Presentation.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Big Data Technologies - Introduction.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I

Java web services using JAX-WS

  • 1. Java web services using JAX- WS Speaker Name Lalit Mohan Chandra Bhatt Company Name Crayom Engineering Services
  • 2. Scope • Understanding how JAX-WS can be used to implement SOAP based web services both at server and client side.
  • 3. Are webservices hard ! Dave Podnar's Five Stages of Dealing with Web Services ● Denial - It's Simple Object Access Protocol, right? ● Over Involvement - OK, I'll read the SOAP, WSDL, WS-I BP, JAX-RPC, SAAJ, JAX-P... specs. next, I'll check the Wiki and finally follow an example showing service and client sides. ● Anger - I can't believe those #$%&*@s made it so difficult! ● Guilt - Everyone is using Web Services, it must be me, I must be missing something. ● Acceptance - It is what it is, Web Services aren't simple or easy
  • 4. Jargons Jargons XML XSD XSLT Xpath JAXP SAX DOM JAXB StaX SOAP WSDL UDDI JAX-RPC JAX-WS JAX-RS SAAJ WS* BP Axis Metro ESB SOA
  • 5. Webservice Invoked initially Web service details – WSDL on XML Request - SOAP on XML Server Client Reposnse – SOAP on XML Invoked whenever message exchange happens
  • 6. Webservice – JAX-WS way Plain old Java Object (POJO) can be easily exposed as ● web service. ● Annotation driven ● Data binding through JAXB ● Server Independent
  • 7. JAX-WS Demo
  • 8. JAX-WS – Servlet Way ● Write the class ● Annotate ● Register in web.xml ● Deploy – The server runtime will ➢ Generate and publish WSDL. ➢ Map SOAP request to a Java method invocation. ➢ Translate method return into a SOAP response.
  • 9. JAX-WS – Servlet Way @WebService public class TemperatureConverter { @WebMethod public double celsiusToFarenheit(double temp){ ... } @WebMethod public double farenheitToCelsius(double temp){ ... } }
  • 10. JAX-WS – Servlet Way <servlet> <servlet-name>tempConv</servlet-name> <servlet-class> com.lalit.TemperatureConverter </servlet-class> </servlet> <servlet-mapping> <servlet-name>tempConv</servlet-name> <url-pattern>/tempConv</url-pattern> </servlet-mapping>
  • 11. JAX-WS Servlet Way 1. Get WSDL WSDL Published On Server 2. SOAP request 3 4 5 6 Handler JAXB Mapping Chain Java endpoint Web Service Dispatcher Clientt Endpoint Listener SOAP 11. SOAP resp 10 9 Fault 8 7 Processing
  • 12. JAX-WS EJB 3.0 way Annotate ● Deploy ejb jar ●
  • 13. JAX-WS – EJB 3.0 way @Stateless @WebService public class TemperatureConverter { //Rest code remains same.
  • 14. JAX-WS – JavaSE Endpoint ● Starting Java 6 ● Generate the artifact using wsgen tool. ● wsgen tool generates JAXB mapped classes ● Use embedded HttpServer to deploy the webservice
  • 15. JAX-WS – JavaSE Endpoint public static void main(String[] args) { TemperatureConverter tc= new TemperatureConverter(); //Java comes with an embedded Http server //which is used to host the service Endpoint endpoint = Endpoint.publish ("http://localhost:8080/tempConv", tc); //Keeping commented, keeps the server running /*endpoint.stop();*/ } }
  • 16. JAX-WS – Client side ● Generate artifact using wsimport pointing to WSDL ● wsimport generates JAXB binding classes and service endpoint ● Call the web service using service end point
  • 17. JAX-WS – Client side //Make the instance of service class TemperatureConverterService service = new TemperatureConverterService(); //Get port to invoke webservice TemperatureConverter port = service.getPort (TemperatureConverter.class); //Call the web service. double fahr = port.celsiusToFarenheit(100);
  • 18. JAX-WS - start from WSDL ● JAX-WS supports start from WSDL approach @WebService(name = "TemperatureConvertor", endpointInterface="com.crayom.ws.TemperatureConvertor", targetNamespace = "http://ws.crayom.com/", wsdlLocation = "WEB-INF/TemperatureConvertorDocStyle.wsdl") public class TemperatureConvertorService implements TemperatureConvertor {
  • 19. 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>.
  • 20. JAX-WS - Provider @WebServiceProvider(serviceName = "TempConvProvider", portName="TempConvPort", targetNamespace = "http://www.crayom.com/om", wsdlLocation="WEB-INF/wsdl/TempConvProvider.wsdl") @ServiceMode(value=Service.Mode.PAYLOAD) public class TempConvProvider implements Provider<Source>{ public Source invoke(Source request) { … return resp; Provide WSDL } yourself } PAYLOAD gives the body of message. MESSAGE will give whole SOAP Message
  • 21. 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 ●
  • 22. JAX-WS - Dispatch Service service = Service.create(url, serviceName); Dispatch<Source> sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD); //request is a XML which is put into SOAP payload StreamSource streamSource = new StreamSource (new StringReader(request)); Source result = sourceDispatch.invoke(streamSource);
  • 23. JAX-WS - Apart from this ● JAX-WS provides support for SOAP fault handling in terms of exceptions. ● JAX-WS supports handlers both on client and server side , which can process SOAP headers. SOAP headers are used to build Quality of services (QOS). ● JAX-WS supports asynchronous communication