B.2 SOAP Transport Classes


Because the bulk of the work is done within the SOAP::Lite module itself, many of the transport-level modules are very simple in their implementations . Transport modules are expected to define both client and server classes within their files. If a module defines only one of the types, it is assumed that the transport protocol itself supports only that side of the conversation. An example is SOAP::Transport::FTP , which provides only a SOAP::Transport::FTP::Client class.

Each class is expected to declare (or inherit, if it is subclassing another transport class) at least two methods . Any newly developed transport classes is also expected to adhere to this interface. Here are the methods:

new( optional key/value pairs )
 $object = $class->new(%params); 

Creates a new object instance and returns it. Like the constructors for both SOAP::Lite and SOAP::Server classes, all arguments passed in are treated as key/value pairs, where the key is expected to be one of the methods the class supports, and the value is the argument (or list reference of arguments) to the method.

send_receive( key/value pairs )
 $client->send_recieve(%hash_table); 

(Required for client classes only) When the SOAP::Lite objects attempt to send out requests , the means for doing so is to attempt to call this method on the object held within the SOAP::Transport object contained within the client itself. All clients are expected to provide this, and the call to this method always passes four values for the hash keys:

action

The URI specifying the action being performed, usually the result from the on_action hook on the client object.

encoding

The URI of the encoding scheme that governs the message being sent.

endpoint

The URI specifying the endpoint to which the message is being sent.

envelope

The XML content of the message to be sent. It is generally the return value of the envelope method from the SOAP::Serializer object instance that the client object maintains.

handle
 $server->handle; 

(Required for server classes only.) This method is the central point for the various server classes to provide an interface to handling requests. The exact set and nature of parameters generally varies based on the classes themselves .

Each individual transport module is now examined, and their provision of client and/or server classes is outlined. Each class detailed also includes notes on which of the classes from SOAP::Lite they inherit from, for reference.

B.2.1 SOAP::Transport::FTP

The SOAP::Transport::FTP module is automatically loaded by the SOAP::Transport portion of the client structure. It is brought in when an endpoint is specified via the proxy method that starts with the characters , ftp:// . This module provides only a client class.

B.2.1.1 SOAP::Transport::FTP::Client

Inherits from: SOAP::Client .

Support is provided for clients to connect to FTP servers using SOAP. The methods defined within the class are just the basic new and send_receive .

B.2.2 SOAP::Transport::HTTP

The most commonly used transport module is the HTTP implementation. This is loaded whenever an endpoint is given that starts with the characters, http:// or https :// . This is also the most involved of the transport modules, defining not only a client class but several different server classes as well.

B.2.2.1 SOAP::Transport::HTTP::Client

Inherits from: SOAP::Client , LWP::UserAgent (from the LWP package).

With this class, clients are able to use HTTP for sending messages. This class provides just the basic new and send_receive methods. Objects of this class understand the compress_threshold option and use it if the server being communicated to also understands it.

B.2.2.2 SOAP::Transport::HTTP::Server

Inherits from: SOAP::Server .

This is the most basic of the HTTP server implementations. It provides the basic methods, new and handle . The handle method's behavior is defined here, along with other methods specific to this class. The role of this class is primarily to act as a superclass for the other HTTP-based server classes.

handle
 $server->handle; 

Expects the request method to have been used to associate a HTTP::Request object with the server object prior to being called. This method retrieves that object reference to get at the request being handled.

request( optional value )
 $server->request($req_object) 

Gets or sets the HTTP::Request object reference that the server will process within the handle method.

response( optional value )
 $server->response(HTTP::Response->new(   ...   )); 

Gets or sets the HTTP::Response object reference that the server has prepared for sending back to the client.

make_response( code, body )
 $server->make_response(200, $body_xml); 

Constructs and returns an object of the HTTP::Response class, using the response code and content provided.

make_fault( fault arguments )
 $server->response($server->make_fault(@data)); 

Creates a HTTP::Response object reference using a predefined HTTP response code to signify that a fault has occurred. The arguments are the same as those for the make_fault method of the SOAP::Server class.

product_tokens

This method takes no arguments and simply returns a string identifying the elements of the server class itself. It is similar to the product_tokens methods in the HTTP::Daemon and Apache classes.

B.2.2.3 SOAP::Transport::HTTP::CGI

Inherits from: SOAP::Transport::HTTP::Server .

This class is a direct subclass of SOAP::Transport::HTTP::Server and defines no additional methods. It includes logic in its implementation of the handle method that deals with the request headers and parameters specific to a CGI environment.

