[MOBY-guts] biomoby commit
Mark Wilkinson
mwilkinson at dev.open-bio.org
Fri Dec 8 16:16:41 UTC 2006
mwilkinson
Fri Dec 8 11:16:41 EST 2006
Update of /home/repository/moby/moby-live/Perl/MOBY/Client
In directory dev.open-bio.org:/tmp/cvs-serv1542/MOBY/Client
Modified Files:
Service.pm
Log Message:
MOBY can now execute HTTP POST services. register as category 'post'. prepare your service to accept a single named POST parameter called 'data'. the content of 'data' is a full block of MOBY XML, including the xml header and moby:MOBY etc elements
moby-live/Perl/MOBY/Client Service.pm,1.28,1.29
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/Service.pm,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- /home/repository/moby/moby-live/Perl/MOBY/Client/Service.pm 2006/12/08 15:46:44 1.28
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/Service.pm 2006/12/08 16:16:41 1.29
@@ -110,6 +110,10 @@
$self->{$attrname} = $self->_default_for( $attrname );
}
}
+ my $wsdl = $self->service;
+ if ($wsdl =~ /<http:binding verb=['"]POST['"]\/>/){
+ $self->category('post');
+ }
#my $dir = cwd;
# seems to be a bug in SOAP::Lite that the WSDL document
@@ -119,13 +123,9 @@
#print OUT $self->service;
#close OUT;
# ________________________________________
- my $wsdl = URI::Escape::uri_escape( $self->service ); # this seems to fix the bug
-# my $wsdl = $self->service;
+ $wsdl = URI::Escape::uri_escape( $self->service ); # this seems to fix the bug
return undef unless $wsdl;
- if ($wsdl =~ /<http:binding verb=['"]POST['"]\/>/){
- $self->category('post');
- }
my $soap = SOAP::Lite->service( "data:,$wsdl" );
if ( $self->uri ) { $soap->uri( $self->uri ) }
$self->serviceName( &_getServiceName( $soap ) );
@@ -290,18 +290,52 @@
&_LOG( %args, $METHOD );
my $response;
- if ($self->category eq 'post'){
- my $d = SOAP::Data->name('data' => $data);
- eval { ( $response ) = $self->_soapService->$METHOD($d) };
- if ($@) { die "Service execution failed: $@"}
- else {return $response;} # the service execution failed then pass back ""
- } elsif ($self->category eq 'moby'){
+ if ($self->category eq 'moby'){
eval { ( $response ) = $self->_soapService->$METHOD( $data ) };
if ($@) { die "Service execution failed: $@"}
else {return $response;} # the service execution failed then pass back ""
+ } elsif ($self->category eq 'post'){
+ my $response = $self->_executePOSTService(data => $data, method => $METHOD);
+ # currently SOAP::Lite does not execute POST WSDL, so we need to
+ # use LWP or something like that in the executePOSTService method
+ #eval { ( $response ) = $self->_soapService->$METHOD( $data ) };
+ unless ($response){ die "Service execution failed: $@"}
+ else {return $response;} # the service execution failed then pass back ""
}
}
+sub _executePOSTService {
+ my ($self, %args) = @_;
+ my $serviceName = $args{method};
+ my $data = $args{data};
+ my $wsdl = $self->service;
+ $wsdl =~ /address\slocation=['"]([^'"]+)/s;
+ my $location = $1;
+ $wsdl =~/operation\slocation=['"]([^'"]+)/s;
+ my $path = $1;
+ use LWP::UserAgent;
+ my $ua = LWP::UserAgent->new;
+
+ # Create a request
+ my $req = HTTP::Request->new(POST => "$location/$path");
+ $req->content_type('application/x-www-form-urlencoded');
+ $req->content('data=$data');
+
+ # Pass request to the user agent and get a response back
+ my $res = $ua->request($req);
+ my $result;
+ # Check the outcome of the response
+ if ($res->is_success) {
+ $result = $res->content;
+ }
+ else {
+ $result = "";
+ }
+ return $result;
+}
+
+
+
=head2 serviceName
Usage : $name = $Service->serviceName()
More information about the MOBY-guts
mailing list