2 |
## $Id$ |
## $Id$ |
3 |
## ------------------------------------------------------------------------ |
## ------------------------------------------------------------------------ |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.7 2004/07/06 00:45:18 joko |
6 |
|
## disabled RPC::XML::SessionServer (TODO: reactivate!) |
7 |
|
## |
8 |
|
## Revision 1.6 2003/07/02 11:00:40 jonen |
9 |
|
## fixed: die now if http-port is used by other app |
10 |
|
## |
11 |
|
## Revision 1.5 2003/07/01 18:11:15 joko |
12 |
|
## fixed: renamed package name according to new filenames |
13 |
|
## |
14 |
|
## Revision 1.4 2003/06/06 03:24:14 joko |
15 |
|
## + SymbolAliasing |
16 |
|
## |
17 |
|
## Revision 1.3 2003/04/04 17:28:59 joko |
18 |
|
## minor update: commented hardcoded stuff |
19 |
|
## |
20 |
## Revision 1.2 2003/04/04 17:28:15 joko |
## Revision 1.2 2003/04/04 17:28:15 joko |
21 |
## starting the *session* server/service from here |
## starting the *session* server/service from here |
22 |
## |
## |
26 |
## ------------------------------------------------------------------------ |
## ------------------------------------------------------------------------ |
27 |
|
|
28 |
|
|
29 |
package OEF::Component::WebService; |
package OEF::Component::WebService::RpcXml; |
30 |
|
|
31 |
use strict; |
use strict; |
32 |
use warnings; |
use warnings; |
36 |
|
|
37 |
use Data::Dumper; |
use Data::Dumper; |
38 |
use RPC::XML; |
use RPC::XML; |
39 |
|
use RPC::XML::Server; |
40 |
use RPC::XML::SessionServer; |
use RPC::XML::SessionServer; |
41 |
use RPC::XML::Procedure; |
use RPC::XML::Procedure; |
42 |
|
use Data::Mungle::Code::Symbol qw( alias_simple ); |
43 |
|
|
44 |
# this is a global counter for giving unnamed webservices a unique id |
# this is a global counter for giving unnamed webservices a unique id |
45 |
our $instance_counter; |
our $instance_counter; |
59 |
$instance_counter++; |
$instance_counter++; |
60 |
|
|
61 |
# here goes the server instance |
# here goes the server instance |
62 |
$self->{_daemon} = RPC::XML::SessionServer->new( |
#$self->{_daemon} = RPC::XML::SessionServer->new( |
63 |
|
$self->{_daemon} = RPC::XML::Server->new( |
64 |
port => $self->{ws_port}, |
port => $self->{ws_port}, |
65 |
path => $self->{ws_path} || 'WebService' . $instance_counter, |
path => $self->{ws_path} || 'WebService' . $instance_counter, |
66 |
auto_updates => 1, |
auto_updates => 1, |
67 |
|
|
68 |
|
# FIXME: this is hardcoded! |
69 |
authentication => { |
authentication => { |
70 |
type => 'plain', |
type => 'plain', |
71 |
user => 'hello', |
user => 'hello', |
73 |
} |
} |
74 |
); |
); |
75 |
|
|
76 |
|
#print Dumper($self->{_daemon}) . "\n"; |
77 |
|
if(!ref($self->{_daemon})) { die($self->{_daemon} . ", maybe same daemon or other daemon on same port is already running??" . "\n"); } |
78 |
|
|
79 |
# API |
# API |
80 |
# load api module |
|
81 |
|
# 1. load api module |
82 |
my $api = DesignPattern::Object->fromPackage($self->{api_module}) or die("Could not load Api-Module '$self->{api_module}'."); |
my $api = DesignPattern::Object->fromPackage($self->{api_module}) or die("Could not load Api-Module '$self->{api_module}'."); |
83 |
# build complete bunch of api declaration metadata handling recursive plugin declaration and stuff ... |
# build complete bunch of api declaration metadata handling recursive plugin declaration and stuff ... |
84 |
#$api->build([qw( OEF::YAA::API::Jobs )]); |
#$api->build([qw( OEF::YAA::API::Jobs )]); |
85 |
$api->build($self->{api_submodules}); |
$api->build($self->{api_submodules}); |
86 |
# get it! |
|
87 |
|
# 2. query it for to-be-published methods ... |
88 |
my $procs = $api->getApiMetadata() or die("Could not load Api-Declarations from '$self->{api_module}'."); |
my $procs = $api->getApiMetadata() or die("Could not load Api-Declarations from '$self->{api_module}'."); |
89 |
# ... and propagate metadata for each method to daemon instance which is not yet running |
# ... and propagate metadata for each method to daemon instance which is not yet running |
90 |
foreach my $proc (@{$procs}) { |
foreach my $proc (@{$procs}) { |
91 |
$self->{_daemon}->add_method($proc); |
$self->{_daemon}->add_method($proc); |
92 |
} |
} |
93 |
|
|
94 |
|
# 3. SymbolAliasing: query it for to-be-established symbols ... |
95 |
|
my $symbols; |
96 |
|
$symbols = $api->getSymbolMetadata() if $api->can("getSymbolMetadata"); |
97 |
|
# ... and vivify them each pointing to a reference. |
98 |
|
foreach my $symbol (@{$symbols}) { |
99 |
|
$symbol->{slot} = $self->{_daemon}; |
100 |
|
alias_simple($symbol); |
101 |
|
} |
102 |
|
|
103 |
# run service / activate instance |
# run service / activate instance |
104 |
# Never returns... |
# Never returns... |