B.2.2.4 SOAP::Transport::HTTP::Daemon

Inherits from: SOAP::Transport::HTTP::Server .

The SOAP::Transport::HTTP::Daemon class encapsulates a reference to an object of the HTTP::Daemon class (from the LWP package). The class catches methods that aren't provided locally or by the superclass and attempts to call them on the HTTP::Daemon object. Thus, all methods defined in the documentation for that class are available to this class as well. Any that conflict with methods in SOAP::Transport::HTTP::Server (such as product_tokens ) go to the superclass. Additionally, the behavior of the handle method is specific to this class:

handle

When invoked, this method enters into the typical accept loop in which it waits for a request on the socket that the daemon object maintains and deals with the content of the request. When all requests from the connection returned by the accept method of the HTTP::Daemon object have been processed , this method returns.

B.2.2.5 SOAP::Transport::HTTP::Apache

Inherits from: SOAP::Transport::HTTP::Server .

This class provides an integration of the SOAP::Server base class with the mod_perl extension for Apache. To work as a location handler, the package provides a method called handler , for which handle is made an alias. The new method isn't functionally different from the superclass. Here are the other methods provided by this class:

handler( Apache request )
 $server->handler($r) 

Defines the basis for a location handler in the mod_perl fashion. The method expects an Apache request object as the parameter, from which it pulls the body of the request and calls the superclass handle method. Note that in this class, the local method named handle is aliased to this method.

configure( Apache request )
 $server->configure(Apache->request); 

Per-location configuration information can be provided to the server object using the Apache DirConfig directive and calling this method on the object itself. When invoked, the method reads the directory configuration information from Apache and looks for lines of the form:

   method   =>   param   

Each line that matches the pattern is regarded as a potential method to call on the server object, with the remaining token taken as the parameter to the method. Methods that take hash references as arguments may be specified as:

   method   =>   key   =>   param   ,   key   =>   param   

The key/value pairs will be made into a hash reference on demand. If the server object doesn't recognize the named method as valid, it ignores the line.

B.2.2.6 SOAP::Transport::HTTP::FCGI

Inherits from: SOAP::Transport::HTTP::CGI .

This is an extension of the SOAP::Transport::HTTP::CGI that implements the differences needed for the FastCGI protocol. None of the methods are functionally different.

B.2.3 SOAP::Transport::IO

The SOAP::Transport::IO -based class allows for a sort of I/O proxying by allowing the application to configure what files or filehandles are used. This module supplies only a server class.

B.2.3.1 SOAP::Transport::IO::Server

Inherits from: SOAP::Server .

The server class defined here inherits all methods from SOAP::Server , and adds two additional methods specific to the nature of the class:

in
 $server->in(IO::File->new($file)); 

Gets or sets the current filehandle being used as the input source.

out
 $server->out(\*STDERR); 

Gets or sets the filehandle being used as the output destination.

B.2.4 SOAP::Transport::JABBER

This class uses the Net::Jabber classes to abstract the Jabber protocol away from the direct notice of the application. Besides maintaining any needed objects internally, the package also uses a separate class as a proxy between communication layers , SOAP::Transport::JABBER::Query . The Jabber support provides both client and server classes.

B.2.4.1 SOAP::Transport::JABBER::Client

Inherits from: SOAP::Client , Net::Jabber::Client .

This class provides localized implementations for both the new and send_receive methods, neither of which are changed in terms of interface. The only difference is that the send_receive method doesn't directly use the action hash key on the input it receives. In addition to these two basic methods, the server class overrides the endpoint method it would otherwise inherit from SOAP::Client :

endpoint

In the general sense, this still acts as a basic accessor method, with the same get value/set value behavior used consistently through the SOAP::Lite module. The difference between this version and most others is that when the endpoint is initially set or is changed, the client object makes the connection to the Jabber endpoint, sending the proper authentication credentials and setting up the conversation mechanism using the SOAP::Transport::JABBER::Query class as a delegate. It then calls the superclass endpoint method to ensure that all other related elements are taken care of.

B.2.4.2 SOAP::Transport::JABBER::Server

Inherits from: SOAP::Server .

The server class provided for Jabber support defines a slightly different interface to the constructor. The server manages the Jabber communication by means of an internal Net::Jabber::Client instance. In a fashion similar to that used by SOAP::Transport::HTTP::Daemon , the server class catches methods that are meant for the Jabber client and treats them as if the class inherits directly from that class, without actually doing so. In doing so, the handle method is implemented as a frontend to the Process method of the Jabber client class. The difference in the interface to the constructor is:

