SlideShare a Scribd company logo
Implementing Web Services in Java
www.edureka.co/java-j2ee-soa-training
View Java/J2EE and SOA course details at http://www.edureka.co/java-j2ee-soa-training
For Queries:
Post on Twitter @edurekaIN: #askEdureka
Post on Facebook /edurekaIN
For more details please contact us:
US : 1800 275 9730 (toll free)
INDIA : +91 88808 62004
Email Us : sales@edureka.co
www.edureka.co/java-j2ee-soa-trainingSlide 2 Twitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Objectives
At the end of this webinar, you will be able to:
 Understand SOAP
 Implement WSDL
 Work Of REST Services
 Create a Restful App in JAVA
Slide 3 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
SOAP
 SOAP is a protocol to access Web services.
 SOAP stands for Simple Object Access Protocol. This protocol is based on XML.
 SOAP was designed in 1998 by Dave Winer, Don Box, Bob Atkinson, and Mohsen Al-Ghose.
Request 1 Request 1
Response1 Response1
SOAP
message
context
SOAP
message
context
Handler 1 Handler 2
Client
Request 1
Response1
SOAP
message
context
Handler
Service
SOAP
Service Requester Service Provider
Slide 4 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
SOAP
 SOAP stands for Simple Object Access Protocol
 SOAP is used for communicating between two applications
 SOAP is a format for sending messages
 SOAP communicates via Internet using HTTP
 SOAP is platform independent
 SOAP is written using XML
 SOAP is a W3C recommendation
Slide 5 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
SOAP - Example
For example: If we want to get the approval/declined status for credit card transaction from
bank using SOAP, following steps to be done/will be executed:
In client module, write the details about the customer details like credit card, account number,
expiry date, CVV2 etc., in SOAP format.
This SOAP message is sent on web to web service which provides the desired service.
The web service unpacks the SOAP message and converts into a command that the
application can understand. Application will get the credit card information. It does the
required processing and generates the response either approval/declined status in SOAP
message.
This SOAP message is sent back to the client.
Client unpacks the SOAP message and gets the required information.
Slide 6 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Credit card
account number
expiry date
CVV2
……..
Client Module
SOAP Format
Output in
Web
Web Service
unpacks the SOAP message
and converts into a command
that the application can
understand
SOAP
Message
SOAP – Flow Diagram
Slide 7 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
SOAP Files - WSDL, Client Generation
Server
Java Code - which does the actual operation/provides the service.
WSDL File - Web Service Description Language. This file says the information about the
services like the functions and what input it takes and what output it generates etc.
Client
Using WSDL file, we can generate the client and can execute the web services.
Slide 8 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Web Services - SOAP
 Web Service is published in UDDI registry
 UDDI stands for Universal Description, Discovery and Integration
 Client looks in the registry for the services and gets connected with the required service and interacts with it
UDDI
Registry
Web
Service
Requestor
Web
Service
Providerinvoke SOAP
register/publish
UDDI
locate/get description
UDDI
Slide 9 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Example of SOAP Request
Slide 10 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Example of SOAP Response
Slide 11 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
WSDL
 WSDL is Web Services Description Language
 WSDL is written in XML and it is a XML document
 WSDL describes the Web services
 WSDL is a W3C recommendation
Slide 12 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
WSDL
WSDL XML document has the following elements:
 <types> - This section is used to specify the data types used by the web services.
 <messages> - Messages for communication will be specified in this section. Input message
and output message can be specified in this section.
 <portType> - This defines the web service and the operations / methods to be executed.
Also the messages that are involved in this operation /method. Messages could be input
message and output message.
 <binding> - This section defines the message bindings and transportation protocol.
 <service> - Location of the service – URL.
Slide 13 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Example of WSDL File
Slide 14 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
REST Services
 REST stands for Representational State Transfer
 This service is developed using HTTP protocol
 In Rest based architecture, similar to SOAP based Architecture, service is developed in REST
and REST client has to be written to use the REST Service
 Java defines REST support via the Java Specification Request (JSR) 311. This specification is
