0% found this document useful (0 votes)
87 views13 pages

Web Application Architecture

The document discusses web application architecture and distributed remote communication. It covers MVC architecture, security issues in web applications, RPC, Java RMI, message queuing, data serialization, and messaging protocols. For MVC, it defines the model, view and controller components and describes how they interact. For RPC, it explains the client-server model and how RPC messages are handled. For RMI, it defines stub and skeleton objects and provides steps to create a basic RMI program. It also provides a code sample for serialization in Java.

Uploaded by

Nikita Pardeshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views13 pages

Web Application Architecture

The document discusses web application architecture and distributed remote communication. It covers MVC architecture, security issues in web applications, RPC, Java RMI, message queuing, data serialization, and messaging protocols. For MVC, it defines the model, view and controller components and describes how they interact. For RPC, it explains the client-server model and how RPC messages are handled. For RMI, it defines stub and skeleton objects and provides steps to create a basic RMI program. It also provides a code sample for serialization in Java.

Uploaded by

Nikita Pardeshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

WEB APPLICATION ARCHITECTURE

[1]Web Architecture:
[2]MVC
[3]middleware
[4]Design considerations
[5]Issues in web application design
[6]Security issues
[7]interoperability issues (WS-I).
MVC Architecture:

MVC stands for Model, View and Controller. MVC separates application into
three components - Model, View and Controller.

Model: Model represents shape of the data and business logic. It maintains
the data of the application. Model objects retrieve and store model state in
a database.

View: View is a user interface. View display data using model to the user
and also enables them to modify the data.

Controller: Controller handles the user request. Typically, user interact


with View, which in-turn raises appropriate URL request, this request will
be handled by a controller. The controller renders the appropriate view with
the model data as a response.

The following figure illustrates the interaction between Model, View and
Controller.

MVC Architecture
The following figure illustrates the flow of the user's request in ASP.NET
MVC.
Request/Response in MVC Architecture

As per the above figure, when the user enters a URL in the browser, it goes
to the server and calls appropriate controller. Then, the Controller uses the
appropriate View and Model and creates the response and sends it back to
the user.

Security issues:

https://searchsecurity.techtarget.com/tip/Security-issues-with-Web-
services

DISTRIBUTED REMOTE COMMUNICATION


1. RPC
2. Java RMI
3. message queuing
4. Data Serialization
5. Messaging Protocols:
6. MQTT, RabbitMQ, JMS – JSON – AVRO, Thrift, protocol buffer

RPC:
Remote Procedure Call (RPC) is a protocol that one program can use to
request a service from a program located in another computer on
a network without having to understand the network's details. A procedure
call is also sometimes known as a function call or a subroutine call.

RPC uses the client-server model. The requesting program is a client and
the service providing program is the server. Like a regular or local
procedure call, an RPC is a synchronous operation requiring the requesting
program to be suspended until the results of the remote procedure are
returned. However, the use of lightweight processes or threads that share
the same address space allows multiple RPCs to be performed
concurrently.

RPC message procedure

When program statements that use RPC framework are compiled into an
executable program, a stub is included in the compiled code that acts as the
representative of the remote procedure code. When the program is run and the
procedure call is issued, the stub receives the request and forwards it to a
client runtime program in the local computer.

The client runtime program has the knowledge of how to address the remote
computer and server application and sends the message across the network that
requests the remote procedure. Similarly, the server includes a runtime program
and stub that interface with the remote procedure itself. Response-request protocols
are returned the same way.
Sample Program of RPC

import java.util.Vector;
import java.util.Scanner;
import java.util.Hashtable;

import helma.xmlrpc.*;
import helma.xmlrpc.WebServer;

