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