called JAX-RS (The Java API for RESTful Web Services)
Slide 15 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
JAX-RS
 Jersey is the reference implementation for JSR (Java Specification Request)-311
 Jersey provides the library for RESTful Web Services using Servlet container
 Download Jersey distribution from the site: https://jersey.java.net/download.html
Slide 16 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Restful Services
 REST is an architecture. RESTful service is a service which follows the REST architecture.
 Following Annotations are used:
» @Path (path) – Sets the path to the base URL. The base URL is the application name,
servlet and URL specified in the web.xml.
» @GET – Indicates the following method will address HTTP GET request.
» @Produces – This function will generate the given output. It could be TEXT/HTML/XML
formats etc.
Slide 17 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Creating Restful Service
 Create a dynamic web project in eclipse.
 Add jersey jar files to the build path.
 Add the web.xml under web content/WEB-INF directory.
 Add a Java file and add the required code of the service.
Slide 18 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Restful Service – web.xml
Slide 19 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
RESTful Service – Java Code
Slide 20 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Creating Restful Service
 Hello should be added for the path of this service.
 Name of the class is Hello.
 @GET – The following method will respond to GET method of the client request.
 @Produces – This method returns the data specified in the Produces annotation.
 Method returns the data.
 Run the project so that Service is running on Apache Tomcat.
Slide 21 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
RESTful – Client
Slide 22 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
RESTful – Client
 Base URL is obtained for the service.
 Methods of RESTful services are invoked by using the path and the media type.
 Apart from writing the client, service can be tested with the URL too
For example:
» http://localhost:8080/jax_rest2/rest/Hello?name=edureka
» Here, service is running under 8080 port.
Name of the application is jax_rest2, /rest/Hello is the Path and name=edureka
is passed as parameter to this service.
Questions
www.edureka.co/java-j2ee-soa-trainingSlide 23 Twitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions
Implementing Web Services In Java

More Related Content

