| Join wMUsers | Blog at wMUsers | User Control Panel | Site Map | webMethods Jobs |For Employers |
![]() |
![]() |
IntroductionThe Perl language has long been referred to as "the glue of the internet" for its ability to bind disparate systems together with relative ease. Accordingly, there are bindings for seemingly every network-based software package under the sun. There is now one for webMethods, too. This article is intended for the Perl developer who wants to natively develop clients and adapters using his favorite language. It as also for developers who have legacy systems written in Perl to which they want to easily attach to a broker. For the unconverted who would like to learn what Perl has to offer, the Perl homepage is the best place to start. About the Perl "Aw" packageThe Perl "Aw" package was developed between late-1999 and early-2002. It was originally built as an interface to the ActiveWorks 3.0 C libraries. Hence the "Aw" name of the package. The Aw package has been available under an open source license from the Comprehensive Perl Archive Network (CPAN) since mid-2000. Developed with the Perl extension language, XS, the Aw package marshals native Perl methods calls to the C libraries. The package provides an object-oriented interface, closely following the Java APIs, to the comprehensive set of C functions exposed through the C header files. In a nutshell, the Aw package is a Perl OO wrapper around the C CADK. Given that the C libraries underlie the package, not quite everything in the Java CADK could be duplicated. Being a Perl interface, it was not always advantageous to mimic Java precisely. In a number of cases, the interfaces are adjusted to harness the power of the Perl language. When this style is used, however, the original Java style interface is still available to the developer. Building adapters and clientsOne of the most alluring features of the Perl language is its simple use of associative arrays. Colloquially, associative arrays are referred to as "hashes" in Perl. Hashes are used throughout the package whenever the approach offers a measure of convenience. Usually, this occurs each time that a collection of related data must be managed. The Aw package contains several sample adapters and clients to demonstrate their composition. Let's look at how a simple adapter might be set up. Below, we have a code fragment from a typical adapter:
1 package SimpleAdapter;
2 use base qw( Aw::Adapter ); # inheritance
3
4 sub processRequest
5 {
6 my ($self, $requestEvent, $eventDef) = @_;
7
8 my %hash = $requestEvent->toHash;
9 :
10 # process request...
11 :
12 $self->deliverAckReplyEvent;
13
14 1;
15 }
16
17 :
18 # other methods...
19 :
20
21 sub main: {
22
23 my $properties ={
24 clientId => 'myAdapter',
25 broker => 'test@myhost.com:8849',
26 adapterId => 0,
27 debug => 1,
28 clientGroup => 'myAdapterGroup',
29 adapterType => 'demoAdapter',
30 messageCatalog => 'myCatalog # optional
31 };
32
33 my $adapter = new SimpleAdapter ( $properties );
34 :
35 # subscribe to events, initialize, etc...
36 :
37 $adapter->getEvents; # continue until interupt
38 :
39 }
In this sample. the adapter is instantiated with a properties hash. In place of the properties hash, a properties array can be used following the traditional style argument lists. For an example of both approaches, review the script "time_adapter.pl". The adapter code fragment also presents the processRequest callback that handles received requests. The processPublish callback and other expected callbacks are invoked as well, when appropriate. A sample broker client is shown in our next code segment:
1 # set the default broker during package import 2 use Aw 'test@myhost.com:8849'; 3 require Aw::Client; 4 require Aw::Event; 5 6 # "new" applies the default broker 7 my $client = new Aw::Client ( "myClientGroup" ); 8 9 $client->newSubscription ( "Demo::test" ); 10 11 my $event = new Aw::Event ( $client, "Demo::testRequest" ); 12 13 $event->setTag ( 1 ); 14 $client->publish ( $event ) and die ( "Publish Error: $!" ); 15 16 17 my $reply = $client->getEvent( AW_INFINITE ); 18 19 print "Received a ", $reply->getTypeName, ""; 20 21 my %data = $reply->toHash; 22 : 23 : In this sample, the "new" constructor creates the client on the default broker (line 2) and assigns an identification based upon the script name. The client class we have created is an You may have noticed that the adapter is created without providing a configuration file. If a configuration file must be specified, you may use the "configFile" key and value. This approach is also shown in the script "time_adapter.pl". Go Deeper on the Subject: The wMUsers Discussion Forums Daniel Mekonnen has over 10 years of IT experience working with information exchange systems and has worked with webMethods since 1999. He enjoys the challenge of bringing systems together with enterprise technologies, data architecture design, and XML API design with standards like SOAP, WSDL and XML-RPC. Daniel works as a consultant in Northern Virginia.
Daniel can be reached via email at |
| © All Rights Reserved, 2001-2008. |