15
1 Fall 2005 CEG 4183 15-1 Lecture 15: Frameworks for Application-layer Communications Prof. Shervin Shirmohammadi SITE, University of Ottawa Fall 2005 CEG 4183 15-2 Background We have seen previously that: – Applications need to exchange messages – In the labs, the assignments, and the project, we used application-level framing that uses application-specific tokens. Whiteboard example

Lecture 15: Frameworks for Application-layer Communications

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

1

Fall 2005 CEG 4183 15-1

Lecture 15:

Frameworks for Application-layer

Communications

Prof. Shervin Shirmohammadi

SITE, University of Ottawa

Fall 2005 CEG 4183 15-2

Background

• We have seen previously that:

– Applications need to exchange messages

– In the labs, the assignments, and the project, we

used application-level framing that uses

application-specific tokens.

• Whiteboard example

2

Fall 2005 CEG 4183 15-3

Motivation

• Token-based messaging scheme can become

complicated as the application adds more and

more features.

– Think of the number of commands in a word-processor

applications.

• There should be a way for a more methodical and

structured technique to allow programs to

communicate.

– Ideally, the programmer should not even have to worry

about communication and how it’s done.

• Enter communications frameworks:

– RPC, RMI, CORBA, SOAP

Fall 2005 CEG 4183 15-4

Remote Procedure Call• RPC, used in C and C++ (theoretically language neutral)

• The idea goes back to 1976, with full-scale implementations appearing in the late 1970s.

• We know that in a program, functions can “call”one another.

• Even different programs running on the same computer can call each other’s function.– e.g., OLE on Windows, pipes on UNIX, …

• The idea behind RPC is to allow the same thing for programs running on different computers.– A program on my computer should be able to call a function inside a program on your computer.

3

Fall 2005 CEG 4183 15-5

RPCHost 1 Host 2

void main()

{

compute(3, 5);

}

int compute()

{

return x+y/x;

}

int compute()

{

return x+y/x;

}

main.c compute.c

compute.c

• Somehow we have to transmit the return value (which can be anything: integer, array, linked list, …) over the network.

• What else must we take care of?

Fall 2005 CEG 4183 15-6

RPC Details• During compilation, client and server stubs are created.

• Application calls a function from the client stub, which converts arguments to Network Data Representation (NDR) and sends them to the RPC run-time.

• Run-time uses the transport

layer to send data to server.

• Server’s RPC run-time takes

the incoming data and passes

them to server’s stub, which

runs the actual procedure.

• Result is returned similarly.

4

Fall 2005 CEG 4183 15-7

Remote Method Invocation

• RMI, used in Java only.

• Can be thought of as “Object-oriented RPC”.

• How to send objects over the network?

Host 1 Host 2

void main()

{

Local.compute(3, 5);

Remote.compute(3,5);

}

int compute()

{

return x+y/x;

}

int compute()

{

return x+y/x;

}

main.java

Local.java Remote.java

Fall 2005 CEG 4183 15-8

RMI Details• Stub (remote object) and skeleton (server object) is created.

• Stubs don’t need to be compiled into the client, they can be downloaded at run-time.

• Remote objects are registered, and clients can download their stub to use their services.

• Application invokes remote object’s stub as if invoking a local object.

• Stub passes the arguments to Remote Reference Layer which then uses the transport layer for network communication.

• RRL at server invokes the skeleton, which invokes the actual object to do the operation. The result is sent back in a similar manner.

5

Fall 2005 CEG 4183 15-9

RMI Example• Time server example in RMI

• First, we define the service available by describing its methods.

• No implementation is needed at this stage– users don’t care anyway about the internal implementation, they just want

to be able to call the function.

• Defining the interface:

• TimeInterface.java:

import java.rmi.*;

public interface TimeInterface extends Remote {

public String getTime() throws RemoteException;

}

Fall 2005 CEG 4183 15-10

RMI Example: Remote Object

• Now we need to implement that Interface

• Time.java:

import java.rmi.*;

import java.rmi.server.*;

public class Time extends UnicastRemoteObject implements TimeInterface {

public String getTime() throws RemoteException {

return "It's 12PM";

}

}

6

Fall 2005 CEG 4183 15-11

RMI Example: Server• We need to run the service:

• Server.java:

