#!/usr/bin/perl -Tw use SOAP::Transport::HTTP; # use Pod::WSDL; # perl 5.8.5 minimum! use XML::Writer; use CGI qw(:standard); use Data::Dumper; use strict; my $doc=<<'EOT'; This perl program is a SOAP server intended to demonstrate SOAP web services for providing Ocean Observing System Data.

On this site, the data is encoded as constants in this file.

This program could be installed at different sites and modified to serve data from other sources. EOT my ($parameter, $result) = 0; #if ( $cgi->dispatch_with =={}) { # print header, "

",Dumper($cgi),"
"; # #} if ( $ENV{HTTP_SOAPACTION} ) { # Answer both SOAP and non-SOAP requests my $cgi=SOAP::Transport::HTTP::CGI -> dispatch_to('Demo'); $cgi-> handle; } else { # Try to process as a plain CGI request my $query = new CGI; $_ = $query->param('keywords'); # attempt the URL?keywords actions SWITCH : { if (/^wsdl$/ ) { print "Content-type: application/xml\n\n",Demo::wsdl(); last ;}; if (/^listProgram$/) { print "Content-type: text/plain\n\n"; open(FILE,"<$0"); while () {print $_ }; close(FILE); last;}; if (/^getLatest/) { $parameter = 'salinity'; print "Content-type: text/plain\n\n", (Demo::getLatest('Demo',$parameter))[0]; last;}; if (/^xmlGetLatest$/) { $result = [Demo::xmlGetLatest('Demo','salinity')]->[0]; $result = (Demo::xmlGetLatest('Demo','salinity','bb'))[0]; print "Content-type: application/xml\n\n", $result; last;}; # default case : my $wsdlLocation='http://sura-vims-pe6600-1.vims.edu/~drf/cgi-bin/oostech.cgi?wsdl'; print "Content-type: text/html\n\n\n"; print <<"EOT"; $doc
This SOAP server has a WSDL at oostech.cgi?wsdl and may be queried for the salinity data with...

Additionally, this program also acts as a cgi server that will serve the latest salinity data as:

This code was written using the following references:

