blib/lib/auto/share/dist/MOBY/cgi/authority.pl untested

filter: Statementstmt 0.0% 0 / 91 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 141 CC 4 SCAR 18.3
CC
4
Cov
0%
dynamic_ops
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.2
1 #!/usr/bin/perl -w
2 #-----------------------------------------------------------------
3 # authority.pl
4 # Author: Edward Kawas <edward.kawas@gmail.com>,
5 # For copyright and disclaimer see below.
6 #
7 # $Id: authority.pl,v 1.3 2008/03/13 15:03:58 kawas Exp $
8 #-----------------------------------------------------------------
9  
10 use strict;
11 use warnings;
12  
13 use MOBY::lsid::authority::MobyMetadataResolver;
14  
15 use LS::ID;
16  
17 use LS::Service::Fault;
18 use LS::Service::Response;
19 use LS::Service::Authority;
20 use LS::Service::Namespace;
21 use LS::Service::DataService;
22 use LS::Service::AdvancedDataService;
23  
24 use LS::HTTP::Service;
25 use LS::RDF::SimpleDocument;
26  
27 #
28 # The SOAP service will travel over HTTP to this mod_perl based
29 # authority where all of the SOAP messages are decoded and
30 # passed up the SOAP stack until they reach this framework
31 #
32 # UNTESTED: The package defaults to HTTP:CGI which works in most
33 # cases.
34 #
35 #use LS::SOAP::Service transport=> 'HTTP::Apache';
36 use LS::SOAP::Service transport => 'HTTP::CGI';
37  
38 ##############
39  
40 # serve wsdl documents on request if they exist and are readable ...
41 # obtain them from the INC
42 if($ENV{'REQUEST_URI'} && ($ENV{'REQUEST_URI'} =~ /^\/authority\/(\w+)\.wsdl/)) {
43 my $wsdl_location = undef;
44 for my $dir (@INC) {
45 my $ls_module = "LS/Authority/WSDL/$1.wsdl";
46 $wsdl_location = "$dir/$ls_module" if -e "$dir/$ls_module";
47 }
48 if ($wsdl_location and -e $wsdl_location and -r $wsdl_location) {
49 my $parser = XML::LibXML->new();
50 my $doc = undef;
51 eval {
52 $doc = $parser->parse_file( "$wsdl_location" );
53 my $doc = $doc->toString();
54 print "Content-type: text/xml\n\n$doc" if $doc;
55 }
56 }
57 }
58  
59 my $location = 'http://';
60  
61 # TODO get this from the mobyconfig file
62 if ( $ENV{'HTTP_HOST'} ) {
63  
64 $location .= $ENV{'HTTP_HOST'};
65 }
66 else {
67  
68 # Set this to the default hostname for the authority
69 $location .= 'localhost:8080';
70 }
71  
72 # Create the authority service
73 my $authority = LS::Service::Authority->new(
74 name => 'BioMOBY',
75 authority => 'biomoby.org',
76 location => $location,
77 getAvailableServices => \&dynamic_ops
78 );
79  
80 #
81 # Add two ports to the authority:
82 #
83 # 1. A HTTP Location for the metadata
84 #
85 # 2. A SOAP location for the metadata
86 #
87 # 3. A HTTP Location for the data
88 #
89 # 4. A SOAP location for the data
90 #
91  
92 my $port;
93  
94 #$port = LS::Authority::WSDL::Simple::MetadataPort->newMetadata(
95 # portName=> 'BioMOBYSoapPort',
96 # endpoint=> "$location/authority/metadata",
97 # protocol=> $LS::Authority::WSDL::Constants::Protocols::SOAP,
98 # );
99 #$authority->addPort(serviceName=> 'BioMOBYSoapMeta', port=> $port);
100  
101 $port = LS::Authority::WSDL::Simple::MetadataPort->newMetadata(
102 portName=> 'BioMOBYHttpPort',
103 endpoint=> "$location/authority/metadata",
104 protocol=> $LS::Authority::WSDL::Constants::Protocols::HTTP,
105 );
106 $authority->addPort(serviceName=> 'BioMOBYHttpMeta', port=> $port);
107  
108 #data ports
109 $port = LS::Authority::WSDL::Simple::DataPort->newData(
110 portName=> 'BioMOBYHttpPort',
111 endpoint=> "$location/authority/data",
112 protocol=> $LS::Authority::WSDL::Constants::Protocols::HTTP,
113 );
114  
115 #$authority->addPort(serviceName=> 'BioMOBYSoapData', port=> $port);
116 #$port = LS::Authority::WSDL::Simple::DataPort->newData(
117 # portName=> 'BioMOBYSoapPort',
118 # endpoint=> "$location/authority/data",
119 # protocol=> $LS::Authority::WSDL::Constants::Protocols::SOAP,
120 # );
121 #$authority->addPort(serviceName=> 'BioMOBYSoapData', port=> $port);
122  
123  
124 # Add the metadata service with namespaces
125  
126 # we will handle 4 namespaces ... namespacetype, serviceinstance, servicetype and objectclass.
127 #TODO add the other predicates ...
128 my $metadata = LS::Service::DataService->new();
129 $metadata->addNamespace( MobyNamespaceType->new() );
130 $metadata->addNamespace( MobyServiceInstance->new() );
131 $metadata->addNamespace( MobyServiceType->new() );
132 $metadata->addNamespace( MobyObjectClass->new() );
133  
134 my $moby_authority_service = LS::SOAP::Service->new();
135  
136 $moby_authority_service->metadata_service($metadata);
137 $moby_authority_service->data_service($metadata);
138 $moby_authority_service->authority_service($authority);
139  
140 #
141 # Create a HTTP service and instruct the SOAP service to
142 # accept HTTP queries
143 #
144 my $moby_http_service = LS::HTTP::Service->new();
145 $moby_http_service->dispatch_authority_to($authority);
146 $moby_http_service->dispatch_metadata_to($metadata);
147  
148 $moby_authority_service->http_server($moby_http_service);
149  
150 $moby_authority_service->dispatch();
151  
152 #
153 # This adds a HTTP/CGI metadata port to the returned WSDL for each valid
154 # LSID
155 #
156 sub dynamic_ops {
157  
158 # if the namespace is serviceinstance, get the signatureURL and add it as a location
159 my ( $lsid, $wsdl ) = @_;
160 my %valid_namespaces = (
161 "namespacetype" => 1,
162 "serviceinstance" => 1,
163 "objectclass" => 1,
164 "servicetype" => 1
165 );
166 my $namespace = $lsid->namespace();
167 my $object = $lsid->object();
168  
169 return LS::Service::Fault->fault('Unknown LSID')
170 unless ( $valid_namespaces{$namespace} );
171  
172 # need to decide whether or not i should check exisitence here as well as in the MobyMetadataResolver.pm ...
173 my $port;
174  
175 do {
176 my $length = length($object);
177 # some error conditions
178 if ( $length > 0 and index( $object, ',' ) > 0 ) {
179 my $servicename =
180 substr( $object, index( $object, ',' ) + 1, $length );
181 my $authURI = substr( $object, 0, index( $object, ',' ) );
182  
183 my $moby = MOBY::Client::Central->new();
184 my ( $services, $RegObject ) = $moby->findService(
185 authURI => $authURI,
186 serviceName => $servicename
187 );
188 foreach my $SI (@$services) {
189 #should only be one of them ...
190 $port = LS::Authority::WSDL::Simple::MetadataPort->newMetadata(
191 portName => 'HTTPMetadata',
192 endpoint => $SI->signatureURL,
193 protocol => $LS::Authority::WSDL::Constants::Protocols::HTTP,
194 );
195 $wsdl->addPort(
196 serviceName => 'ServiceProviderMetadataHTTPPort',
197 port => $port
198 );
199 }
200 }
201 } if ( $namespace eq 'serviceinstance' );
202 return $wsdl;
203 }
204 __END__