SOAP, RMI, and Java Serialization - Lecture Slides PDF
Document Details

Uploaded by SmartestSaxhorn
Queen Mary University of London
Tags
Summary
This document presents lecture slides on SOAP, RMI, and Java Serialization. It covers the advantages and disadvantages of SOAP, modern SOAP usage, Remote Method Invocation (RMI), and Java serialization. Code examples and diagrams are included.
Full Transcript
SOAP Advantages and Disadvantages Advantages SOAP's neutrality characteristic explicitly makes it suitable for use with any transport protocol. SOAP, when combined with HTTP post/response exchanges, tunnels easily through existing firewalls and proxies Disadvantag...
SOAP Advantages and Disadvantages Advantages SOAP's neutrality characteristic explicitly makes it suitable for use with any transport protocol. SOAP, when combined with HTTP post/response exchanges, tunnels easily through existing firewalls and proxies Disadvantages When relying on HTTP as a transport protocol and not using Web Services Addressing or an Enterprise Service Bus, the roles of the interacting parties are fixed. Only one party (the client) can use the services of the other. The verbosity of the protocol and slow parsing speed of XML make it quite slow www.qmul.ac.uk /QMUL @QMUL Modern SOAP Usage Use of through the WS-Security extension ACID-compliant SOAP is in decline as other alternatives (such as REST which we will discuss next week) have better performance There are some cases, however, where the usage of SOAP is preferred. SOAP can be used to achieve: – more robust security transactions with WS-Transaction and www.qmul.ac.uk WS-Coordination /QMUL @QMUL Remote Method Invocation (RMI) RPC does not provide support for object abstraction Java’s RMI includes support for the direct transfer of serialised classes It also includes support for distributed garbage collection To achieve this a class must implement the Remote or UnicastRemote interface to make them Remote Objects www.qmul.ac.uk /QMUL @QMUL Java Remote Objects Remote objects are the exact same as local objects in Java References are used to identify objects in Java Java applications will never possess the reference to the remote object A proxy object known as a stub is used to represent this object locally and the stub is responsible for marshalling of messages and their delivery in a similar fashion to RPC www.qmul.ac.uk /QMUL @QMUL Remote Method Invocation (RMI) https://cseweb.ucsd.edu/classes/sp16/cse291-e/applications/ln/lecture3.html www.qmul.ac.uk /QMUL @QMUL RMI Passing By Reference In Java all values are passed by reference rather than by value This is problematic with RMI To determine which objects can be passed by RMI Java uses the simple rule of only allowing objects which implement Remote to be passed To transfer objects Java uses the process of serialisation www.qmul.ac.uk /QMUL @QMUL Java Serialisation https://www.geeksforgeeks.org/serialization-in-java/ www.qmul.ac.uk /QMUL @QMUL Java Serialisation Serialisation is the conversion of the object to a Byte Stream which contains information on the class, the member variables, the type of the member variables and the values of this particular instance This allows the class to be recreated after it is transferred across the network We can use the following code to examine a Java Byte Stream www.qmul.ac.uk /QMUL @QMUL Java Serialisation Example import java.io.*; import java.util.*; public class SerializationSample implements Serializable { private String aString = "The value of that string"; private int someInteger = 0; private transient List unInterestingLongLongList; public static void main( String [] args ) throws IOException { SerializationSample instance = new SerializationSample(); ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(new File("o.ser"))); oos.writeObject( instance ); oos.close(); } } www.qmul.ac.uk /QMUL @QMUL Java RMI Remote Interface Example package com.mkyong.rmiinterface; import java.rmi.Remote; import java.rmi.RemoteException; public interface RMIInterface extends Remote { public String helloTo(String name) throws RemoteException; } www.qmul.ac.uk /QMUL @QMUL Java RMI Server Example package com.mkyong.rmiserver; import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import com.mkyong.rmiinterface.RMIInterface; public class ServerOperation extends UnicastRemoteObject implements RMIInterface{ private static final long serialVersionUID = 1L; protected ServerOperation() throws RemoteException { super(); } @Override public String helloTo(String name) throws RemoteException{ System.err.println(name + " is trying to contact!"); return "Server says hello to " + name; } public static void main(String[] args){ try { Naming.rebind("//localhost/MyServer", new ServerOperation()); System.err.println("Server ready"); } catch (Exception e) { System.err.println("Server exception: " + e.toString()); e.printStackTrace(); } } } www.qmul.ac.uk /QMUL @QMUL Java RMI Client Example package com.mkyong.rmiclient; import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.RemoteException; import javax.swing.JOptionPane; import com.mkyong.rmiinterface.RMIInterface; public class ClientOperation { private static RMIInterface look_up; public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException { look_up = (RMIInterface) Naming.lookup("//localhost/MyServer"); String txt = JOptionPane.showInputDialog("What is your name?"); String response = look_up.helloTo(txt); JOptionPane.showMessageDialog(null, response); } } www.qmul.ac.uk /QMUL @QMUL Apache Thrift Created by Facebook Now an Apache Project Simple Interface Definition Language Efficient Serialisation in Space and Time- Variable Protocols Support for different Languages Code Generators for Glue Code Soft Versioning to allow interface and data type evolution between teams www.qmul.ac.uk /QMUL @QMUL Apache Thrift From:; A.Prunicki, Thrift Overview, http://jnb.ociweb.com/jnb/jnbJun2009.html www.qmul.ac.uk /QMUL @QMUL gRPC Developed at Google in 2015 Uses Google Protocol Buffers as the interface description language Protocol buffers are a flexible, efficient, automated mechanism for serialising structured data Similar to XML but smaller faster and simpler www.qmul.ac.uk /QMUL @QMUL Google Protocol Buffers message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { required string number = 1; optional PhoneType type = 2 [default = HOME]; } repeated PhoneNumber phone = 4; } www.qmul.ac.uk /QMUL @QMUL Google Protocol Buffers Person person; person.set_name("John Doe"); person.set_id(1234); person.set_email("[email protected]"); fstream output("myfile", ios::out | ios::binary); person.SerializeToOstream(&output); www.qmul.ac.uk /QMUL @QMUL gRPC https://grpc.io/docs/guides/ www.qmul.ac.uk /QMUL @QMUL