File: | blib/lib/OpenSRF/DomainObject/oilsResponse.pm |
Coverage: | 70.3% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package OpenSRF::DomainObject::oilsResponse; | ||||||
2 | 9 9 9 | 52 31 70 | use vars qw/@EXPORT_OK %EXPORT_TAGS/; | ||||
3 | 9 9 9 | 62 39 59 | use Exporter; | ||||
4 | 9 9 9 | 60 38 56 | use OpenSRF::Utils::JSON; | ||||
5 | 9 9 9 | 63 30 73 | use base qw/Exporter/; | ||||
6 | 9 9 9 | 76 45 78 | use OpenSRF::Utils::Logger qw/:level/; | ||||
7 | |||||||
8 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResponse', name => 'OpenSRF::DomainObject::oilsResponse', type => 'hash' ); | ||||||
9 | |||||||
10 | BEGIN { | ||||||
11 | 9 | 98 | @EXPORT_OK = qw/STATUS_CONTINUE STATUS_OK STATUS_ACCEPTED | ||||
12 | STATUS_BADREQUEST STATUS_UNAUTHORIZED STATUS_FORBIDDEN | ||||||
13 | STATUS_NOTFOUND STATUS_NOTALLOWED STATUS_TIMEOUT | ||||||
14 | STATUS_INTERNALSERVERERROR STATUS_NOTIMPLEMENTED | ||||||
15 | STATUS_VERSIONNOTSUPPORTED STATUS_REDIRECTED | ||||||
16 | STATUS_EXPFAILED STATUS_COMPLETE/; | ||||||
17 | |||||||
18 | 9 | 101 | %EXPORT_TAGS = ( | ||||
19 | status => [ qw/STATUS_CONTINUE STATUS_OK STATUS_ACCEPTED | ||||||
20 | STATUS_BADREQUEST STATUS_UNAUTHORIZED STATUS_FORBIDDEN | ||||||
21 | STATUS_NOTFOUND STATUS_NOTALLOWED STATUS_TIMEOUT | ||||||
22 | STATUS_INTERNALSERVERERROR STATUS_NOTIMPLEMENTED | ||||||
23 | STATUS_VERSIONNOTSUPPORTED STATUS_REDIRECTED | ||||||
24 | STATUS_EXPFAILED STATUS_COMPLETE/ ], | ||||||
25 | ); | ||||||
26 | |||||||
27 | } | ||||||
28 | |||||||
29 - 50 | =head1 NAME OpenSRF::DomainObject::oilsResponse =head1 SYNOPSIS use OpenSRF::DomainObject::oilsResponse qw/:status/; my $resp = OpenSRF::DomainObject::oilsResponse->new; $resp->status( 'a status message' ); $resp->statusCode( STATUS_CONTINUE ); $client->respond( $resp ); =head1 ABSTRACT OpenSRF::DomainObject::oilsResponse implements the base class for all Application layer messages send between the client and server. =cut | ||||||
51 | |||||||
52 | 9 | 0 | 41 | sub STATUS_CONTINUE { return 100 } | |||
53 | |||||||
54 | 27 | 0 | 119 | sub STATUS_OK { return 200 } | |||
55 | 0 | 0 | 0 | sub STATUS_ACCEPTED { return 202 } | |||
56 | 0 | 0 | 0 | sub STATUS_COMPLETE { return 205 } | |||
57 | |||||||
58 | 0 | 0 | 0 | sub STATUS_REDIRECTED { return 307 } | |||
59 | |||||||
60 | 0 | 0 | 0 | sub STATUS_BADREQUEST { return 400 } | |||
61 | 0 | 0 | 0 | sub STATUS_UNAUTHORIZED { return 401 } | |||
62 | 18 | 0 | 78 | sub STATUS_FORBIDDEN { return 403 } | |||
63 | 0 | 0 | 0 | sub STATUS_NOTFOUND { return 404 } | |||
64 | 0 | 0 | 0 | sub STATUS_NOTALLOWED { return 405 } | |||
65 | 0 | 0 | 0 | sub STATUS_TIMEOUT { return 408 } | |||
66 | 18 | 0 | 78 | sub STATUS_EXPFAILED { return 417 } | |||
67 | |||||||
68 | 27 | 0 | 116 | sub STATUS_INTERNALSERVERERROR { return 500 } | |||
69 | 0 | 0 | sub STATUS_NOTIMPLEMENTED { return 501 } | ||||
70 | 0 | 0 | sub STATUS_VERSIONNOTSUPPORTED { return 505 } | ||||
71 | |||||||
72 | my $log = 'OpenSRF::Utils::Logger'; | ||||||
73 | |||||||
74 | sub toString { | ||||||
75 | 0 | 0 | my $self = shift; | ||||
76 | 0 | return OpenSRF::Utils::JSON->perl2JSON($self); | |||||
77 | } | ||||||
78 | |||||||
79 | sub new { | ||||||
80 | 0 | 0 | my $class = shift; | ||||
81 | 0 | $class = ref($class) || $class; | |||||
82 | |||||||
83 | 0 | my $default_status = eval "\$${class}::status"; | |||||
84 | 0 | my $default_statusCode = eval "\$${class}::statusCode"; | |||||
85 | |||||||
86 | 0 | my %args = ( status => $default_status, | |||||
87 | statusCode => $default_statusCode, | ||||||
88 | @_ ); | ||||||
89 | |||||||
90 | 0 | return bless( \%args => $class ); | |||||
91 | } | ||||||
92 | |||||||
93 | sub status { | ||||||
94 | 0 | 0 | my $self = shift; | ||||
95 | 0 | my $val = shift; | |||||
96 | 0 | $self->{status} = $val if (defined $val); | |||||
97 | 0 | return $self->{status}; | |||||
98 | } | ||||||
99 | |||||||
100 | sub statusCode { | ||||||
101 | 0 | 0 | my $self = shift; | ||||
102 | 0 | my $val = shift; | |||||
103 | 0 | $self->{statusCode} = $val if (defined $val); | |||||
104 | 0 | return $self->{statusCode}; | |||||
105 | } | ||||||
106 | |||||||
107 | #------------------------------------------------------------------------------- | ||||||
108 | |||||||
109 | package OpenSRF::DomainObject::oilsStatus; | ||||||
110 | 9 9 9 | 86 32 89 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
111 | 9 9 9 | 63 34 68 | use base 'OpenSRF::DomainObject::oilsResponse'; | ||||
112 | 9 9 9 | 62 34 70 | use vars qw/$status $statusCode/; | ||||
113 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' ); | ||||||
114 | |||||||
115 - 135 | =head1 NAME OpenSRF::DomainObject::oilsException =head1 SYNOPSIS use OpenSRF::DomainObject::oilsResponse; ... # something happens. $client->status( OpenSRF::DomainObject::oilsStatus->new ); =head1 ABSTRACT The base class for Status messages sent between client and server. This is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and sets the default B<status> to C<Status> and B<statusCode> to C<STATUS_OK>. =cut | ||||||
136 | |||||||
137 | $status = 'Status'; | ||||||
138 | $statusCode = STATUS_OK; | ||||||
139 | |||||||
140 | #------------------------------------------------------------------------------- | ||||||
141 | |||||||
142 | package OpenSRF::DomainObject::oilsConnectStatus; | ||||||
143 | 9 9 9 | 69 39 54 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
144 | 9 9 9 | 65 36 53 | use base 'OpenSRF::DomainObject::oilsStatus'; | ||||
145 | 9 9 9 | 58 35 54 | use vars qw/$status $statusCode/; | ||||
146 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' ); | ||||||
147 | |||||||
148 - 172 | =head1 NAME OpenSRF::DomainObject::oilsConnectStatus =head1 SYNOPSIS use OpenSRF::DomainObject::oilsResponse; ... # something happens. $client->status( new OpenSRF::DomainObject::oilsConnectStatus ); =head1 ABSTRACT The class for Stati relating to the connection status of a session. This is implemented on top of the C<OpenSRF::DomainObject::oilsStatus> class, and sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>. =head1 SEE ALSO B<OpenSRF::DomainObject::oilsStatus> =cut | ||||||
173 | |||||||
174 | $status = 'Connection Successful'; | ||||||
175 | $statusCode = STATUS_OK; | ||||||
176 | |||||||
177 | #------------------------------------------------------------------------------- | ||||||
178 | |||||||
179 | package OpenSRF::DomainObject::oilsContinueStatus; | ||||||
180 | 9 9 9 | 70 32 57 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
181 | 9 9 9 | 62 34 51 | use base 'OpenSRF::DomainObject::oilsStatus'; | ||||
182 | 9 9 9 | 60 32 67 | use vars qw/$status $statusCode/; | ||||
183 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' ); | ||||||
184 | |||||||
185 - 208 | =head1 NAME OpenSRF::DomainObject::oilsContinueStatus =head1 SYNOPSIS use OpenSRF::DomainObject::oilsResponse; ... # something happens. $client->status( new OpenSRF::DomainObject::oilsContinueStatus ); =head1 ABSTRACT Implements the STATUS_CONTINUE message, informing the client that it should continue to wait for a response to its request. =head1 SEE ALSO B<OpenSRF::DomainObject::oilsStatus> =cut | ||||||
209 | |||||||
210 | $status = 'Please hold. Creating response...'; | ||||||
211 | $statusCode = STATUS_CONTINUE; | ||||||
212 | |||||||
213 | 1; | ||||||
214 | |||||||
215 | #------------------------------------------------------------------------------- | ||||||
216 | |||||||
217 | package OpenSRF::DomainObject::oilsResult; | ||||||
218 | 9 9 9 | 65 38 61 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
219 | 9 9 9 | 63 38 53 | use base 'OpenSRF::DomainObject::oilsResponse'; | ||||
220 | 9 9 9 | 69 36 57 | use vars qw/$status $statusCode/; | ||||
221 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' ); | ||||||
222 | |||||||
223 | |||||||
224 | $status = 'OK'; | ||||||
225 | $statusCode = STATUS_OK; | ||||||
226 | |||||||
227 - 260 | =head1 NAME OpenSRF::DomainObject::oilsResult =head1 SYNOPSIS use OpenSRF::DomainObject::oilsResponse; .... do stuff, create $object ... my $res = OpenSRF::DomainObject::oilsResult->new; $res->content($object) $session->respond( $res ); =head1 ABSTRACT This is the base class for encapuslating RESULT messages send from the server to a client. It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>. =head1 METHODS =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] ) =over 4 Sets or gets the content of the response. This should be exactly one object of (sub)type domainObject or domainObjectCollection. =back =cut | ||||||
261 | |||||||
262 | sub content { | ||||||
263 | 0 | my $self = shift; | |||||
264 | 0 | my $val = shift; | |||||
265 | |||||||
266 | 0 | $self->{content} = $val if (defined $val); | |||||
267 | 0 | return $self->{content}; | |||||
268 | } | ||||||
269 | |||||||
270 - 274 | =head1 SEE ALSO B<OpenSRF::DomainObject::oilsResponse> =cut | ||||||
275 | |||||||
276 | 1; | ||||||
277 | |||||||
278 | #------------------------------------------------------------------------------- | ||||||
279 | |||||||
280 | package OpenSRF::DomainObject::oilsException; | ||||||
281 | 9 9 9 | 77 40 54 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
282 | 9 9 9 | 66 38 68 | use OpenSRF::EX; | ||||
283 | 9 9 9 | 60 41 53 | use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/; | ||||
284 | 9 9 9 | 64 35 53 | use vars qw/$status $statusCode/; | ||||
285 | 9 9 9 | 60 33 68 | use Error; | ||||
286 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' ); | ||||||
287 | |||||||
288 | sub message { | ||||||
289 | 0 | my $self = shift; | |||||
290 | 0 | return '<' . $self->statusCode . '> ' . $self->status; | |||||
291 | } | ||||||
292 | |||||||
293 | sub new { | ||||||
294 | 0 | 0 | my $class = shift; | ||||
295 | 0 | return $class->OpenSRF::DomainObject::oilsResponse::new( @_ ); | |||||
296 | } | ||||||
297 | |||||||
298 | |||||||
299 - 319 | =head1 NAME OpenSRF::DomainObject::oilsException =head1 SYNOPSIS use OpenSRF::DomainObject::oilsResponse; ... # something breaks. $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) ); =head1 ABSTRACT The base class for Exception messages sent between client and server. This is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and sets the default B<status> to C<Exception occurred> and B<statusCode> to C<STATUS_BADREQUEST>. =cut | ||||||
320 | |||||||
321 | $status = 'Exception occurred'; | ||||||
322 | $statusCode = STATUS_INTERNALSERVERERROR; | ||||||
323 | |||||||
324 | #------------------------------------------------------------------------------- | ||||||
325 | |||||||
326 | package OpenSRF::DomainObject::oilsConnectException; | ||||||
327 | 9 9 9 | 76 41 61 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
328 | 9 9 9 | 62 35 49 | use OpenSRF::EX; | ||||
329 | 9 9 9 | 61 35 56 | use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/; | ||||
330 | 9 9 9 | 60 35 60 | use vars qw/$status $statusCode/; | ||||
331 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' ); | ||||||
332 | |||||||
333 - 357 | =head1 NAME OpenSRF::DomainObject::oilsConnectException =head1 SYNOPSIS use OpenSRF::DomainObject::oilsResponse; ... # something breaks while connecting. $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException ); =head1 ABSTRACT The class for Exceptions that occur durring the B<CONNECT> phase of a session. This is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>. =head1 SEE ALSO B<OpenSRF::DomainObject::oilsException> =cut | ||||||
358 | |||||||
359 | |||||||
360 | $status = 'Connect Request Failed'; | ||||||
361 | $statusCode = STATUS_FORBIDDEN; | ||||||
362 | |||||||
363 | #------------------------------------------------------------------------------- | ||||||
364 | |||||||
365 | package OpenSRF::DomainObject::oilsMethodException; | ||||||
366 | 9 9 9 | 69 34 65 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
367 | 9 9 9 | 60 36 50 | use base 'OpenSRF::DomainObject::oilsException'; | ||||
368 | 9 9 9 | 65 35 58 | use vars qw/$status $statusCode/; | ||||
369 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' ); | ||||||
370 | |||||||
371 - 396 | =head1 NAME OpenSRF::DomainObject::oilsMethodException =head1 SYNOPSIS use OpenSRF::DomainObject::oilsResponse; ... # something breaks while looking up or starting # a method call. $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException ); =head1 ABSTRACT The class for Exceptions that occur during the B<CONNECT> phase of a session. This is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>. =head1 SEE ALSO B<OpenSRF::DomainObject::oilsException> =cut | ||||||
397 | |||||||
398 | |||||||
399 | $status = 'A server error occurred during method execution'; | ||||||
400 | $statusCode = STATUS_INTERNALSERVERERROR; | ||||||
401 | |||||||
402 | # ------------------------------------------- | ||||||
403 | |||||||
404 | package OpenSRF::DomainObject::oilsServerError; | ||||||
405 | 9 9 9 | 76 39 63 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
406 | 9 9 9 | 62 35 47 | use base 'OpenSRF::DomainObject::oilsException'; | ||||
407 | 9 9 9 | 61 33 54 | use vars qw/$status $statusCode/; | ||||
408 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' ); | ||||||
409 | |||||||
410 | $status = 'Internal Server Error'; | ||||||
411 | $statusCode = STATUS_INTERNALSERVERERROR; | ||||||
412 | |||||||
413 | # ------------------------------------------- | ||||||
414 | |||||||
415 | package OpenSRF::DomainObject::oilsBrokenSession; | ||||||
416 | 9 9 9 | 65 35 52 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
417 | 9 9 9 | 64 32 70 | use OpenSRF::EX; | ||||
418 | 9 9 9 | 64 37 51 | use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/; | ||||
419 | 9 9 9 | 57 44 58 | use vars qw/$status $statusCode/; | ||||
420 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' ); | ||||||
421 | $status = "Request on Disconnected Session"; | ||||||
422 | $statusCode = STATUS_EXPFAILED; | ||||||
423 | |||||||
424 | #------------------------------------------------------------------------------- | ||||||
425 | |||||||
426 | package OpenSRF::DomainObject::oilsXMLParseError; | ||||||
427 | 9 9 9 | 1040 36 47 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
428 | 9 9 9 | 61 36 60 | use OpenSRF::EX; | ||||
429 | 9 9 9 | 70 33 64 | use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/; | ||||
430 | 9 9 9 | 68 38 59 | use vars qw/$status $statusCode/; | ||||
431 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' ); | ||||||
432 | $status = "XML Parse Error"; | ||||||
433 | $statusCode = STATUS_EXPFAILED; | ||||||
434 | |||||||
435 | #------------------------------------------------------------------------------- | ||||||
436 | |||||||
437 | package OpenSRF::DomainObject::oilsAuthException; | ||||||
438 | 9 9 9 | 72 32 50 | use OpenSRF::DomainObject::oilsResponse qw/:status/; | ||||
439 | 9 9 9 | 64 38 61 | use OpenSRF::EX; | ||||
440 | 9 9 9 | 61 43 49 | use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/; | ||||
441 | OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' ); | ||||||
442 | 9 9 9 | 59 34 49 | use vars qw/$status $statusCode/; | ||||
443 | $status = "Authentication Failure"; | ||||||
444 | $statusCode = STATUS_FORBIDDEN; | ||||||
445 | |||||||
446 | 1; |