LS/Client/SOAP.pm untested

filter: Statementstmt 0.0% 0 / 179 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 278 CC 27 SCAR 33.9
CC
27
Cov
0%
getContent
90.0
getMetadata
30.0
new
20.0
CRAP 29.8
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::Client::SOAP;
10  
11 use strict;
12 use warnings;
13  
14 use vars qw( $_METHOD_PREFIX );
15  
16 use SOAP::Lite ;
17  
18 use LS::ID;
19 use LS::Client;
20 use LS::Service::Response;
21 use LS::SOAP::Serializer;
22  
23 use base 'LS::Client';
24  
25  
26 #
27 # $_METHOD_PREFIX -
28 #
29 $_METHOD_PREFIX = 'op';
30  
31  
32 #
33 # new( %options ) -
34 #
35 sub new {
36  
37 my ($self, %options) = @_;
38  
39 unless($options{'url'}) {
40  
41 $self->recordError('Missing url parameter in sub new');
42 $self->addStackTrace();
43 die($self->errorDetails());
44 }
45  
46 unless(ref $self) {
47  
48 $self = bless {
49 %options,
50 _err=> undef,
51 }, $self;
52 }
53  
54 my $soap = SOAP::Lite->serializer(LS::SOAP::Serializer->method_prefix($_METHOD_PREFIX))
55 ->on_fault(sub {})
56 ->on_action(sub { return ''; })
57 ->uri('http://www.ibm.com/LSID/Standard/WSDL/SchemaTypes')
58 ->proxy( $options{'url'} );
59  
60 unless($soap) {
61  
62 $self->recordError( "Unable to initialize SOAP proxy object for url: $options{url}" );
63 $self->addStackTrace();
64 die($self->errorDetails());
65 }
66  
67 $self->{'_soap'} = $soap;
68  
69 return $self;
70 }
71  
72  
73 #
74 # getContent( %options ) -
75 #
76 sub getContent {
77  
78 my ($self, %options) = @_;
79  
80 unless($options{'method'}) {
81  
82 $self->recordError( 'Missing method parameter in sub getContent' );
83 $self->addStackTrace();
84 die($self->errorDetails());
85 }
86
87 my $method = $options{'method'};
88 delete $options{'method'};
89  
90 my $service = $self->{'_soap'};
91 my @params = @{ $options{'params'} } if($options{'params'});
92  
93 if($self->credentials()) {
94  
95 my $username = $self->credentials->username();
96 my $password = $self->credentials->password();
97  
98 eval("sub SOAP::Transport::HTTP::Client::get_basic_credentials { return \"$username\"=> \"$password\"; }");
99 }
100  
101 my $response = $service->call("$method"=> @params);
102  
103 unless($response) {
104  
105 $self->recordError( "Method: $method - returned an invalid response in sub getContent" );
106 $self->addStackTrace();
107 die($self->errorDetails());
108 }
109  
110 if ($response->fault()) {
111  
112 my $errorCode = $response->fault->{'detail'}->{'errorcode'};
113 my $faultString = $response->faultstring();
114 my $description = $response->fault->{'detail'}->{'description'};
115  
116 my $faultMessage;
117  
118 $faultMessage = $faultString
119 if($faultString);
120
121 $faultMessage .= ": Error Code $errorCode."
122 if($errorCode);
123
124 $faultMessage .= "\nDescription: $description"
125 if($description);
126  
127 $self->recordError( $faultMessage );
128 $self->addStackTrace();
129 die($self->errorDetails());
130 }
131  
132 return $response;
133 }
134  
135  
136 #
137 # getAvailableservices( %options ) -
138 #
139 sub getAvailableServices {
140  
141 my ($self, %options) = @_;
142  
143 unless($options{'lsid'}) {
144  
145 $self->recordError( 'Missing lsid parameter in sub getMetadata' );
146 $self->addStackTrace();
147 die($self->errorDetails());
148 }
149  
150 my $lsid = $options{'lsid'};
151
152 my $SOAPlsid = SOAP::Data->prefix('')
153 ->name(lsid=> $lsid->as_string());
154  
155 my $response = $self->getContent(method=> 'getAvailableServices',
156 params=> [ $SOAPlsid ] );
157  
158 return undef
159 unless($response);
160  
161 $self->recordError( undef );
162  
163 #
164 # OMG Spec: SOAP with MIME Attachments
165 #
166 if(UNIVERSAL::isa($response->{'_parts'}, 'ARRAY')) {
167
168 my $entity = ${ $response->{'_parts'}->[1] };
169
170 my $body = $entity->bodyhandle();
171
172 return LS::Service::Response->new(response=> $body->as_string());
173 }
174
175 $self->recordError('Response for getAvailableServices did not return MIME attachments');
176 $self->addStackTrace();
177
178 die($self->errorDetails());
179 }
180  
181  
182 #
183 # getMetadata( %options ) -
184 #
185 sub getMetadata {
186  
187 my ($self, %options) = @_;
188  
189 unless($options{'lsid'}) {
190  
191 $self->recordError( 'Missing lsid parameter in sub getMetadata' );
192 $self->addStackTrace();
193  
194 die($self->errorDetails());
195 }
196  
197 my $lsid = SOAP::Data->prefix('')
198 ->name(lsid=> $options{'lsid'}->as_string());
199  
200  
201 my $acceptedFormats = $options{'acceptedFormats'} ? $options{'acceptedFormats'} : 'application/rdf+xml';
202 my $formats = SOAP::Data->prefix('')
203 ->name(acceptedFormats=> $acceptedFormats);
204  
205 my $response = $self->getContent(method=> 'getMetadata',
206 params=> [ $lsid, $formats ] );
207  
208 return undef unless($response);
209  
210 $self->recordError( undef );
211  
212 #
213 # OMG Spec: SOAP with MIME Attachments
214 #
215 if(UNIVERSAL::isa($response->{'_parts'}, 'ARRAY')) {
216
217 my $entity = ${ $response->{'_parts'}->[1] };
218
219 my $body = $entity->bodyhandle();
220
221 return LS::Service::Response->new(response=> $body->as_string());
222 }
223
224 $self->recordError('Response for getMetadata did not return MIME attachments');
225 $self->addStackTrace();
226
227 die($self->errorDetails());
228 }
229  
230  
231 #
232 # getMetadataSubset( %options ) -
233 #
234 sub getMetadataSubset {
235  
236 return LS::Service::Response->new(response=> '');
237 }
238  
239  
240 #
241 # getData( %options ) -
242 #
243 sub getData {
244  
245 my ($self, %options) = @_;
246  
247 unless($options{'lsid'}) {
248  
249 $self->recordError( 'Missing lsid parameter in sub getData' );
250 $self->addStackTrace();
251 die($self->errorDetails());
252 }
253  
254 my $lsid = $options{'lsid'};
255  
256 my $SOAPlsid = SOAP::Data->prefix('')
257 ->name(lsid=> $lsid->as_string());
258  
259 my $response = $self->getContent(method=> 'getData',
260 params=> [ $SOAPlsid ] );
261  
262 return undef
263 unless($response);
264  
265 $self->recordError( undef );
266  
267 #
268 # OMG Spec: SOAP with MIME Attachments
269 #
270 if(UNIVERSAL::isa($response->{'_parts'}, 'ARRAY')) {
271
272 my $entity = ${ $response->{'_parts'}->[1] };
273
274 my $body = $entity->bodyhandle();
275
276 return LS::Service::Response->new(response=> $body->as_string());
277 }
278
279 $self->recordError('Response for getData did not return MIME attachments');
280 $self->addStackTrace();
281
282 die($self->errorDetails());
283 }
284  
285  
286 #
287 # getDataByRange( %options ) -
288 #
289 sub getDataByRange {
290  
291 my ($self, %options) = @_;
292  
293 unless($options{'lsid'} &&
294 $options{'start'} &&
295 $options{'length'} ) {
296  
297 $self->recordError( 'Missing parameters in sub getDataByRange' );
298 $self->addStackTrace();
299  
300 die($self->errorDetails());
301 }
302  
303 my $lsid = $options{'lsid'};
304 my $start = $options{'start'};
305 my $length = $options{'length'};
306  
307 my $SOAPlsid = SOAP::Data->prefix('')
308 ->name(lsid=> $lsid->as_string());
309  
310 my $SOAPstart = SOAP::Data
311 ->prefix('')
312 ->name(start=> $start );
313  
314 my $SOAPlength = SOAP::Data
315 ->prefix('')
316 ->name(length=> $length );
317  
318 my $response = $self->getContent(method=> 'getData',
319 params=> [ $SOAPlsid, $SOAPstart, $SOAPlength ] );
320  
321 return undef unless($response);
322  
323 $self->recordError( undef );
324  
325 #
326 # OMG Spec: SOAP with MIME Attachments
327 #
328 if(UNIVERSAL::isa($response->{'_parts'}, 'ARRAY')) {
329
330 my $entity = ${ $response->{'_parts'}->[1] };
331
332 my $body = $entity->bodyhandle();
333
334 return LS::Service::Response->new(response=> $body->as_string());
335 }
336
337 $self->recordError('Response for getDataByRange did not return MIME attachments');
338 $self->addStackTrace();
339
340 die($self->errorDetails());
341 }
342  
343  
344  
345 #
346 # FAN Stubs
347 #
348  
349  
350 #
351 # _fan_call( %options ) -
352 #
353 sub _fan_call {
354  
355 my ($self, %options) = @_;
356  
357 unless($options{'lsid'} &&
358 $options{'authorityName'} &&
359 $options{'method'} ) {
360  
361 $self->recordError( 'Missing parameters in sub notifyForeignAuthority' );
362 $self->addStackTrace();
363  
364 die($self->errorDetails());
365 }
366  
367 my $lsid = $options{'lsid'};
368 my $authorityName = $options{'authorityName'};
369 my $method = $options{'method'};
370  
371 my $SOAPlsid = SOAP::Data->prefix('')
372 ->name(lsid=> $lsid->as_string());
373  
374 my $SOAPan = SOAP::Data
375 ->prefix('')
376 ->name(authorityName=> $authorityName);
377  
378 my $response = $self->getContent(method=> $method,
379 params=> [ $SOAPlsid, $SOAPan ] );
380  
381 return undef unless($response);
382  
383 $self->recordError( undef );
384  
385 return LS::Service::Response->new(response=> $response);
386 }
387  
388  
389 #
390 #
391 # notifyForeignAuthority( $lsid, $authorityName )
392 #
393 sub notifyForeignAuthority {
394  
395 my $self = shift;
396  
397 return $self->_fan_call(method=> 'notifyForeignAuthority', @_);
398 }
399  
400  
401 #
402 #
403 # revokeNotifcationForeignAuthority( $lsid, $authorityName )
404 #
405 sub revokeNotificationForeignAuthority {
406  
407 my $self = shift;
408  
409 return $self->_fan_call(method=> 'revokeNotificationForeignAuthority', @_);
410 }
411  
412 1;
413  
414 __END__