public class JavaClient {

// The location of our server.

private final static String


server_url =
"http://localhost:7070";

public static void main (String []


args) { try {

// Create an object to represent our server.


XmlRpcClient server = new XmlRpcClient(server_url);

// Build our parameter list.


Vector params = new Vector();
System.out.println("Enter first value:");
Scanner in = new Scanner(System.in);

String s1 = in.nextLine();

System.out.println("Enter second value:");

String s2 = in.nextLine();
System.out.println("Number 1 :"+s1);
System.out.println("Number 2 "+s2);

params.addElement(new Integer(s1));
params.addElement(new Integer(s2));

// Call the server, and get our result.

int a = (Integer)server.execute("sum", params);


int b = (Integer)server.execute("diff",
params); int c =
(Integer)server.execute("multiply", params);
// int sum = ((Integer) result.get("sum")).intValue();
System.out.println("Mathematical
Operations"); int sum=a;
int diff=b;
int mul=c;

// Print out our result.


System.out.println("Sum: " + Integer.toString(sum));
System.out.println("Diff: " + Integer.toString(diff));
System.out.println("Multiplication: " +
Integer.toString(mul));

} catch (XmlRpcException exception) {


System.err.println("JavaClient: XML-RPC Fault #" +

Integer.toString(exception.code) + ":
" + exception.toString());
} catch (Exception exception) {
System.err.println("JavaClient: " +
exception.toString());
}
}

}
Server Code:

from xmlrpc.server import SimpleXMLRPCServer

import logging

# Set up logging
logging.basicConfig(level=logging.INFO)
server = SimpleXMLRPCServer(

('localhost', 7070),

logRequests=True,

)
# Expose a function
def sum(a,b):

return a+b

def diff(a,b):

return a-b

def multiply(a,b):

return a*b

server.register_function(sum)

server.register_function(diff)

server.register_function(multiply)

# Start the server


try:

print('Use Control-C to exit')

server.serve_forever()

except KeyboardInterrupt:

print('Exiting')

JAVA RMI
The RMI (Remote Method Invocation) is an API that provides a mechanism to create
distributed application in java. The RMI allows an object to invoke methods on an object
running in another JVM.

The RMI provides remote communication between the applications using two
objects stub and skeleton.

Understanding stub and skeleton


RMI uses stub and skeleton object for communication with the remote object.

A remote object is an object whose method can be invoked from another JVM. Let's
understand the stub and skeleton objects:

stub
The stub is an object, acts as a gateway for the client side. All the outgoing requests are
routed through it. It resides at the client side and represents the remote object. When
the caller invokes method on the stub object, it does the following tasks:

1. It initiates a connection with remote Virtual Machine (JVM),


2. It writes and transmits (marshals) the parameters to the remote Virtual Machine
(JVM),
3. It waits for the result
4. It reads (unmarshals) the return value or exception, and
5. It finally, returns the value to the caller.

skeleton
The skeleton is an object, acts as a gateway for the server side object. All the incoming
requests are routed through it. When the skeleton receives the incoming request, it does
the following tasks:

1. It reads the parameter for the remote method


2. It invokes the method on the actual remote object, and
3. It writes and transmits (marshals) the result to the caller.

In the Java 2 SDK, an stub protocol was introduced that eliminates the need for
skeletons.

Java RMI Example


The is given the 6 steps to write the RMI program.

1. Create the remote interface


2. Provide the implementation of the remote interface
3. Compile the implementation class and create the stub and skeleton objects using
the rmic tool
4. Start the registry service by rmiregistry tool
5. Create and start the remote application
6. Create and start the client application
1) create the remote interface
1. import java.rmi.*;
2. public interface Adder extends Remote{
3. public int add(int x,int y)throws RemoteException;
4. }

2) Provide the implementation of the remote interface


1. import java.rmi.*;
2. import java.rmi.server.*;
3. public class AdderRemote extends UnicastRemoteObject implements Adder{
4. AdderRemote()throws RemoteException{
5. super();
6. }
7. public int add(int x,int y){return x+y;}
8. }

3) create the stub and skeleton objects using the rmic tool.

1. rmic AdderRemote

4) Start the registry service by the rmiregistry tool


1. rmiregistry 5000
5) Create and run the server application
1. import java.rmi.*;
2. import java.rmi.registry.*;
3. public class MyServer{
4. public static void main(String args[]){
5. try{
6. Adder stub=new AdderRemote();
7. Naming.rebind("rmi://localhost:5000/sonoo",stub);
8. }catch(Exception e){System.out.println(e);}
9. }
10. }

6) Create and run the client application


1. import java.rmi.*;
2. public class MyClient{
3. public static void main(String args[]){
4. try{
5. Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/sonoo");
6. System.out.println(stub.add(34,4));
7. }catch(Exception e){}
8. }
9. }

Serialization

import java.io.Serializable;

class Student implements Serializable {


private static final long serialVersionUID = 536871008L;
private String name;
private String registerNumber;
private String courseName;
private String assessmentType;
private double mark;

public Student() {
}

public Student(String name, String registerNumber, String


courseName, String assessmentType, double mark){
this.name = name;
this.registerNumber = registerNumber;
this.courseName = courseName;
this.assessmentType = assessmentType;
this.mark = mark;
}

public String getName() {


return name;
}
public void setName(String name) {
this.name = name;
}
public String getRegisterNumber() {
return registerNumber;
}
public void setRegisterNumber(String registerNumber) {
this.registerNumber = registerNumber;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getAssessmentType() {
return assessmentType;
}
public void setAssessmentType(String assessmentType) {
this.assessmentType = assessmentType;
}
public double getMark() {
return mark;
}
public void setMark(double mark) {
this.mark = mark;
}
}

You might also like