#!/usr/bin/perl use SOAP::Lite; # SOAP API use HTTP::Cookies; use XML::DOM; $uri = 'urn:PDBjSOAPServiceX'; $url = 'http://pdbjs8.protein.osaka-u.ac.jp/soap/servlet/messagerouter'; $dbURL = "http://pdbjs8.protein.osaka-u.ac.jp/tamino/pdbMLplus"; $colName = "pdbMLplus_Collection"; if ($ARGV[0] eq "" || lc($ARGV[0]) eq "-h" || lc($ARGV[0]) eq "-help") { printf("sample3.pl [xquery_file] (result num) (timeout)\n"); printf(" call method : \n"); printf(" void connect(string dbURL)\n"); printf(" void setaccesslocation(string collectionName)\n"); printf(" org.w3c.dom.Element txquery(string xquery, string result_num)\n"); printf(" void disconnect()\n"); printf(" uri : \n"); printf(" $uri\n"); printf(" url : \n"); printf(" $url\n"); printf(" default result num : 5 \n"); printf(" default timeout : 10 minutes\n"); exit; } #$xquery = $ARGV[0]; my $query_file = $ARGV[0]; my $xquery = ""; my $ret = open(IN, $query_file); if ($ret != undef) { while () { if (length($_) > 0) { $xquery .= $_; } } close(IN); } else { print STDERR "($query_file) open failed!\n"; exit; } $num = 5; if ($ARGV[1] ne "") { $num = $ARGV[1]; } $tm = 10 * 60; if ($ARGV[2] ne "") { $tm = $ARGV[2]; } $method1 = 'connect'; $method2 = 'setaccesslocation'; $method3 = 'txquery'; $method5 = 'disconnect'; # encodingStyle $enc1 = 'http://schemas.xmlsoap.org/soap/encoding/'; $enc2 = 'http://xml.apache.org/xml-soap/literalxml'; # set uri,endpoint and load module my $service = SOAP::Lite -> uri($uri) -> proxy($url, cookie_jar => HTTP::Cookies->new(ignore_discard => 1), timeout => $tm); $service -> $method1($dbURL); ## connect $service -> $method2($colName); ## setaccesslocation $res = $service ->outputxml(true); my $parser = new XML::DOM::Parser(ErrorContext=>3); # call method(txquery) and String->Element $doc1 = $parser->parse($service->call(SOAP::Data->name($method3) ->attr({xmlns => $uri, 'SOAP-ENV:encodingStyle' => $enc2 }) =>SOAP::Data ->type(string => $xquery) =>SOAP::Data ->type(string => $num) ->encodingStyle($enc1))); @top_node_list1 = &getElementList($doc1); # print result foreach my $node (@top_node_list1) { print $node->toString(),"\n"; } $service -> $method5(); ## disconnect sub getElementList () { my ($doc) = @_; my @ret_list = (); if ($doc ne undef) { my $node = $doc->getElementsByTagName("xq:result")->item(0); if ($node ne undef) { my @childs = $node->getChildNodes(); foreach $child (@childs) { push @ret_list, $child; } } else { $node = $doc->getElementsByTagName("error")->item(0); if ($node ne undef) { my $child = $node->getFirstChild(); if ($child ne undef) { push @ret_list, $child; } } } } return @ret_list; }