import java.rmi.Naming;

public Server {

public static void main (String[] argv) {

try {

Naming.rebind ("Time", new Time());

System.out.println ("Time Server is running.");

} catch (Exception e) {

System.out.println ("Problem with Time Server: " + e);

}

}

}

Fall 2005 CEG 4183 15-12

RMI Example: Client• Finally, we can write a client program that uses the Time service:

• Client.java:

import java.rmi.Naming;

public Client {

public static void main (String[] argv) {

try {

TimeInterfacce time_object = (TimeInterface) Naming.lookup("137.122.20.16/Time");

System.out.println (time_object.getTime());

}

catch (Exception e) {

System.out.println ("Exception: " + e);

}

}

}

7

Fall 2005 CEG 4183 15-13

CORBA• Common Object Request Broker Architecture, an Object

Management Group (OMG) standard

• Cross-platform, language-independent!

• Provides services to enable an application in a given programming language to talk to a remote application using another programming language, both running on different platforms.

• Includes many services for registry, lookup, naming, and so on.

• Uses Interface Definition Language (IDL) to specify method signatures (return type, name, arguments).– IDL is platform-independent, and defines its own types.

• Stub (client) and skeleton (server) is created during compilation. These have to be implemented in a language-specific manner.

• Binding is done during run-time.

Fall 2005 CEG 4183 15-14

CORBA Scenario

Host 1Win 95

Host 2Solaris

void main()

{

compute(3, 5);

}

int compute()

{

return x+y/x;

}

main.cRemote.java

8

Fall 2005 CEG 4183 15-15

SOAP• Simple Object Access Protocol, a W3C standard, is a communications protocol to exchange messages among applications.

• Typically used on top of HTTP.– Doesn’t have to be HTTP.

• An XML-based application-layer communications technique.

• The idea is, similar to RPC RMI and CORBA, to hide the communication part and let the application-layer on one side to talk to the application layer on the other side.

• Part of the Web Services paradigm.

• What is a Web Service? A Web page that provides a a service?

Fall 2005 CEG 4183 15-16

IBM

Evolution of Networked Applications

9

Fall 2005 CEG 4183 15-17

Web Evolution

XMLXML

ProgrammabilityProgrammabilityConnectivityConnectivity

HTMLHTML

PresentationPresentation

TCP/IP

TCP/IP

Techno

logy

Techno

logy

Innovation

Innovation

FTP,FTP, EE--mail, Gopher

mail, GopherWeb Pages

Web Pages

Browse Browse the Webthe Web

Program Program the Webthe Web

Web Services

Web Services

Fall 2005 CEG 4183 15-18

Web Services are:• a solution for providing application-to-application

communication over the Internet.

• a URL-addressable software resource that performs functions.

• Web services communicate using standard protocol known as

SOAP (Simple Object Access Protocol)

•A Web services is located by its listing in a Universal

Discovery, Description and Integration (UDDI) directory.

•A Web Service is typically defined using the Web Service

Definition Language (WSDL)

SOAP

Bind

WSDL

UDDI

Publish /

describe

WSDL

UDDI

Discover /

describeService

Requester

Service

Broker

Service

Provider

XML

Requester Broker Provider

10

Fall 2005 CEG 4183 15-19

Architecture – Request & Response

Listener

SOAP or XML-RPC

SOAP or XML-RPCWeb

Services

HTTP

HTTP

middleware

Service Tier

Business

Services

API

– SOAP and XML-RPC have become accepted standards for

XML-based messaging.

– HTTP is the protocol for the Internet.

– The Web Service will parse the request and either fulfill the

request directly, or invoke one or more business services via

some middleware API.

CORBA,

RMI,

DCOM,

JMS…

Fall 2005 CEG 4183 15-20

Extensible Markup Language (XML)• XML is a metadata language: data that describes data.

• It is used as a standard way for information exchange.

– W3C standard

– In some ways it can be thought as part of the presentation layer.

• It is a subset of SGML (Standard Generalized Markup

Language)

– SGML is the “parent” of HTML

• The key to success of XML: it lets you define your own

data types in a standard way.

• Processing XML:

– APIs (DOM, SAX)

– addressing XML: XPath, XLink, XPointer

11

Fall 2005 CEG 4183 15-21