EOT #print "
ENV:\n",Dumper(\%ENV);
#print "CGI Vars:\n",Dumper(\{$query->Vars}),"
\n"; } # end of CGI processing 1; } # end of service package Demo; use Data::Dumper; =begin WSDL _RETURN $string The 'hello, world' string =end WSDL =cut sub hi { return "hello, world from $0"; } =begin WSDL _RETURN $string A goodbye string =end WSDL =cut sub bye { return "goodbye, cruel world"; } =begin WSDL _RETURN $string the wsdl =end WSDL =cut sub wsdl{ my $basename = $0; $basename =~ s|^.*/||; # my $pod = new Pod::WSDL( # source => "$0", # location => "http://localhost/~drf/cgi-bin/$basename", # pretty => 1, # withDocumentation => 1); # return $pod->WSDL; # Pod.WSDL needs perl 5.8.5 so... my $pod = ''; open (WSDL,'<','oostech_wsdl.xml'); while() { $pod .= $_ } return $pod; } =begin WSDL _return $string the latest parameter reading (Currently a constant) _IN parameter $string A parameter of interest _IN boundingBox $string An optional bounding box to search =end WSDL =cut sub getLatest { my ($class, $parameter, $boundingBox) = @_; my $result = -9999; # Simulate a text file in memory and read from it my $datafilevar=<<'EOT'; #datetime, winddir, windspeed, salinity, temperature 20051225T100100, 120, 5.5, 13, 45.2 20051227T131600, 180, 10.0, 14, 46.00 EOT # set up some variables my %data; open(DATAFILE, '<', \$datafilevar); # open the string while () { # loop for the last observation @data{'datetime','winddirection','windspeed','salinity','temperature'} = split(/,\s*/); } close(DATAFILE); $result = $data{$parameter}; return ($result); } =begin WSDL _return $string XML containing ioosData.xml of the lastest parameter data in the boundingbox _IN parameter $string A parameter of interest _IN boundingBox $string XML descriptor of the bounding box to search. =end WSDL =cut sub xmlGetLatest { my ($package,$parameter, $boundingBox) = @_; my $openioosXML; my $GMLns = "http://www.opengis.net/gml"; my $ioosns = "http://www.openioos.org/"; my $xmlns = "http://fixme/"; my $DublinNS = "http://purl.org/dc/elements/1.1/"; my $defaultns = "http://mine.own.default.ns/"; my $writer = new XML::Writer(OUTPUT => \$openioosXML, NAMESPACES => 1, # NEWLINES => 1, DATA_INDENT=>4, DATA_MODE => 1, PREFIX_MAP => { $ioosns => 'openioos', $xmlns => 'xmlns', $DublinNS => 'dc', $GMLns => 'gml', $defaultns => '' } ); # Simulate a text file in memory and read from it my $datafilevar=<<'EOT'; #datetime, winddir, windspeed, salinity, temperature 20051225T100100, 120, 5.5, 13, 45.2 20051227T131600, 180, 10.0, 14, 46.00 EOT my %latestObs; #setup some metadata: my %units = ('datetime' => 'ISOtime', 'winddirection' => 'degreesDecimalFromNorth', 'windspeed' => 'mph', 'salinity' => 'psu', 'temperature' => 'degreesF'); open(DATAFILE, '<', \$datafilevar); # open the string while () { # loop for the last observation @latestObs{'datetime','winddirection','windspeed','salinity','temperature'} = split(/,\s*/); } close(DATAFILE); $writer->xmlDecl("UTF-8"); $writer->startTag([$ioosns,"ioosData"]); # $writer->startTag( "ioosData"); # $writer->startTag([platform, "class" => "simple"); $writer->startTag("platform", "id" => "http://www.vims.edu/~drf/realtime#bouy1"); $writer->emptyTag("typeOfPlatform", "id" => "http://www.vims.edu/~drf/realtime#bouy"); $writer->dataElement("urlPlatform", "http://www.vims.edu/~drf/realtime#bouy1"); $writer->startTag('hasContentMetadata'); $writer->startTag('metadata'); $writer->dataElement([$DublinNS,"title"],"Latest $parameter Data from AUV"); $writer->dataElement("description","How the data was collected"); $writer->startTag([$DublinNS,'creator']); $writer->startTag('organization',id=>'http://www.openioos.org/org#mbari'); $writer->dataElement("name","MBARI"); $writer->dataElement("urlHome","http://www.mbari.org"); $writer->dataElement("urlLogo","http://www.mbari.org/data/images/Logo_blue.gif"); $writer->dataElement("personFullName",''); $writer->dataElement("personEmail",''); $writer->endTag('organization'); $writer->endTag([$DublinNS,'creator']); $writer->endTag('metadata'); $writer->endTag('hasContentMetadata'); $writer->dataElement([$ioosns,'callingParameters'], 'some char data','parameter'=> $parameter, 'boundingBox'=>$boundingBox); $writer->startTag('observation'); $writer->dataElement('parameterScalar',,$latestObs{$parameter}, 'id'=>"http://www.openioos.org/parameter#$parameter", 'uom'=>"http://www.openioos.org/units#$units{$parameter}"); $writer->dataElement('latitude','32.00', 'uom'=>'http://www.openioos.org/units#degreesDecimal'); $writer->dataElement('longitude','-79.00', 'uom'=>'http://www.openioos.org/units#degreesDecimal'); $writer->dataElement('depth',1.0, 'uom'=>'http://www.openioos.org/units#meters'); $writer->dataElement('dateTime',$latestObs{'datetime'}, 'uom'=>'http://www.openioos.org/units#ISOtime'); $writer->dataElement('qualityFlag',3, 'values'=>'http://www.openioos.org/flagValues'); $writer->endTag('observation'); $writer->endTag("platform"); $writer->endTag([$ioosns,"ioosData"]); $writer->end(); return ($openioosXML); } 1; =begin WSDL _return $string XML containing ioosData.xml of the lastest parameter data in the boundingbox. From the oostech definition team emails. _IN parameter $string A parameter of interest _IN boundingBox $string XML descriptor of the bounding box to search. =end WSDL =cut sub getLatestV20051219 { my ($package, $parameter, $boundingBox) = @_; my $response= <<'EOT'; http://www.mbari.org?platform=AUV1 Latest Salinity Data from AUV Description of how the data was collected MBARI http://www.mbari.org http://www.mbari.org/data/images/Logo_blue.gif 35 32.00 -79.00 1.0 2001-01-01T00:00:00 EOT return ($response); } 1;