intro to web and web services (rest series 01)

12
INTRO TO WEB AND WEB SERVICES Overview of HTTP, Servlets and SOAP Web Services Presenter: Heartin Jacob Kanikathottu ( www.codingarchitect.com , www.javajee.com )

Upload: heartin-jacob

Post on 16-Apr-2017

124 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Intro To Web and Web Services (REST Series 01)

INTRO TO WEB AND WEB SERVICES

Overview of HTTP, Servlets and SOAP Web ServicesPresenter: Heartin Jacob Kanikathottu (

www.codingarchitect.com, www.javajee.com)

Page 2: Intro To Web and Web Services (REST Series 01)

TOPICS

• Revision of basic web application concepts.• Revision of HTTP, Servlets and Servers.• Introduction to Web Services and Overview of SOAP Web Services.• Overview of REST Web Services and Differences with SOAP Web Services.• Java support for Web Services – JAX-WS and JAX-RS.• Resources and References

Page 3: Intro To Web and Web Services (REST Series 01)

REVISION OF BASIC WEB APPLICATION CONCEPTS

• Internet Protocols• TCP (Transmission Control Protocol), IP (Internet Protocol), UDP (User Datagram Protocol),

HTTP (Hypertext Transfer Protocol), FTP (File Transfer Protocol) and SMTP (Simple Mail Transfer Protocol).

• URI, URL and URN• Uniform resource identifier (URI) is a string of characters used to identify a name of a resource.• Concrete forms of URI: uniform resource locator (URL) and uniform resource name (URN).

• Client side technologies: HTML, JavaScript and CSS• Web applications vs. web services

• Human users vs. other systems as client.

Page 4: Intro To Web and Web Services (REST Series 01)

REVISION OF HYPER TEXT TRANSFER PROTOCOL (HTTP)

• HTTP is a synchronous request-response application network protocol.• The seven HTTP methods are GET, POST, HEAD, OPTIONS, TRACE, PUT, DELETE.• Idempotent request

• An idempotent request is meant to have the same result how many times it is executed.• GET, PUT, DELETE are supposed to be idempotent, whereas POST is not.

• HTTP Status Codes• Status of a request sent through the use of status codes, which are sent back along with the

response. • There are five classes of status codes:  Informational (1XX), Successful (2XX), Redirection

(3XX), Client Error (4XX), Server Error (5XX).

Page 5: Intro To Web and Web Services (REST Series 01)

REVISION OF SERVLETS AND SERVERS

• Servlets are java components that can respond to an HTTP request.• There are methods in Java Servlets corresponding to each of the HTTP methods. 

• The seven HTTP methods map on to seven servlet methods of the same name with a “do” in front (e.g., POST maps on to doPost()).

• The doXXX() methods receive two objects as parameters—the first representing the HTTP request and the second the HTTP response.

• Java Web Servers• Web container for servlets and JSPs. E.g. Tomcat• Application server has EJB and Web Container, and more. E.g. Glassfish, Jboss.

Note: You can learn more about servlets and http, for better understanding this course @ http://javajee.com/java-ee-web-components-part1-http-and-servlets.

Page 6: Intro To Web and Web Services (REST Series 01)

SIMPLE SERVLET EXERCISE

• Note: May skip this exercise if you are really comfortable with Servlets and one of tcpmon or wireshark, else follow below steps:• Download tomcat (version 8 or anything that your eclipse support).• Configure eclipse to use tomcat. Start, stop and restart to verify.• Create a dynamic web project.• Create a simple Servlet named HelloWorld.• Execute the servlet by deploying into to tomcat from within eclipse.• See the actual HTTP request and response using tcp mon or wireshark. You may

refer to config notes for these @ http://javajee.com/monitoring-and-analyzing-tools.

Page 7: Intro To Web and Web Services (REST Series 01)

INTRO TO WEB SERVICE

• Web services are services exposed over a network and is designed to be used automatically by other applications without human interaction.

• Web services communicate using standard, vendor-independent protocols such as HTTP, XML, Javascript etc.

• Web Services vs. Web Applications• web applications are applications with web pages primarily for use by humans• web service is a server-based application component meant primarily for interaction

with other programs. • Two types of Web Services: SOAP and REST.

Page 8: Intro To Web and Web Services (REST Series 01)

OVERVIEW OF SOAP WEB SERVICES

• SOAP stands for Simple Object Access Protocol. AKA SOA Protocol.• Contains primarily three components

• SOAP Protocol: SOAP based web services uses a special form of XML that follows a protocol called SOAP to exchange messages.

• WSDL: Web Services Description Language is an XML-based language that is used for describing the functionality offered by a Web service.

• UDDI: Universal Description, Discovery and Integration (UDDI) is a directory service, and is optional.

• Message Exchange Pattern (MEP): Request Response (Input-Output), Input only, Solicit Response (Output input), Notification or publish-subscribe (Output only).

Note: You can learn more about SOAP Web Services and Web Services in general @ http://javajee.com/web-services.

Page 9: Intro To Web and Web Services (REST Series 01)

OVERVIEW OF REST AND DIFFERENCES FROM SOAP

• Follow a resource oriented way:• Every resource will be represented by a single URI and uses the standard set of

http operations like POST, GET, PUT, and DELETE, to do various operations on that resource.

• Current state of representation is transferred using formats such as XML and JSON.

• SOAP is based on rules whereas REST is based on guidelines.• There is no formal definitions for REST like the WSDL.

• There is WADL, but not so popular or widely accepted.• REST support only request-response message exchange pattern.

Page 10: Intro To Web and Web Services (REST Series 01)

JAVA SUPPORT FOR WEB SERVICES – JAX-WS AND JAX-RS.

• Java API for XML Web services (JAX-WS) can be used for SOAP-based as well as REST-style, but more suited for SOAP.

• JAX–WS require at least core java 5 because of the support of annotation and is part of JDK from Java 6.

• Java API for XML – Restful web services (JAX–RS) is the standard specification for REST web services.

• Jersy is the reference implementation for JAX-RS. Other popular implementations include RESTEasy, Restlet and Spring REST.

Note: You can learn more about SOAP Web Services and Web Services in general @ http://javajee.com/web-services.

Page 11: Intro To Web and Web Services (REST Series 01)

SIMPLE SOAP DEMO

• You may skip this if you don’t want to learn anything about SOAP, but if you do, these exercises it will help you compare SOAP with REST better:• Please do at least one of these two exercises:

• Create a simple SOAP service and deploy it in Apache Tomcat• Create a simple SOAP service and deploy it in Glassfish Server

• Note: Notes and step by step lab for above can be found @ http://javajee.com/web-services.

Page 12: Intro To Web and Web Services (REST Series 01)

RESOURCES & REFERENCES

• JavaJee.com – • You can find the session materials, examples and much more @ Javajee.com.

Additional materials or references are provided @ Javajee.com on respective pages.

• Important related links include:• http://javajee.com/java-ee-web-components-part1-http-and-servlets • http://javajee.com/web-services• http://javajee.com/rest-web-services-with-jax-rs (For future sessions)

• Java Web Services: Up and Running by Martin Kalin.