new( URI, optional server key/value options )
 $srv = SOAP::Transport::JABBER::Server-> new($uri); 

The constructor for the class expects that the first argument will be a Jabber-style URI, followed by the standard set of optional key/value pairs of method names and their parameters. All the method/parameter pairs are delegated to the superclass constructor; only the Jabber URI is handled locally. It's used to set up the Net::Jabber::Client instance that manages the actual communications.

B.2.5 SOAP::Transport::LOCAL

The SOAP::Transport::LOCAL module is designed to provide a no-transport client class for tracing and debugging communications traffic. It links SOAP::Client and SOAP::Server so that the same object that "sends" the request also "receives" it.

B.2.5.1 SOAP::Transport::LOCAL::Client

Inherits from: SOAP::Client , SOAP::Server .

The implementations of the new and send_receive methods aren't noticeably different in their interface. Their behavior warrants description, however:

new

When the constructor creates a new object of this class, it sets up a few things beyond the usual SOAP::Client layout. The is_success method is set to a default value of 1 . The dispatch_to method inherited from SOAP::Server is called with the current value of the global array @INC , allowing the client to call any methods that can be found in the current valid search path . And as with most of the constructors in this module, the optional key/value pairs are treated as method names and parameters.

send_receive

The implementation of this method simply passes the envelope portion of the input data to the handle method of SOAP::Server . While no network traffic results (directly) from this, it allows for debug signals to be sent through the SOAP::Trace facility.

B.2.6 SOAP::Transport::MAILTO

This transport class manages SMTP-based sending of messages from a client perspective. It doesn't provide a server class. The class gets selected when a client object passes a URI to proxy or endpoint that starts with the characters, mailto: .

B.2.6.1 SOAP::Transport::MAILTO::Client

Inherits from: SOAP::Client .

The client class for this protocol doesn't define any new methods. The constructor functions in the same style as the others class constructors. The functionality of the send_receive method is slightly different from other classes, however.

When invoked, the send_receive method uses the MIME::Lite package to encapsulate and transmit the message. Because mail messages are one-way communications (the reply being a separate process), there is no response message to be returned by the method. Instead, all the status-related attributes ( code , message , status , is_success ) are set, and no value is explicitly returned.

B.2.7 SOAP::Transport::MQ

This class provides implementations of both client and server frameworks built on IBM's Message Queue set of classes. The SOAP objects encapsulate additional objects from these classes, creating and using them behind the scenes as needed.

B.2.7.1 SOAP::Transport::MQ::Client

Inherits from: SOAP::Client .

The client class provides two methods specific to it, as well as specialized versions of the endpoint and send_receive methods. It also provides a localized new method, but the interface isn't changed from the superclass method. The new methods are:

requestqueue
 $client->requestqueue->Put(message => $request); 

Manages the MQSeries::Queue object the client uses for enqueuing requests to the server. In general, an application shouldn't need to directly access this attribute, let alone set it. If setting it, the new value should be an object of (or derived from) the MQSeries::Queue class.

replyqueue
 $client->replyqueue(MQSeries::Queue->new(%args)); 

Manages the queue object used for receiving messages back from the designated server (endpoint). It is also primarily for internal use, though if the application needs to set it explicitly, the new value should be an object of (or derived from) the MQSeries::Queue class.

The two previous methods are mainly used by the localized versions of the methods:

endpoint

