#!/usr/bin/perl -w
if
(
$ENV
{
'REQUEST_URI'
} && (
$ENV
{
'REQUEST_URI'
} =~ /^\/authority\/(\w+)\.wsdl/)) {
my
$wsdl_location
=
undef
;
for
my
$dir
(
@INC
) {
my
$ls_module
=
"LS/Authority/WSDL/$1.wsdl"
;
$wsdl_location
=
"$dir/$ls_module"
if
-e
"$dir/$ls_module"
;
}
if
(
$wsdl_location
and -e
$wsdl_location
and -r
$wsdl_location
) {
my
$parser
= XML::LibXML->new();
my
$doc
=
undef
;
eval
{
$doc
=
$parser
->parse_file(
"$wsdl_location"
);
my
$doc
=
$doc
->toString();
print
"Content-type: text/xml\n\n$doc"
if
$doc
;
}
}
}
if
(
$ENV
{
'HTTP_HOST'
} ) {
$location
.=
$ENV
{
'HTTP_HOST'
};
}
else
{
$location
.=
'localhost:8080'
;
}
my
$authority
= LS::Service::Authority->new(
name
=>
'BioMOBY'
,
authority
=>
'biomoby.org'
,
location
=>
$location
,
getAvailableServices
=> \
&dynamic_ops
);
my
$port
;
$port
= LS::Authority::WSDL::Simple::MetadataPort->newMetadata(
portName
=>
'BioMOBYHttpPort'
,
endpoint
=>
"$location/authority/metadata"
,
protocol
=>
$LS::Authority::WSDL::Constants::Protocols::HTTP
,
);
$authority
->addPort(
serviceName
=>
'BioMOBYHttpMeta'
,
port
=>
$port
);
$port
= LS::Authority::WSDL::Simple::DataPort->newData(
portName
=>
'BioMOBYHttpPort'
,
endpoint
=>
"$location/authority/data"
,
protocol
=>
$LS::Authority::WSDL::Constants::Protocols::HTTP
,
);
my
$metadata
= LS::Service::DataService->new();
$metadata
->addNamespace( MobyNamespaceType->new() );
$metadata
->addNamespace( MobyServiceInstance->new() );
$metadata
->addNamespace( MobyServiceType->new() );
$metadata
->addNamespace( MobyObjectClass->new() );
my
$moby_authority_service
= LS::SOAP::Service->new();
$moby_authority_service
->metadata_service(
$metadata
);
$moby_authority_service
->data_service(
$metadata
);
$moby_authority_service
->authority_service(
$authority
);
my
$moby_http_service
= LS::HTTP::Service->new();
$moby_http_service
->dispatch_authority_to(
$authority
);
$moby_http_service
->dispatch_metadata_to(
$metadata
);
$moby_authority_service
->http_server(
$moby_http_service
);
$moby_authority_service
->dispatch();
sub
dynamic_ops {
my
(
$lsid
,
$wsdl
) =
@_
;
my
%valid_namespaces
= (
"namespacetype"
=> 1,
"serviceinstance"
=> 1,
"objectclass"
=> 1,
"servicetype"
=> 1
);
my
$namespace
=
$lsid
->namespace();
my
$object
=
$lsid
->object();
return
LS::Service::Fault->fault(
'Unknown LSID'
)
unless
(
$valid_namespaces
{
$namespace
} );
my
$port
;
do
{
my
$length
=
length
(
$object
);
if
(
$length
> 0 and
index
(
$object
,
','
) > 0 ) {
my
$servicename
=
substr
(
$object
,
index
(
$object
,
','
) + 1,
$length
);
my
$authURI
=
substr
(
$object
, 0,
index
(
$object
,
','
) );
my
$moby
= MOBY::Client::Central->new();
my
(
$services
,
$RegObject
) =
$moby
->findService(
authURI
=>
$authURI
,
serviceName
=>
$servicename
);
foreach
my
$SI
(
@$services
) {
$port
= LS::Authority::WSDL::Simple::MetadataPort->newMetadata(
portName
=>
'HTTPMetadata'
,
endpoint
=>
$SI
->signatureURL,
protocol
=>
$LS::Authority::WSDL::Constants::Protocols::HTTP
,
);
$wsdl
->addPort(
serviceName
=>
'ServiceProviderMetadataHTTPPort'
,
port
=>
$port
);
}
}
}
if
(
$namespace
eq
'serviceinstance'
);
return
$wsdl
;
}