XML Element and Attributes

<resource>

<tutorial name=“cooking">

<authors>

<author>Jane Smith</author>

</authors>

<title>The Joy of Cooking</title>

</tutorial>

</resource>

Nice, but how do we know what are resource, tutorial, title, …?

Element

Attribute

Fall 2005 CEG 4183 15-22

Document Type Definitions (DTD)

• recursive types<!ELEMENT A (B|C)> "an A can contain a B..."

<!ELEMENT B (A|C)> "... which contains an A!"

<!ELEMENT C (#PCDATA)>

• loose typing – <!ELEMENT A ANY>

• no context-sensitive types:DTDs cannot distinguish between the publisher in

– <journal> <publisher>... </publisher> </journal>

– <website> <publisher> ... </publisher> </website>

• What do to in terms of conflicts such as this?

12

Fall 2005 CEG 4183 15-23

XML Namespaces

• My element may not be your element:

– geometry context: <element>line</element>

– chemistry context: <element>oxygen</element>

– use XML namespaces to identify the vocabulary

<?xml version="1.0" encoding="utf-8" ?>

<lists xmlns=“http://deltabis.com/products” xmlns:it="http://deltabis.com/itinerary">

<product sku="8822N" size="small" type="trouser">

<it:itinerary>

<it:sold>120</it:sold>

. . .

Fall 2005 CEG 4183 15-24

Example

<?xml version="1.0" encoding="utf-8" ?>

<lists xmlns=“http://deltabis.com/products” xmlns:it="http://deltabis.com/itinerary">

<product sku="8822N" size="small" type="trouser">

<it:itinerary>

<it:sold>120</it:sold>

<it:onhold>45</it:onhold>

<it:returned>10</it:returned>

</it:itinerary>

</product>

<product sku="9820Y" size="small" type="tshirt">

<it:itinerary>

<it:sold>283</it:sold>

<it:onhold>232</it:onhold>

<it:returned>23</it:returned>

</it:itinerary>

</product>

</lists>

13

Fall 2005 CEG 4183 15-25

WSDL

– Web Services Definition Language

– Standard for defining a Web Service

• Defines an abstract interface and bindings to particular message

formats

• Defines how to locate the service (URLs for HTTP)

• Defines what protocol the service uses (HTTP, SMTP, FTP)

• Written in XML

– Used to publish services in UDDI

Fall 2005 CEG 4183 15-26

UDDI• Universal Discovery, Description and Integration

• Standard for publishing Web Services– Directory service that enables clients to locate services

– Services can be found by searching or unique ID

– Servers provide a SOAP based interface (API) for finding and publishing

• Three roles for UDDI data– White pages – technical contact information and addresses

– Yellow pages – various services available from business

– Green pages – technical information about services

including WSDL

Clientapplication

Webserver

UDDI registry nodeUDDI registry node

SOAPprocessor

UDDI registryservice

UDDIdatabase

SOAP request

SOAP response

14

Fall 2005 CEG 4183 15-27

Back to Web Services: SOAP

–SOAP provides transfer of structured databetween services.

–SOAP is an XML based transport protocol.

–Protocol binding: HTTP, SMTP…

–One way message: Sender or Receiver

– It is stateless, and therefore the sender and receiver need not maintain a session to communicate.• The application however has to take care of the communications semantics.

Fall 2005 CEG 4183 15-28

SOAP Details

• With SOAP, we’re actually back to a

concept which is similar to the familiar

token-based message passing, but SOAP is

standardized.

Host 1 Host 2void main()

{

getLowestPrice();

}

main.cWeb service provider

Give me lowest price for book

lowest price is $67.99

15

Fall 2005 CEG 4183 15-29

SOAP Request

getLowestPrice<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>

<m:GetPrice mlns:m="http://www.w3schools.com/prices"> <m:Item>ISBN78932167</m:Item>

</m:GetPrice>

</soap:Body>

</soap:Envelope>

This message is sent to the server using HTTP.

Fall 2005 CEG 4183 15-30

SOAP ResponseResponse:

<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>

<m:GetPrice mlns:m="http://www.w3schools.com/prices"> <m:Price>67.99</m:Price>

</m:GetPrice>

</soap:Body>

</soap:Envelope>

This message is returned to the requester.