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