Download Apache SOAP - Andrew.cmu.edu

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Apache SOAP
and the Java API for XML
Messaging (JAXM)
Notes from the Axis User’s Guide
and the books “Java Web Services” by
Deitel and “Distributed Systems
Concepts and Design” by Coulouris
1
Middleware layers
Applications
RMI, RPC and events
Request reply protocol
Middleware
layers
External data representation
Operating System
2
Remote and local method
invocations
local
remote
invocation
A
B
C
local E
invocation
invocation
local
invocation
D
remote
invocation
F
3
A remote object and its remote
interface
remoteobject
remote
interface
{
Data
m1
m2
m3
implementation
of methods
m4
m5
m6
4
Invocation semantics
Fault tolerance measures
Retransmit request
message
Duplicate
filtering
Invocation
semantics
Re-execute procedure
or retransmit reply
No
Not applicable
Not applicable
Maybe
Yes
No
Re-execute procedure
At-least-once
Yes
Yes
Retransmit reply
At-most-once
5
The role of proxy and skeleton in
remote method invocation
server
client
object A proxy for B
Request
skeleton
& dispatcher
for B’s class
remote
object B
Reply
Communication
Remote
reference module
module
Communication
module
Remote reference
module
6
What is SOAP?
•
•
•
•
•
XML-based communication protocol
XML-based encoding format
Supports inter-application communication
Cross platform
Cross Language
7
What is Axis?
• Apache Extensible Integration System
• Axis began as IBM’s SOAP4J
• A Framework for constructing SOAP
clients and servers
• Written in Java
8
Who competes with Axis?
•
•
•
•
CapeConnect from CapeClear
GLUE Standard from MindElectric
Orbix E2A XMLBus 5.2 From IONA
WASP Server for Java 4.0 from Systinet
9
Axis Architecture
Client
Transport
Listener
Message Handlers
Provider
Java
Class
10
Axis WSDL Support
• The Web Service Description Language
is a machine readable description of
a web service
• Given a WSDL document generate
communication stubs (WSDL2Java)
• Given a Java based web services
generate WSDL (Java2WSDL)
11
WSDL
•
•
•
•
•
•
•
An Interface Definition Language (IDL)
Java RMI uses Java Remote Interfaces
An IDL is needed when languages differ
Other example IDL’s
Corba IDL (Object-oriented syntax)
OSF’s DCE (C like syntax)
DCOM IDL based on OSF’s DCE and used by
Microsoft’s DCOM
• Sun XDR (An IDL for RPC)
12
CORBA IDL example
// In file Person.idl
struct Person {
string name;
string place;
long year;
};
interface PersonList {
readonly attribute string listname;
void addPerson(in Person p) ;
void getPerson(in string name, out Person p);
long number();
};
13
File interface in Sun XDR (Originally External Data
Representation but now an IDL)
const MAX = 1000;
typedef int FileIdentifier;
typedef int FilePointer;
typedef int Length;
struct Data {
int length;
char buffer[MAX];
};
struct writeargs {
FileIdentifier f;
FilePointer position;
Data data;
};
struct readargs {
FileIdentifier f;
FilePointer position;
Length length;
};
program FILEREADWRITE {
version VERSION {
void WRITE(writeargs)=1; // procedure
Data READ(readargs)=2; // numbers
}=2; // version number
} = 9999; // program number
// numbers passed in request message
// rpcgen is the interface compiler
14
WSDL
• Given a Description of a service (WSDL
document) Axis uses wsdl2java to create
the client code
• Given a Java service, Axis uses java2wsdl
to generate a description (WSDL
document)
• wsdl2java is an interface compiler
15
Example Client
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
public class Client
{
public static void main(String [] args)
{
try {
if(args.length != 2) {
System.out.println("usage:java Client BigInt BigInt");
System.exit(-1);
}
16
Service service = new Service();
Call call = (Call) service.createCall();
// hold data about the service
call.setTargetEndpointAddress(
new java.net.URL("http://localhost:8080/axis/servlet/AxisServlet") );
call.setOperationName( new QName("BigCalculatorService", "add") );
call.addParameter( "arg1", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( "arg2", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );
// This code does not look like normal
// application code!
17
String ret = (String) call.invoke( new Object[] { args[0],args[1] } );
System.out.println("The BigCalculator Service computed : " + ret);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
18
On The Server
// copy compiled code to the axis/WEB-INF/classes directory
import java.math.*;
public class BigCalculator {
public String add(String i1, String i2) {
BigInteger x = new BigInteger(i1);
BigInteger y = new BigInteger(i2);
return new String(x.add(y).toString());
}
//This code does not look
//like normal server side Java!
public String subtract(String i1, String i2) {
BigInteger x = new BigInteger(i1);
BigInteger y = new BigInteger(i2);
return new String(x.subtract(y).toString());
}
19
public static void main(String args[]) {
BigCalculator bc = new BigCalculator();
String a = bc.add("9999999999999","1");
System.out.println(a);
}
}
STEPS :
javac BigCalculator.java
Copy BigCalculator.class to D:\jwsdp-1.2\webapps\axis\WEB-INF\classes
Startup Tomcat
adminclient deploy.wsdd
java org.apache.axis.client.AdminClient deploy.wsdd
Processing file deploy.wsdd
<Admin>Done processing</Admin>
20
Web Service Deployment
<!-- deploy.wsdd -->
<!-- tell axis about this deployment with
java org.apache.axis.client.AdminClient deploy.wsdd
-->
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="BigCalculatorService" provider="java:RPC">
<parameter name="className" value="BigCalculator"/>
<parameter name="allowedMethods" value="*"/>
</service>
</deployment>
21
java Client 1
999999999999999999999999999999999
The BigCalculator Service computed :
10000000000000000000000000000000
But it works.
22
SOAP To Server
POST /axis/servlet/AxisServlet HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.1
Host: 127.0.0.1
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 520
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
23
<soapenv:Body>
<ns1:add soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="BigCalculatorService">
<myarg1 xsi:type="xsd:string">1</myarg1>
<myarg2 xsi:type="xsd:string">999999999999999999999999999999999999999999
</myarg2>
</ns1:add>
</soapenv:Body>
</soapenv:Envelope>
24
SOAP Back To Client
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Date: Mon, 27 Oct 2003 22:48:01 GMT
Server: Apache-Coyote/1.1
Connection: close
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
25
<soapenv:Body>
<ns1:addResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="BigCalculatorService">
<ns1:addReturn
xsi:type="xsd:string">
1000000000000000000000000000000000000000000
</ns1:addReturn>
</ns1:addResponse>
</soapenv:Body>
</soapenv:Envelope>
26
Use WSDL2Java
• From the WSDL document we can
generate client side code
• The WSDL document describes the
method names and variable types
• WSDL2Java is very much like rmic in Java
RMI
• It allows application programmers to think
about applications rather than distributed
systems
27
Code Generation using WSDL
java org.apache.axis.wsdl.WSDL2Java bigcalc.wsdl
localhost
└───axis
└───services
└───BigCalculatorService
BigCalculator.java
BigCalculatorService.java
BigCalculatorServiceLocator.java
BigCalculatorServiceSoapBindingStub.java
28
BigCalcClient.java
import localhost.axis.services.BigCalculatorService.*;
public class BigCalcClient {
public static void main(String args[]) throws Exception {
BigCalculatorService bs = new BigCalculatorServiceLocator();
BigCalculator bc = bs.getBigCalculatorService();
String a = new String("1");
String b = new String("9999999999999999");
String c = bc.add(a,b);
// This code looks like
System.out.println(c);
}
// application code
}
java BigCalcClient
10000000000000000
29
But We Are Still Working With
Strings
• Create a server class that works with
BigIntegers and not Strings
• Place it behind Axis under Tomcat
• Generate the WSDL
• The client uses the WSDL to generate the
client side code
• Write the client code
30
import java.math.*;
// Server Code
// Working with BigIntegers
public class BigCalculatorBigInt {
public BigInteger add(BigInteger i1, BigInteger i2) {
return i1.add(i2);
}
public BigInteger subtract(BigInteger i1, BigInteger i2) {
return i1.subtract(i2);
}
31
public static void main(String args[]) {
BigCalculatorBigInt bc = new BigCalculatorBigInt();
BigInteger a = bc.add(
new BigInteger("9999999999999"),
new BigInteger("1"));
System.out.println(a);
}
}
32
Write the Client
import localhost.axis.services.BigCalculatorBigIntegerService.*;
import java.math.*;
public class BigCalcClient {
public static void main(String args[]) throws Exception {
BigCalculatorBigIntService bs =
new BigCalculatorBigIntServiceLocator();
BigCalculatorBigInt bc =
bs.getBigCalculatorBigIntegerService();
33
BigInteger a = new BigInteger("1");
BigInteger b = new BigInteger("9999999999999999");
BigInteger c = bc.add(a,b);
System.out.println(c);
}
}
// Looks even better!
34
SOAP To Server
POST /axis/services/BigCalculatorBigIntegerService HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.1
Host: 127.0.0.1
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 487
35
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:add soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://DefaultNamespace">
<in0 xsi:type="xsd:integer">1</in0>
<in1 xsi:type="xsd:integer">9999999999999999</in1>
</ns1:add>
</soapenv:Body>
</soapenv:Envelope>
There are 44 simple types available
in the XMLShema namespace
Integer is defined as an arbitrarily long
integer
36
SOAP To Client
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Date: Tue, 28 Oct 2003 00:04:51 GMT
Server: Apache-Coyote/1.1
Connection: close
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:addResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://DefaultNamespace">
<ns1:addReturn xsi:type="xsd:integer">10000000000000000
</ns1:addReturn>
</ns1:addResponse>
37
</soapenv:Body>
</soapenv:Envelope>
Events and Notifications
• Examples of the local event model
-- a keystroke causes an interrupt
handler to execute storing a key
character in the keyboard buffer
-- a mouse click causes an interrupt
handler to call
a registered listener to handle the mouse
event
38
Distributed Event Based Systems
• Suppose the whiteboard server is willing to
make calls to all registered clients when
the drawing is changed by any one client
• Clients may subscribe to this service
(register interest)
• The whiteboard server publishes the
events that it will make available to clients
• This is the publish-subscribe paradigm
39
Two Characteristics of Distributed
Event Based Systems
(1) Heterogeneous
-- event generators publish the types of
events they offer
-- other objects subscribe and provide
callable methods
-- components that were not designed
to work together may interoperate
40
Two Characteristics of Distributed
Event Based Systems
(2) Asynchronous
-- Publishers and subscribers are
decoupled
-- notifications of events are sent
asynchronously to all subscribers
41
Dealing room system
Dealer’s computer
Dealer
Dealer’s computer
External
source
Notification
Notification
Notification
Information
provider Notification
Notification
Dealer
Notification
Notification
Dealer’s computer
Dealer’s computer
Notification
Information
provider
Notification
Notification
Dealer
Dealer
External
source
42
Architecture for distributed event
notification
Event service
subscriber
object of interest
1.
notification
object of interest
2.
object of interest
observer
notification
subscriber
notification
observer
3.
subscriber
notification
Next Topic ….JAXM and Asynchronous Messaging….
43
Related documents