This accessor method has the same interface as other similar classes but is worth noting for the internal actions that take place. When the endpoint is set or changed, the method creates a queue-manager object (from the MQSeries::QueueManager class) and references this object when creating queues for replies and requests using the methods described earlier. The URI structure used with these classes (strings beginning with the characters mq:// user @host:port ) contains the information needed for these operations.

send_receive

This method uses the same interface as other classes, but makes use of only the endpoint and envelope keys in the hash-table input data. The endpoint key is needed only if the client wishes to switch endpoints prior to sending the message. The message (the value of the envelope key) is inserted into the queue stored in the requestqueue attribute. The client then waits for a reply to the message to appear in the queue stored in the replyqueue attribute.

B.2.7.2 SOAP::Transport::MQ::Server

Inherits from: SOAP::Server .

The server class also defines requestqueue and replyqueue methods under the same terms as the client class. Of course, the server reads from the request queue and writes to the reply queue, the opposite of the client's behavior. The methods whose functionality are worth noting are:

new( URI, optional parameters )

When called, the constructor creates the MQSeries::QueueManager object and the two MQSeries::Queue objects, similar to what the client does inside its endpoint method. Like the Jabber server described earlier, the first argument to this constructor is expected to be the URI that describes the server itself. The remainder of the arguments are treated as key/value pairs, as with other class constructors previously described.

handle

When this method is called, it attempts to read a pending message from the request-queue stored on the requestqueue attribute. The message itself is passed to the handle method of the superclass, and the result from that operation is enqueued to the replyqueue object. This process loops until no more messages are present in the request queue. The return value is the number of messages processed. The reads from the request queue are done in a nonblocking fashion, so if there is no message pending, the method immediately returns with a value of zero.

B.2.8 SOAP::Transport::POP3

POP3 support is limited to a server implementation. Just as the MAILTO class detailed earlier operates by sending requests without expecting to process a response, the server described here accepts request messages and dispatches them without regard for sending a response other than that which POP3 defines for successful delivery of a message.

B.2.8.1 SOAP::Transport::POP3::Server

Inherits from: SOAP::Server .

The new method of this class creates an object of the Net::POP3 class to use internally for polling a specified POP3 server for incoming messages. When an object of this class is created, it expects an endpoint to be specified with a URI that begins with the characters pop:// and includes user ID and password information as well as the hostname itself.

The handle method takes the messages present in the remote mailbox and passes them (one at a time) to the superclass handle method. Each message is deleted after being routed. All messages in the POP3 mailbox are presumed to be SOAP messages.

Methods for the Net::POP3 object are detected and properly routed, allowing operations such as $server->ping( ) . This means that the endpoint string doesn't need to provide the user ID and password because the login method from the POP3 API may be used directly.

B.2.9 SOAP::Transport::TCP

The classes provided by this module implement direct TCP/IP communications methods for both clients and servers. The connections don't use HTTP or any other higher-level protocol. These classes are selected when the client or server object being created uses an endpoint URI that starts with tcp:// . Both client and server classes support using Secure Socket Layer if it is available. If any of the parameters to a new method from either of the classes begins with SSL_ (such as SSL_server in place of Server ), the class attempts to load the IO::Socket::SSL package and use it to create socket objects.

Both of the following classes catch methods that are intended for the socket objects and pass them along, allowing calls such as $client->accept( ) without including the socket class in the inheritance tree.

B.2.9.1 SOAP::Transport::TCP::Client

Inherits from: SOAP::Client .

The TCP client class defines only two relevant methods beyond new and send_receive . These methods are:

SSL( optional new boolean value )
 if ($client->SSL) # Execute only if in SSL mode 

Reflects the attribute that denotes whether the client object is using SSL sockets for communications.

io_socket_class
 ($client->io_socket_class)->new(%options); 

Returns the name of the class to use when creating socket objects for internal use in communications. As implemented, it returns one of IO::Socket::INET or IO::Socket::SSL , depending on the return value of the previous SSL method.

If an application creates a subclass that inherits from this client class, either method is a likely target for overloading. The new method behaves identically to most other classes, except that it detects the presence of SSL- targeted values in the parameter list and sets the SSL method appropriately if they are present.

The send_receive method creates a socket of the appropriate class and connects to the configured endpoint. It then sets the socket to nonblocking I/O, sends the message, shuts down the client end of the connection (preventing further writing), and reads the response back from the server. The socket object is discarded after the response and appropriate status codes are set on the client object.

B.2.9.2 SOAP::Transport::TCP::Server

Inherits from: SOAP::Server .

The server class also defines the same two additional methods as in the client class:

SSL( optional new boolean value )
 if ($client->SSL) # Execute only if in SSL mode 

Reflects the attribute that denotes whether the client object is using SSL sockets for communications.

io_socket_class
 ($client->io_socket_class)->new(%options); 

Returns the name of the class to use when creating socket objects for internal use in communications. As implemented, it returns one of IO::Socket::INET or IO::Socket::SSL , depending on the return value of the previous SSL method.

The new method also manages the automatic selection of SSL in the same fashion as the client class does.

The handle method in this server implementation isn't designed to be called once with each new request. Rather, it is called with no arguments, at which time it enters into an infinite loop of waiting for a connection, reading the request, routing the request and sending back the serialized response. This continues until the process itself is interrupted by an untrapped signal or similar means.



Programming Web Services with Perl
Programming Web Services with Perl
ISBN: 0596002068
EAN: 2147483647
Year: 2000
Pages: 123

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net