Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.

Slides:



Advertisements
Similar presentations
World Wide Web Basics Original version by Carolyn Watters (Dalhousie U. Computer Science)
Advertisements

Hypertext Transfer Protocol Kyle Roth Mark Hoover.
1 Java Networking – Part I CS , Spring 2008/9.
16-Jun-15 HTTP Hypertext Transfer Protocol. 2 HTTP messages HTTP is the language that web clients and web servers use to talk to each other HTTP is largely.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
How the web works: HTTP and CGI explained
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Know how HTTP accesses data on the WWW Objectives.
Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Hypertext Transport Protocol CS Dick Steflik.
Client, Server, HTTP, IP Address, Domain Name. Client-Server Model Client Bob Yahoo Server yahoo.com/finance.html A text file named finance.html.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
PL-IV- Group A HTTP Request & Response Header
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
Human-Computer Interface Course 5. ISPs and Internet connection.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
FTP (File Transfer Protocol) & Telnet
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
Rensselaer Polytechnic Institute Shivkumar Kalvanaraman, Biplab Sikdar 1 The Web: the http protocol http: hypertext transfer protocol Web’s application.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
Maryam Elahi University of Calgary – CPSC 441.  HTTP stands for Hypertext Transfer Protocol.  Used to deliver virtually all files and other data (collectively.
Hypertext Transfer Protocol HTTP Photo courtesy: 1.
Web application architecture
Sistem Jaringan dan Komunikasi Data #9. DNS The Internet Directory Service  the Domain Name Service (DNS) provides mapping between host name & IP address.
TCP/IP Protocols Dr. Sharon Hall Perkins Applications World Wide Web(HTTP) Presented by.
Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman Chapter 17 This presentation © 2004, MacAvon Media Productions Multimedia and Networks.
Web Client-Server Server Client Hypertext link TCP port 80.
HTTP1 Hypertext Transfer Protocol (HTTP) After this lecture, you should be able to:  Know how Web Browsers and Web Servers communicate via HTTP Protocol.
1 Seminar on Service Oriented Architecture Principles of REST.
ECEN “Internet Protocols and Modeling”, Spring 2012 Course Materials: Papers, Reference Texts: Bertsekas/Gallager, Stuber, Stallings, etc Class.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Fundamentals.
Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman Chapter 17 This presentation © 2004, MacAvon Media Productions Multimedia and Networks.
HTTP Here, we examine the hypertext transfer protocol (http) – originally introduced around 1990 but not standardized until 1997 (version 1.0) – protocol.
Web Services. 2 Internet Collection of physically interconnected computers. Messages decomposed into packets. Packets transmitted from source to destination.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
CS 6401 The World Wide Web Outline Background Structure Protocols.
Project Scenario for OpX. High-level Overview In the Test GUI Controller, opXController, for the opX command there is conceptually a call to an appropriate.
RESTful Web Services What is RESTful?
Overview of Servlets and JSP
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
Week 11: Application Layer 1 Web and HTTP r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file,… r Web page consists.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
INTRODUCTION Dr Mohd Soperi Mohd Zahid Semester /16.
Network Programming. These days almost all devices.
HTTP Protocol Amanda Burrows. HTTP Protocol The HTTP protocol is used to send HTML documents through the Internet. The HTTP protocol sends the HTML documents.
Tiny http client and server
HTTP – An overview.
Computing with C# and the .NET Framework
Hypertext Transport Protocol
IS333D: MULTI-TIER APPLICATION DEVELOPMENT
WEB API.
Hypertext Transfer Protocol
Hypertext Transfer Protocol
HyperText Transfer Protocol
William Stallings Data and Computer Communications
Hypertext Transfer Protocol
HTTP Hypertext Transfer Protocol
Web APIs API = Application Programmer Interface
Hypertext Transfer Protocol
Presentation transcript:

Simple Web Services

Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running on different computers to connect and communicate directly with each other TCP requires that each computer have a unique identifier called an “IP Address” – –

Internet Basics Since a computer runs many programs simultaneously, TCP uses Port Numbers to identify individual programs running on a computer –TCP Port Numbers are in the range 0 – –Ports 0 – 1023 are reserved for system services ( , web, etc.) –Ports 1024 – are registered to particular applications –Ports – can be used for custom or temporary purposes – servers typically run on Port 25 –Web servers typically run on Port 80

Internet Basics The combination of (IP Address, TCP Port Number) uniquely identifies a particular program on a particular computer –( , 25) => server on machine –( , 80) => Web server on machine

Internet Basics Through TCP, a program on one computer can connect to a program running on another computer by specifying its (IP Address, TCP Port Number) –Connect to ( , 25) => Connect to server on machine –Connect to ( , 80) => Connect to web server on machine Such a TCP connection is called a “Socket” Once a connection has been established, the two programs can pass data back and forth to each other (i.e., communicate)

Internet Basics IP Addresses are hard to remember and work with directly Users prefer to reference machines by Name rather than by IP Address –pinky.cs.byu.edu instead of – instead of DNS (Domain Name System) is a protocol for looking up a machine’s IP Address based on its (Domain) Name –Connect to ( 80) –DNS, what is the IP Address for “ – –OK, Connect to ( , 80)

Internet Basics Java Sockets example: FileTransferFileTransfer

URLs (uniform resource locators) scheme://domain:port/path?query_string#fragment_id scheme (case-insensitive) – http or https domain (case-insensitive) – The server’s domain name or IP address. The domain name google.com, or its IP address , is the address of Google's website. port (optional) – The port, if present, specifies the server’s TCP port number. For http URLs, the default port is 80. For https URLs, the default port is 443. path (case-sensitive) – The path is used to specify and perhaps locate the requested resource. query_string (optional, case-sensitive) – The query string, if present, contains data to be passed to software running on the server. It may contain name/value pairs separated by ampersands, for example ?first_name=John&last_name=Doe. fragment_id (optional, case-sensitive) – The fragment identifier, if present, specifies a part or a position within the overall resource or document.

URLs scheme – http domain – port – 80 path – /basketball/nba/index.html query_string – ?team=dallas&order=name fragment_id – #Roster

Java’s URL Class import java.net.URL; URL url = new URL( ” team=dallas&order=name#Roster”); String host = url.getHost(); int port = url.getPort(); String path = url.getPath(); String query = url.getQuery(); String fragment = url.getRef(); // Many more URL operations

HTTP (hypertext transfer protocol) Network protocol that drives the Web Built on top of TCP By default, Web servers run on TCP Port 80 HTTP has a Request/Response structure –Client (e.g., web browser) sends a “request” message to the server –Server sends back a “response” message to the client

HTTP Request message format \r\n GET /test/hi-there.txt HTTP/1.1 Accept: text/* Host: is the operation to perform on URL can be full URL or just the path part is of the form HTTP/. is a stream of bytes (could be empty)

HTTP Response message format \r\n HTTP/ OK Content-type: text/plain Content-length: 18 Hi! I’m a message! is of the form HTTP/. is a 3-digit number indicating status of request human-readable description of status code is a stream of bytes (could be empty)

HTTP Request Methods GET – Retrieve document from server POST – Send data to server for processing PUT – Store document on server DELETE – Remove document from server HEAD – Retrieve document headers from server OPTIONS – Determine what methods the server supports TRACE – Trace the path taken by a request through proxy servers on the way to the destination server

HTTP Response status codes Informational Successful Redirection Client error Server error 200 OK 401 Unauthorized to access resource 404 Requested resource does not exist

HTTP Headers List of name/value pairs Name: Value\r\n Empty line separates headers and entity body General headers (request or response) –Date: Tue, 3 Oct :16:00 GMT Time at which message was generated –Connection: close Client or server can specify options about the underlying connection

HTTP Request Headers Host: –Host from the request URL User-Agent: Mozilla/4.0 –Client application making the request Accept: text/html, text/xml –MIME types the client can handle Referer: –Page that contained the link currently being requested If-Modified-Since: Tue, 3 Oct :16:00 GMT –Conditional request; only send the document if it changed since I last retrieved it

HTTP Response Headers Content-length: –Length of response entity body measured in bytes Content-type: text/html –MIME type of response entity body Server: Apache/1.2b6 –Server software that handled the request Cache-Control: no-cache –Clients must not cache the response document

HTTP HTTP request/response example: HttpTraceHttpTrace Java’s URLConnection class can be used by clients to make HTTP requests and receive HTTP responsesURLConnection Java’s HttpServer class can be used to implement an HTTP serverHttpServer

Java’s URLConnection class (GET) try { URL url = new URL(” HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod(”GET”); // Set HTTP request headers, if necessary // connection.addRequestProperty(”Accept”, ”text/html”); connection.connect(); if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { // Get HTTP response headers, if necessary // Map > headers = connection.getHeaderFields(); InputStream responseBody = connection.getInputStream(); // Read response body from InputStream... } else { // SERVER RETURNED AN HTTP ERROR } catch (IOException e) { // IO ERROR }

Java’s URLConnection class (POST) try { URL url = new URL(” HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod(”POST”); connection.setDoOutput(true); // Set HTTP request headers, if necessary // connection.addRequestProperty(”Accept”, ”text/html”); connection.connect(); OutputStream requestBody = connection.getOutputStream(); // Write request body to OutputStream... requestBody.close(); if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { // Get HTTP response headers, if necessary // Map > headers = connection.getHeaderFields(); InputStream responseBody = connection.getInputStream(); // Read response body from InputStream... } else { // SERVER RETURNED AN HTTP ERROR } catch (IOException e) { // IO ERROR }

Contact Manager example The Contact Manager client uses URLConnection to communicate with the Contact Manager server

Java’s HttpServer class HttpServer server = HttpServer.create(new InetSocketAddress(8000)); server.createContext("/applications/myapp", new MyHandler()); server.setExecutor(null); // creates a default executor server.start();... class MyHandler implements HttpHandler { public void handle(HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); read(is); //.. read the request body String response = "This is the response"; t.sendResponseHeaders(200, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); }

Java’s HttpExchange class The typical life-cycle of a HttpExchange is shown in the sequence below. –getRequestMethod() to determine the command –getRequestHeaders() to examine the request headers (if needed) –getRequestBody() returns a InputStream for reading the request body. After reading the request body, the stream is close. –getResponseHeaders() to set any response headers, except content- length –sendResponseHeaders(int,long) to send the response headers. Must be called before next step. –getResponseBody() to get a OutputStream to send the response body. When the response body has been written, the stream must be closed to terminate the exchange.

Contact Manager example Contact Manager uses the HttpServer, HttpHandler, and HttpExchange classes to implement its server