Implementing Web Services In Java

  • 1. Implementing Web Services in Java www.edureka.co/java-j2ee-soa-training View Java/J2EE and SOA course details at http://www.edureka.co/java-j2ee-soa-training For Queries: Post on Twitter @edurekaIN: #askEdureka Post on Facebook /edurekaIN For more details please contact us: US : 1800 275 9730 (toll free) INDIA : +91 88808 62004 Email Us : sales@edureka.co
  • 2. www.edureka.co/java-j2ee-soa-trainingSlide 2 Twitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Objectives At the end of this webinar, you will be able to:  Understand SOAP  Implement WSDL  Work Of REST Services  Create a Restful App in JAVA
  • 3. Slide 3 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions SOAP  SOAP is a protocol to access Web services.  SOAP stands for Simple Object Access Protocol. This protocol is based on XML.  SOAP was designed in 1998 by Dave Winer, Don Box, Bob Atkinson, and Mohsen Al-Ghose. Request 1 Request 1 Response1 Response1 SOAP message context SOAP message context Handler 1 Handler 2 Client Request 1 Response1 SOAP message context Handler Service SOAP Service Requester Service Provider
  • 4. Slide 4 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions SOAP  SOAP stands for Simple Object Access Protocol  SOAP is used for communicating between two applications  SOAP is a format for sending messages  SOAP communicates via Internet using HTTP  SOAP is platform independent  SOAP is written using XML  SOAP is a W3C recommendation
  • 5. Slide 5 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions SOAP - Example For example: If we want to get the approval/declined status for credit card transaction from bank using SOAP, following steps to be done/will be executed: In client module, write the details about the customer details like credit card, account number, expiry date, CVV2 etc., in SOAP format. This SOAP message is sent on web to web service which provides the desired service. The web service unpacks the SOAP message and converts into a command that the application can understand. Application will get the credit card information. It does the required processing and generates the response either approval/declined status in SOAP message. This SOAP message is sent back to the client. Client unpacks the SOAP message and gets the required information.
  • 6. Slide 6 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Credit card account number expiry date CVV2 …….. Client Module SOAP Format Output in Web Web Service unpacks the SOAP message and converts into a command that the application can understand SOAP Message SOAP – Flow Diagram
  • 7. Slide 7 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions SOAP Files - WSDL, Client Generation Server Java Code - which does the actual operation/provides the service. WSDL File - Web Service Description Language. This file says the information about the services like the functions and what input it takes and what output it generates etc. Client Using WSDL file, we can generate the client and can execute the web services.
  • 8. Slide 8 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Web Services - SOAP  Web Service is published in UDDI registry  UDDI stands for Universal Description, Discovery and Integration  Client looks in the registry for the services and gets connected with the required service and interacts with it UDDI Registry Web Service Requestor Web Service Providerinvoke SOAP register/publish UDDI locate/get description UDDI
  • 9. Slide 9 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Example of SOAP Request
  • 10. Slide 10 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Example of SOAP Response
  • 11. Slide 11 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions WSDL  WSDL is Web Services Description Language  WSDL is written in XML and it is a XML document  WSDL describes the Web services  WSDL is a W3C recommendation
  • 12. Slide 12 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions WSDL WSDL XML document has the following elements:  <types> - This section is used to specify the data types used by the web services.  <messages> - Messages for communication will be specified in this section. Input message and output message can be specified in this section.  <portType> - This defines the web service and the operations / methods to be executed. Also the messages that are involved in this operation /method. Messages could be input message and output message.  <binding> - This section defines the message bindings and transportation protocol.  <service> - Location of the service – URL.
  • 13. Slide 13 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Example of WSDL File
  • 14. Slide 14 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions REST Services  REST stands for Representational State Transfer  This service is developed using HTTP protocol  In Rest based architecture, similar to SOAP based Architecture, service is developed in REST and REST client has to be written to use the REST Service  Java defines REST support via the Java Specification Request (JSR) 311. This specification is called JAX-RS (The Java API for RESTful Web Services)
  • 15. Slide 15 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions JAX-RS  Jersey is the reference implementation for JSR (Java Specification Request)-311  Jersey provides the library for RESTful Web Services using Servlet container  Download Jersey distribution from the site: https://jersey.java.net/download.html
  • 16. Slide 16 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Restful Services  REST is an architecture. RESTful service is a service which follows the REST architecture.  Following Annotations are used: » @Path (path) – Sets the path to the base URL. The base URL is the application name, servlet and URL specified in the web.xml. » @GET – Indicates the following method will address HTTP GET request. » @Produces – This function will generate the given output. It could be TEXT/HTML/XML formats etc.
  • 17. Slide 17 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Creating Restful Service  Create a dynamic web project in eclipse.  Add jersey jar files to the build path.  Add the web.xml under web content/WEB-INF directory.  Add a Java file and add the required code of the service.
  • 18. Slide 18 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Restful Service – web.xml
  • 19. Slide 19 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions RESTful Service – Java Code
  • 20. Slide 20 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions Creating Restful Service  Hello should be added for the path of this service.  Name of the class is Hello.  @GET – The following method will respond to GET method of the client request.  @Produces – This method returns the data specified in the Produces annotation.  Method returns the data.  Run the project so that Service is running on Apache Tomcat.
  • 21. Slide 21 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions RESTful – Client
  • 22. Slide 22 www.edureka.co/java-j2ee-soa-trainingTwitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions RESTful – Client  Base URL is obtained for the service.  Methods of RESTful services are invoked by using the path and the media type.  Apart from writing the client, service can be tested with the URL too For example: » http://localhost:8080/jax_rest2/rest/Hello?name=edureka » Here, service is running under 8080 port. Name of the application is jax_rest2, /rest/Hello is the Path and name=edureka is passed as parameter to this service.
  • 23. Questions www.edureka.co/java-j2ee-soa-trainingSlide 23 Twitter @edurekaIN, Facebook /edurekaIN, use #askEdureka for Questions