LS/Authority/WSDL/Services.pm untested

filter: Statementstmt 0.0% 0 / 90 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 135 CC 13 SCAR 33.7
CC
13
Cov
0%
add_port
72.0
buildServiceLocations
20.0
new
6.0
CRAP 29.0
1 # ====================================================================
2 # Copyright (c) 2002,2003 IBM Corporation
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Common Public License v1.0
5 # which accompanies this distribution, and is available at
6 # http://www.opensource.org/licenses/cpl.php
7 #
8 # =====================================================================
9 package LS::Authority::WSDL::Services;
10  
11 use strict;
12 use warnings;
13  
14 use vars qw( $METHODS );
15  
16 use LS;
17  
18 use LS::Authority::WSDL::Location;
19  
20 use base 'LS::Authority::WSDL';
21  
22  
23 sub BEGIN {
24
25 $METHODS = [
26 'defaultServiceName',
27 'methodLocations',
28 ];
29
30 LS::makeAccessorMethods($METHODS, __PACKAGE__);
31 }
32  
33  
34 sub new {
35 my $self = shift;
36 my %params = @_;
37  
38 $self = $self->SUPER::new(@_);
39  
40 $self->methodLocations( {} );
41
42 if(exists($params{'name'})) {
43 $self->defaultServiceName($params{'name'});
44 $self->add_service(LS::Authority::WSDL::ServiceDefinition->new(name=> $params{'name'}));
45 }
46  
47 # Default imports
48 $self->add_xml_import(location=> 'LSIDAuthorityServiceHTTPBindings.wsdl',
49 namespace=> 'http://www.omg.org/LSID/2003/AuthorityServiceHTTPBindings');
50  
51 $self->add_xml_import(location=> 'LSIDAuthorityServiceSOAPBindings.wsdl',
52 namespace=> 'http://www.omg.org/LSID/2003/AuthorityServiceSOAPBindings');
53  
54  
55 # Default namespaces
56 $self->add_namespace(prefix=>'ahb',
57 uri=>'http://www.omg.org/LSID/2003/AuthorityServiceHTTPBindings');
58  
59 $self->add_namespace(prefix=>'asb',
60 uri=>'http://www.omg.org/LSID/2003/AuthorityServiceSOAPBindings');
61  
62 return $self;
63 }
64  
65  
66  
67 sub add_port {
68 my ($self, %params) = @_;
69
70 my $location = $params{location};
71 my $user = $params{user};
72 my $password = $params{password};
73  
74 my $protocol = $params{protocol};
75 my $name = $params{name};
76 my $type = $params{type};
77 my $method = $params{method};
78
79 my $expires = $params{expires};
80
81 if ($protocol eq ${LS::Authority::WSDL::Constants::Protocols::HTTP}) {
82 $method = $method ? uc($method) : 'GET';
83 }
84 else {
85 $method = undef;
86 }
87  
88 my $binding;
89  
90 if ($protocol eq ${LS::Authority::WSDL::Constants::Protocols::HTTP}) {
91  
92 # $location .= '/'
93 # unless($location =~ m|/$|);
94  
95 $binding = 'ahb:LSIDAuthorityHTTPBinding';
96 }
97 elsif ($protocol eq ${LS::Authority::WSDL::Constants::Protocols::SOAP}) {
98  
99 $binding = 'asb:LSIDAuthoritySOAPBinding';
100 }
101
102 my $port_impl = LS::Authority::WSDL::Implementation->new(
103 protocol => $protocol,
104 name => 'address',
105 attr => {
106 location => ($location =~ m|^http://|i ? '' : 'http://') . $location,
107 }
108 );
109
110 unless(UNIVERSAL::isa($port_impl, 'LS::Authority::WSDL::Implementation')) {
111
112 return undef;
113 }
114  
115 my $port = LS::Authority::WSDL::Port->new(
116 name=> ($name) ? $name : $type . '_name',
117 binding=> $binding,
118 implementation=> $port_impl
119 );
120  
121 $self->services()->{ $self->defaultServiceName() }->add_port($port);
122 }
123  
124  
125 sub from_xml {
126 my $self = shift->new();
127  
128 $self = $self->SUPER::from_xml(@_);
129  
130 # Get the first service's name and use that as a default
131 $self->defaultServiceName((values(%{ $self->services() }))[0]->name())
132 if(scalar(values(%{ $self->services() })) > 0);
133  
134 $self->buildServiceLocations();
135
136 return $self;
137 }
138  
139  
140 sub buildServiceLocations {
141  
142 my $self = shift;
143  
144 foreach my $service (values(%{ $self->services() })) {
145  
146 foreach my $port (@{ $service->ports() }) {
147  
148 my $protocol = $port->implementation()->protocol();
149 my $binding = $port->binding();
150 my $type = $port->name();
151  
152  
153 my $locations = $self->methodLocations()->{ $type };
154  
155 $locations = $self->methodLocations()->{ $type } = []
156 unless($locations);
157
158 my $method = "";
159 my $url = $port->implementation->get_attr('location');
160  
161 if ($protocol eq ${LS::Authority::WSDL::Constants::Protocols::HTTP}) {
162  
163 $method = ( uc($port->implementation->get_attr('verb')) || 'GET' );
164 }
165 elsif ($protocol eq ${LS::Authority::WSDL::Constants::Protocols::SOAP}) {
166 # Nothing to do
167 }
168 else {
169  
170 # FIXME: Maybe use LS::Service::Response
171 print STDERR "Unknown protocol: $protocol\n";
172 return undef;
173 }
174  
175 push(
176 @{ $locations },
177 LS::Authority::WSDL::Location->new(
178 name=> $type,
179 protocol=> $protocol,
180 url=> $url,
181 binding=> $binding,
182 method=> $method,
183 parentName=> $service->name(),
184 )
185 );
186 }
187 }
188  
189 }
190  
191  
192 sub to_xml {
193  
194 my $self = shift;
195  
196 $self->targetNamespace('http://www.omg.org/LSID/2003/Standard/WSDL');
197  
198 return $self->SUPER::to_xml(@_);
199 }
200  
201 1;
202  
203  
204 __END__