Вы находитесь на странице: 1из 5

What is SOAP?

• SOAP stands for Simple Object Access Protocol


• SOAP is a communication protocol
• SOAP is for communication between applications
• SOAP is a format for sending messages
• SOAP is designed to communicate via Internet
• SOAP is platform independent
• SOAP is language independent
• SOAP is based on XML
• SOAP is simple and extensible
• SOAP allows you to get around firewalls
• SOAP will be developed as a W3C standard

Why SOAP?

It is important for application development to allow Internet communication between programs.

Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA, but
HTTP was not designed for this. RPC represents a compatibility and security problem; firewalls and proxy servers will
normally block this kind of traffic.

A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers
and servers. SOAP was created to accomplish this.

SOAP provides a way to communicate between applications running on different operating systems, with different
technologies and programming languages.

Syntax Rules

Here are some important syntax rules:

• A SOAP message MUST be encoded using XML


• A SOAP message MUST use the SOAP Envelope namespace
• A SOAP message MUST use the SOAP Encoding namespace
• A SOAP message must NOT contain a DTD reference
• A SOAP message must NOT contain XML Processing Instructions

The HTTP Protocol

HTTP communicates over TCP/IP. An HTTP client connects to an HTTP server using TCP. After establishing a
connection, the client can send an HTTP request message to the server:

The server then processes the request and sends an HTTP response back to the client. The response contains a status code
that indicates the status of the request:

SOAP HTTP Binding

A SOAP method is an HTTP request/response that complies with the SOAP encoding rules.
1.1.1. HTTP + XML = SOAP

A SOAP request could be an HTTP POST or an HTTP GET request.

The HTTP POST request specifies at least two HTTP headers: Content-Type and Content-Length.

What is WSDL?

• WSDL stands for Web Services Description Language


• WSDL is written in XML
• WSDL is an XML document
• WSDL is used to describe Web services
• WSDL is also used to locate Web services
• WSDL is not yet a W3C standard

WSDL Describes Web Services

WSDL stands for Web Services Description Language.

WSDL is a document written in XML. The document describes a Web service. It specifies the location of the service and
the operations (or methods) the service exposes.

Binding to SOAP

The binding element has two attributes - the name attribute and the type attribute.

The name attribute (you can use any name you want) defines the name of the binding, and the type attribute points to the
port for the binding, in this case the "glossaryTerms" port.

The soap:binding element has two attributes - the style attribute and the transport attribute.

The style attribute can be "rpc" or "document". In this case we use document. The transport attribute defines the SOAP
protocol to use. In this case we use HTTP.

The operation element defines each operation that the port exposes.

For each operation the corresponding SOAP action has to be defined. You must also specify how the input and output are
encoded.

WSDL documents that describes a web service. It also specifies the location of the service and the operations (or methods)
the service exposes.
define the message format and protocol details for a web service.

SAX PARSER….

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

private static final String SAX_PARSER = "org.apache.xerces.parsers.SAXParser";

//parse request xml and populate into DTO


//use a the XMLReaderFactory to create the XMLReader and hide the
// implementation parser in case we change it
//one example - parser =
// XMLReaderFactory.createXMLReader(SAX_PARSER);
//SAX_PARSER = "org.apache.xerces.parsers.SAXParser"
//Post Production Change Start - 02/01/2008
XMLReader xr = XMLReaderFactory.createXMLReader(SAX_PARSER);
//XMLReader xr = new org.apache.xerces.parsers.SAXParser();
//Post Production Change End - 02/01/2008

PrcRecallInpXMLParser xmlHandler = new PrcRecallInpXMLParser();


xr.setContentHandler(xmlHandler);
StringWriter stringWriter = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(elems[0]), new StreamResult(stringWriter));
xr.parse(new InputSource(new StringReader(stringWriter.getBuffer().toString())));
prcRecallDTO = xmlHandler.parseInputXML();
//Input Validations
prcRecallDTO = (new
PrcRecallInpXMLValidator()).validateRePricingInput(prcRecallDTO);
************************************************************************************************

The XML documents you have to parse are getting too large to load the entire document tree into
memory; performance is suffering. The solution: use SAX.
1.1.2. Understanding Event-Driven XML Processing

SAX (Simple API for XML) is an event-driven model for processing XML. Most XML processing models (for
example: DOM and XPath) build an internal, tree-shaped representation of the XML document. The
developer then uses that model's API (getElementsByTagName in the case of the DOM or findnodes using
XPath, for example) to access the contents of the document tree. The SAX model is quite different. Rather
than building a complete representation of the document, a SAX parser fires off a series of events as it reads
the document from beginning to end. Those events are passed to event handlers, which provide access to
the contents of the document.

1.1.3. Event Handlers

There are three classes of event handlers: DTDHandlers, for accessing the contents of XML Document-Type
Definitions; ErrorHandlers, for low-level access to parsing errors; and, by far the most often used,
DocumentHandlers, for accessing the contents of the document. For clarity's sake, I'll only cover
DocumentHandler events.

A SAX processor will pass the following events to a DocumentHandler:

• The start of the document.


• A processing instruction element.
• A comment element.
• The beginning of an element, including that element's attributes.
• The text contained within an element.
• The end of an element.
• The end of the document.

Вам также может понравиться