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