SOAP Simple Object Access Protocol SOAP SOAP Approach SOAP ...

therapistarmyΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 5 μήνες)

107 εμφανίσεις

9 December 20041
SOAP
Simple Object Access Protocol
Content
1. Introduction to SOAP
2. Axis Server
3. Demo
Prof. Dr. Dominik Gruntz
FH Aargau
gruntz@fh-aargau.ch
http://www.cs.fh-aargau.ch/~gruntz
9 December 20042
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP
•Web Services Architecture
cross-platform interoperability between loosely coupled applications
–SOAPSimple Object Access Protocol Wire
–WSDLWeb Services Description LanguageDescription
XML grammerto describe SOAP enabled Web services
–UDDIUniversal Description, Discovery and Integration Discovery
discovery of web services on the internet ( ~ DNS )
•SOAP
–12/1999 SOAP v1.0Microsoft & Develop Mentor(D. Box)
–05/2000 SOAP v1.1+ IBM
–2003 SOAP v1.2www.w3.org/2002/ws
9 December 20044
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP Approach
•SOAP = Simple Object Access Protocol
(actually, today SOAP is no longer an acronym)
–simple, lightweight protocol for exchanging structured and typed
information on the Web
Protocol: HTTP, SMTP, FTP, raw TCP/IP, …..
Format: XML
Messaging type:one-way or request/response
•Design Goal: KISS
–can be implemented over a weekend
–stick to absolutely minimum of functionality
–based on existing and adopted standards (HTTP / XML)
9 December 20045
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP Example
•Book Store Service
service BookService{
booleanOrderBook(
/* in */ string title,
/* in */ string author,
/* out */ long daysToDeliver,
/* out */ double cost
);
};
=> 2 in-parameters
=> 2 out-parameters
=> 1 result
9 December 20046
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP HTTP Request
POST /BookStoreServletHTTP/1.1
Host: www.amazon.com
Content-Length: 162
Content-Type: text/xml; charset="utf-8"
SOAPAction: ”BookService"
<Envelope>
<Body>
<OrderBook>
<title>Understanding SOAP</title>
<author>Kennard Scribner</author>
</OrderBook>
</Body>
</Envelope>
HTTP Request
SOAP HTTP Binding
SOAP Payload
9 December 20047
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP HTTP Response (Success)
HTTP/1.0 200 OK
Content-Length: 162
Content-Type: text/xml; charset="utf-8"
<Envelope>
<Body>
<OrderBookResponse>
<return>true</return>
<daysToDeliver>3</daysToDeliver>
<cost>62.50</cost>
</OrderBookResponse>
</Body>
</Envelope>
9 December 20048
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP HTTP Response (Fault)
HTTP/1.0 500 Internal Server Error
Content-Length: 339
Content-Type: text/xml; charset="utf-8"
<Envelope>
<Body>
<Fault>
<faultcode>Server</faultcode>
<faultstring>Server Error</faultstring>
<detail>
<myfaultdetails>
<message>Book out of print</message>
<errorcode>4711</errorcode>
<myfaultdetails>
</detail>
</Fault>
</Body>
</Envelope>
9 December 20049
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP HTTP Request
POST /BookStoreServletHTTP/1.1
Host: www.amazon.com
Content-Length: 520
Content-Type: text/xml; charset="utf-8"
SOAPAction: ""
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:OrderBook xmlns:ns1="BookService" SOAP-ENV:
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<title xsi:type="xsd:string">Understanding SOAP</title>
<author xsi:type="xsd:string">Kennard Scribner</author>
</ns1:OrderBook>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
with namespaces name
collisions are avoided
determines version
of SOAP (1.1)
9 December 200410
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP HTTP Response (Success)
HTTP/1.0 200 OK
Content-Length: 580
Content-Type: text/xml; charset="utf-8"
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:OrderBookResponse xmlns:ns1="BookService" SOAP-ENV:
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:boolean">true</return>
<daysToDeliverxsi:type="xsd:integer">3</daysToDeliver>
<cost xsi:type="xsd:double">62.50</cost >
</ns1:OrderBookResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
9 December 200411
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP HTTP Response (Fault)
HTTP/1.0 500 Internal Server Error
Content-Length: 496
Content-Type: text/xml; charset="utf-8"
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/”>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Server Error</faultstring>
<detail>
<e:myfaultdetailsxmlns:e=“BookService”>
<message>Book out of print</message>
<errorcode>4711</errorcode>
</e:myfaultdetails>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
9 December 200412
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP Message
•sdf
•Envelope
–0..1 Header
–1 Body
•SOAP does not limit the type of
XML documents
=> flexibility
Envelope
Header
Body
xml
<…>
<…>
xml
<…>
<…>
xml
<…>
<…>
9 December 200413
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP Header
•Header Data
–Has to be processed on the message path (from sender to reciever)
–May contain additional information;
=> allows for modular addition of features and services, e.g.
Transaction IDs
Routing information
Security credentials (e.g. a digital signature)
Payment tokens
Debugging information
–SOAP intermediaries may
Process (and remove) header information
Add new header information
9 December 200414
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP Header Attributes
•actorattribute
–Specifies a role a node must play in order to process the header
(=> SOAP 1.2: role attribute)
–Roles are specified as URI
http://www.gruntz.ch/logger
http://schemas.xmlsoap.org/soap/actor/next
Default: ultimate receiver
•mustUnderstandattribute
("1" = true, "0" = false)
–if this attribute is set then the server must understand and handle this
header attribute, otherwise must fail processing the message
–Default: 0
9 December 200415
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP Header (example)
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<t:Transaction xmlns:t=”urn:ubs" SOAP-ENV:mustUnderstand="1">
5
</t:Transaction>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:Deposit xmlns:m=”urn:bank#132-23-2003a">
<m:amount>200</m:amount>
</m:Deposit>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
9 December 200416
(C) Fachhochschule Aargau
Nordwestschweiz
Data Types in SOAP
•simple types (data types defined in XML Schema Spec part 2)
<m:method>
<paraxsi:type=“int”>26</para>
</m:method>
•compound type
<m:method>
<book>
<title xsi:type=“xsi:string”>Inside C# </title>
<author xsi:type=“xsi:string”>Tom Archer</author>
</book>
</m:method>
9 December 200417
(C) Fachhochschule Aargau
Nordwestschweiz
Built-in data types of
XML Schema Part 2: Datatypes
9 December 200418
(C) Fachhochschule Aargau
Nordwestschweiz
Data Types in SOAP
•references
<m:compare>
<x href=“#book1”/>
<y href=“#book1”/>
</m:compare>
<m:book id=“book1”>
<title xsi:type=“xsi:string”>Inside C#</title>
<author xsi:type=“xsi:string”>Tom Archer</author>
</m:book>
•circular list
<m:method>
<x href=“#node1”/>
</m:method>
<m:node id=“node1”><next href=“#node2”></m:node>
<m:node id=“node2”><next href=“#node1”></m:node>
9 December 200419
(C) Fachhochschule Aargau
Nordwestschweiz
Array
•Java Argument
int[] primes = new int[]{2,3,5,7,11,13,17};
•XML Translation
<primes xsi:type="soapenc:Array"
soapenc:arrayType="xsd:int[7]"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<item>2</item>
<item>3</item>
<item>5</item>
<item>7</item>
<item>11</item>
<item>13</item>
<item>17</item>
</primes>
9 December 200420
(C) Fachhochschule Aargau
Nordwestschweiz
Example: Map
•Java Argument
Map m = new HashMap();
m.put("Daffy Duck", "123-444");
m.put("Lucky Luck", "123-445");
•XML Translation
<arg1 href="#id0"/>
<multiRefid="id0" soapenc:root="0" soapenv:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/" xsi:type=
"ns2:Map" xmlns:ns2="http://xml.apache.org/xml-soap"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" >
<item>
<key xsi:type="xsd:string">Daffy Duck</key>
<value xsi:type="xsd:string">123-444</value>
</item>
<item>
<key xsi:type="xsd:string">Lucky Luck</key>
<value xsi:type="xsd:string">123-445</value>
</item>
</multiRef>
9 December 200421
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP Summary
•Simple means:
–stateless objects (similar to internet)
–no call-backs (i.e. no bidirectional communications)
–no distributed garbage collection
–no objects-by-reference
–no remote object activation
–no session/state management
–no distributed transactions
•Advantages
–easy to implement (HTTP/XML)
–easy to install / administrate
–firewall friendly
9 December 200422
(C) Fachhochschule Aargau
Nordwestschweiz
SOAP Summary
•Security
–no security facility
custom security measures on top of SOAP
•WS-Security
custom security measures on top of HTTP
•HTTPS
•Efficiency
–performance loss of factor 10 (approx)
–most time is used in coding and parsing payload
9 December 200427
(C) Fachhochschule Aargau
Nordwestschweiz
Apache Axis
•Key Design Features
–Speed
SAX based
–Flexibility
design based around a chain of message handlers
extensions possible for custom header processing, system management, etc.
–Transport independence
the SOAP kernel is completely transport-independent (SMTP, FTP, MOM)
•Functionality
–Drop-In development
–WSDL support (WSDL <-> Java)
•Resources
–http://ws.apache.org/axis/index.html
9 December 200428
(C) Fachhochschule Aargau
Nordwestschweiz
Installing Axis
•Installation
–download and expand axis (http://ws.apache.org/axis/
)
Stable Release: Axis 1.1 [June 2003]
Release Candidate: Axis 1.2 [Nov 2004]
–copy axisfolder from
AXIS_HOME/webappsto
CATALINA_HOME/webapps
•Class-Path extension to include XML parser (xerces)
–Use jdk1.4 (or above)
–Alternatively: put xerces.jarin tomcat lib directory
9 December 200429
(C) Fachhochschule Aargau
Nordwestschweiz
Test Axis Installation
•Visit http://localhost:8080/axis
–To enable the dis-
abledfeatures,
uncomment the
appropriate de-
clarationsin
WEB-INF/web.xml
in the webapplication
and restart it.
9 December 200430
(C) Fachhochschule Aargau
Nordwestschweiz
Example Service:
1. Service Implementation
•Write Server
public class HelloServer{
public String sayHelloTo(Strings) {
return "[axis] Hello " + s + ", how are you?"
+ "["+ new java.util.Date() + "]";
}
}
•Store source as *.jwsfile (Java Web Service) in webapps/axis
–webapps/axis/HelloServer.jws
Restriction:
Packages cannot be used; JWS are
intended for simple services only
9 December 200431
(C) Fachhochschule Aargau
Nordwestschweiz
Example Service:
2. Client Implementation
import org.apache.axis.client.Call;
public class HelloClient{
public static void main(String[] args) throws Exception {
String endpoint =
"http://localhost:8080/axis/HelloServer.jws";
Call service = new Call(endpoint);
System.out.println(
service.invoke("sayHelloTo", new Object[]{args[0]})
);
}
}
9 December 200432
(C) Fachhochschule Aargau
Nordwestschweiz
Example Service:
3. Test & Demo
•Run Client (JDK 1.4)
–java HelloClientDominik
[axis] Hello Dominik, how are you? [Thu Dec 19 07:18:02 2002]
•SOAP Request
POST /axis/HelloServer.jwsHTTP/1.0
SOAPAction: ""
<?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>
<sayHelloTosoapenv:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/">
<arg0 xsi:type="xsd:string">Dominik</arg0>
</sayHelloTo>
</soapenv:Body>
</soapenv:Envelope>
9 December 200433
(C) Fachhochschule Aargau
Nordwestschweiz
Custom Deployment using WSDD
•Web Service Deployment Descriptor (WSDD)<deployment
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name = "HelloServer” provider="java:RPC">
<parameter
name="className" value="samples.hello.HelloServer"/>
<parameter
name="methodName" value="sayHelloTo"/>
</service>
</deployment>
–Additional information:
additional handlers (e.g. logging)
type mappings
scope information (Application / Request)
9 December 200434
(C) Fachhochschule Aargau
Nordwestschweiz
Custom Deployment using WSDD
•Admin Client
java org.apache.axis.client.AdminClientdeploy.wsdd
-Processing file deploy.wsdd
-<Admin>Done processing</Admin>
java org.apache.axis.client.AdminClientlist
•Configuration
–stored in file webapps\axis\WEB-INF\server-config.wsdd
–Inspect over http://localhost:8080/axis/servlet/AxisServlet
•Undeploy
<undeploymentxmlns="http://xml.apache.org/axis/wsdd/">
<service name="HelloServer"/>
</undeployment>
9 December 200435
(C) Fachhochschule Aargau
Nordwestschweiz
Client
package samples.hello;
import org.apache.axis.client.Call;
public class HelloClient{
public static void main(String[] args) throws Exception {
Call service = new Call(
"http://localhost:8080/axis/servlet/AxisServlet");
System.out.println(
service.invoke("HelloServer", "sayHelloTo",
new Object[]{args[0]})
);
}
}
9 December 200436
(C) Fachhochschule Aargau
Nordwestschweiz
Client
package samples.hello;
import ...
public class HelloClient1 {
public static void main(String[] args) throws Exception {
String endpoint = "http://localhost:8081/axis/servlet/AxisServlet";
Call call= new Call(newService());
String result = "";
try {
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( new QName("HelloServer", "sayHelloTo") );
call.addParameter( "name", Constants.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
result = (String) call.invoke( new Object[] { args[0] } );
}
catch (AxisFaultfault) {result = "Error : " + fault.toString();}
System.out.println(result);
}
}
9 December 200437
(C) Fachhochschule Aargau
Nordwestschweiz
WSDL
•Web Service Description Language
–specification of Web Services (IBM / Microsoft)
–used to access service from .NET / SOAP::Lite, …
•WSDL for deployed services
–http://localhost:8080/axis/HelloServer.jws?wsdl
–http://localhost:8080/axis/services/HelloServer?wsdl
–Java2WSDL
java org.apache.axis.wsdl.Java2WSDL
9 December 200438
(C) Fachhochschule Aargau
Nordwestschweiz
WSDL: Stub/Skeleton generation
•Wsdl2java
–java org.apache.axis.wsdl.WSDL2Java -p samples.hello.proxy
samples\hello\HelloServer.wsdl
•Generated Files
–HelloServerPortTypeservice interface
–HelloServerfactory interface
–HelloServerSoapBindingStubservice proxy
–HelloServerLocatorfactory implementation
9 December 200439
(C) Fachhochschule Aargau
Nordwestschweiz
HelloServer: Generated Classes
•HelloServerPortType
package samples.hello.proxy;
import java.rmi.*;
public interface HelloServerPortTypeextends Remote {
public String sayHelloTo(StringnameOfClient)
throws RemoteException;
}
•HelloServer
package samples.hello.proxy;
import javax.xml.rpc.*;
public interface HelloServerextends Service {
public String getHelloServerPortAddress();
public HelloServerPortTypegetHelloServerPort()
throws ServiceException;
public HelloServerPortTypegetHelloServerPort(
java.net.URLportAddress) throws ServiceException
}
9 December 200440
(C) Fachhochschule Aargau
Nordwestschweiz
HelloServer: Generated Classes
•HelloServerSoapBindingStub
package samples.hello.proxy;
public class HelloServerSoapBindingStub
extends javax.xml.rpc.Stub
implements samples.hello.proxy.HelloServerPortType{
public String sayHelloTo(Stringarg0)
throws java.rmi.RemoteException{...}
// From javax.xml.rpc.Stub
public void _setProperty(Stringname, Object value) {...}
public Object _getProperty(Stringname) {...}
public void _setTargetEndpoint(java.net.URLaddress) {...}
public java.net.URL_getTargetEndpoint() {...}
public void setMaintainSession(booleansession) {...}
// From javax.naming.Referenceable
public javax.naming.ReferencegetReference() {...}
}
9 December 200441
(C) Fachhochschule Aargau
Nordwestschweiz
HelloServer: Client (using proxies)
•Client
package samples.hello;
import samples.hello.proxy.HelloServerPortType;
import samples.hello.proxy.HelloServerLocator;
public class HelloClient2 {
public static void main(String[] args) throws Exception {
HelloServerPortTypeport =
new HelloServerLocator().getHelloServerPort();
System.out.println(port.sayHelloTo(args[0]));
}
}
9 December 200442
(C) Fachhochschule Aargau
Nordwestschweiz
Axis SoapMonitor
•Deploy Monitoring Service
<deploymentxmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler name="soapmonitor"
type="java:org.apache.axis.handlers.SOAPMonitorHandler">
<parameter name="wsdlURL" value="/axis/SOAPMonitorService-impl.wsdl"/>
<parameter name="namespace"
value="http://tempuri.org/wsdl/2001/12/SOAPMonitorService-impl.wsdl"/>
<parameter name="serviceName" value="SOAPMonitorService"/>
<parameter name="portName" value="Demo"/>
</handler>
<service name="SOAPMonitorService" provider="java:RPC">
<parameter name="allowedMethods" value="publishMessage"/>
<parameter name="className"
value="org.apache.axis.monitor.SOAPMonitorService"/>
<parameter name="scope" value="Application"/>
</service>
</deployment>
9 December 200443
(C) Fachhochschule Aargau
Nordwestschweiz
Axis SoapMonitor
•Compile Applet
–axis\SoapMonitorApplet.java
•Activate Monitoring
–For each service that is to be monitored, add request and response flow
definitions to the service's deployment descriptor
<service name="quotes" provider="java:RPC">
<requestFlow>
<handler type="soapmonitor"/>
</requestFlow>
<responseFlow>
<handler type="soapmonitor"/>
</responseFlow>
•Bring up the SOAP Monitor
–http://localhost:8080/axis/SOAPMonitor