]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/perlmods/OpenSRF/DomainObject/oilsResponse.pm
minor bug fixes and removal of some extra stringifications
[Evergreen.git] / OpenSRF / src / perlmods / OpenSRF / DomainObject / oilsResponse.pm
1 package OpenSRF::DomainObject::oilsResponse;
2 use vars qw/@EXPORT_OK %EXPORT_TAGS/;
3 use Exporter;
4 use JSON;
5 use base qw/Exporter/;
6 use OpenSRF::Utils::Logger qw/:level/;
7
8 JSON->register_class_hint( hint => 'osrfResponse', name => 'OpenSRF::DomainObject::oilsResponse', type => 'hash' );
9
10 BEGIN {
11 @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 %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 =head1 NAME
30
31 OpenSRF::DomainObject::oilsResponse
32
33 =head1 SYNOPSIS
34
35 use OpenSRF::DomainObject::oilsResponse qw/:status/;
36
37 my $resp = OpenSRF::DomainObject::oilsResponse->new;
38
39 $resp->status( 'a status message' );
40
41 $resp->statusCode( STATUS_CONTINUE );
42
43 $client->respond( $resp );
44
45 =head1 ABSTRACT
46
47 OpenSRF::DomainObject::oilsResponse implements the base class for all Application
48 layer messages send between the client and server.
49
50 =cut
51
52 sub STATUS_CONTINUE             { return 100 }
53
54 sub STATUS_OK                           { return 200 }
55 sub STATUS_ACCEPTED             { return 202 }
56 sub STATUS_COMPLETE             { return 205 }
57
58 sub STATUS_REDIRECTED   { return 307 }
59
60 sub STATUS_BADREQUEST   { return 400 }
61 sub STATUS_UNAUTHORIZED { return 401 }
62 sub STATUS_FORBIDDEN            { return 403 }
63 sub STATUS_NOTFOUND             { return 404 }
64 sub STATUS_NOTALLOWED   { return 405 }
65 sub STATUS_TIMEOUT              { return 408 }
66 sub STATUS_EXPFAILED            { return 417 }
67
68 sub STATUS_INTERNALSERVERERROR  { return 500 }
69 sub STATUS_NOTIMPLEMENTED                       { return 501 }
70 sub STATUS_VERSIONNOTSUPPORTED  { return 505 }
71
72 my $log = 'OpenSRF::Utils::Logger';
73
74 sub toString {
75         my $self = shift;
76         my $pretty = shift;
77         return JSON->perl2prettyJSON($self) if ($pretty);
78         return JSON->perl2JSON($self);
79 }
80
81 sub new {
82         my $class = shift;
83         $class = ref($class) || $class;
84
85         my $default_status = eval "\$${class}::status";
86         my $default_statusCode = eval "\$${class}::statusCode";
87
88         my %args = (    status => $default_status,
89                         statusCode => $default_statusCode,
90                         @_ );
91         
92         return bless( \%args => $class );
93 }
94
95 sub status {
96         my $self = shift;
97         my $val = shift;
98         $self->{status} = $val if (defined $val);
99         return $self->{status};
100 }
101
102 sub statusCode {
103         my $self = shift;
104         my $val = shift;
105         $self->{statusCode} = $val if (defined $val);
106         return $self->{statusCode};
107 }
108
109
110 #-------------------------------------------------------------------------------
111
112
113
114 package OpenSRF::DomainObject::oilsStatus;
115 use OpenSRF::DomainObject::oilsResponse qw/:status/;
116 use base 'OpenSRF::DomainObject::oilsResponse';
117 use vars qw/$status $statusCode/;
118 JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' );
119
120 =head1 NAME
121
122 OpenSRF::DomainObject::oilsException
123
124 =head1 SYNOPSIS
125
126 use OpenSRF::DomainObject::oilsResponse;
127
128 ...
129
130 # something happens.
131
132 $client->status( OpenSRF::DomainObject::oilsStatus->new );
133
134 =head1 ABSTRACT
135
136 The base class for Status messages sent between client and server.  This
137 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and 
138 sets the default B<status> to C<Status> and B<statusCode> to C<STATUS_OK>.
139
140 =cut
141
142 $status = 'Status';
143 $statusCode = STATUS_OK;
144
145 package OpenSRF::DomainObject::oilsConnectStatus;
146 use OpenSRF::DomainObject::oilsResponse qw/:status/;
147 use base 'OpenSRF::DomainObject::oilsStatus';
148 use vars qw/$status $statusCode/;
149 JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' );
150
151 =head1 NAME
152
153 OpenSRF::DomainObject::oilsConnectStatus
154
155 =head1 SYNOPSIS
156
157 use OpenSRF::DomainObject::oilsResponse;
158
159 ...
160
161 # something happens.
162
163 $client->status( new OpenSRF::DomainObject::oilsConnectStatus );
164
165 =head1 ABSTRACT
166
167 The class for Stati relating to the connection status of a session.  This
168 is implemented on top of the C<OpenSRF::DomainObject::oilsStatus> class, and 
169 sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>.
170
171 =head1 SEE ALSO
172
173 B<OpenSRF::DomainObject::oilsStatus>
174
175 =cut
176
177 $status = 'Connection Successful';
178 $statusCode = STATUS_OK;
179
180
181
182
183 package OpenSRF::DomainObject::oilsContinueStatus;
184 use OpenSRF::DomainObject::oilsResponse qw/:status/;
185 use base 'OpenSRF::DomainObject::oilsStatus';
186 use vars qw/$status $statusCode/;
187 JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
188
189 =head1 NAME
190
191 OpenSRF::DomainObject::oilsContinueStatus
192
193 =head1 SYNOPSIS
194
195 use OpenSRF::DomainObject::oilsResponse;
196
197 ...
198
199 # something happens.
200
201 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
202
203 =head1 ABSTRACT
204
205 Implements the STATUS_CONTINUE message, informing the client that it should
206 continue to wait for a response to it's request.
207
208 =head1 SEE ALSO
209
210 B<OpenSRF::DomainObject::oilsStatus>
211
212 =cut
213
214 $status = 'Please hold.  Creating response...';
215 $statusCode = STATUS_CONTINUE;
216
217 1;
218
219
220
221 #-------------------------------------------------------------------------------
222
223
224
225 package OpenSRF::DomainObject::oilsResult;
226 use OpenSRF::DomainObject::oilsResponse qw/:status/;
227 use OpenSRF::DomainObject::oilsPrimitive;
228 use base 'OpenSRF::DomainObject::oilsResponse';
229 use vars qw/$status $statusCode/;
230 JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
231
232
233 $status = 'OK';
234 $statusCode = STATUS_OK;
235
236 =head1 NAME
237
238 OpenSRF::DomainObject::oilsResult
239
240 =head1 SYNOPSIS
241
242 use OpenSRF::DomainObject::oilsResponse;
243
244  .... do stuff, create $object ...
245
246 my $res = OpenSRF::DomainObject::oilsResult->new;
247
248 $res->content($object)
249
250 $session->respond( $res );
251
252 =head1 ABSTRACT
253
254 This is the base class for encapuslating RESULT messages send from the server
255 to a client.  It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and
256 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
257
258 =head1 METHODS
259
260 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
261
262 =over 4
263
264 Sets or gets the content of the response.  This should be exactly one object
265 of (sub)type domainObject or domainObjectCollection.
266
267 =back
268
269 =cut
270
271 sub content {
272         my $self = shift;
273         my $val = shift;
274
275         $self->{content} = $val if (defined $val);
276         return $self->{content};
277 }
278
279 =head1 SEE ALSO
280
281 B<OpenSRF::DomainObject::oilsResponse>
282
283 =cut
284
285 1;
286
287
288
289 #-------------------------------------------------------------------------------
290
291
292
293 package OpenSRF::DomainObject::oilsException;
294 use OpenSRF::DomainObject::oilsResponse qw/:status/;
295 use OpenSRF::EX;
296 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
297 use vars qw/$status $statusCode/;
298 use Error;
299 JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
300
301 sub message {
302         my $self = shift;
303         return '<' . $self->statusCode . '>  ' . $self->status;
304 }
305
306 sub new {
307         my $class = shift;
308         return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
309 }
310
311
312 =head1 NAME
313
314 OpenSRF::DomainObject::oilsException
315
316 =head1 SYNOPSIS
317
318 use OpenSRF::DomainObject::oilsResponse;
319
320 ...
321
322 # something breaks.
323
324 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
325
326 =head1 ABSTRACT
327
328 The base class for Exception messages sent between client and server.  This
329 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and 
330 sets the default B<status> to C<Exception occured> and B<statusCode> to C<STATUS_BADREQUEST>.
331
332 =cut
333
334 $status = 'Exception occured';
335 $statusCode = STATUS_INTERNALSERVERERROR;
336
337 package OpenSRF::DomainObject::oilsConnectException;
338 use OpenSRF::DomainObject::oilsResponse qw/:status/;
339 use OpenSRF::EX;
340 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
341 use vars qw/$status $statusCode/;
342 JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
343
344 =head1 NAME
345
346 OpenSRF::DomainObject::oilsConnectException
347
348 =head1 SYNOPSIS
349
350 use OpenSRF::DomainObject::oilsResponse;
351
352 ...
353
354 # something breaks while connecting.
355
356 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
357
358 =head1 ABSTRACT
359
360 The class for Exceptions that occur durring the B<CONNECT> phase of a session.  This
361 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and 
362 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
363
364 =head1 SEE ALSO
365
366 B<OpenSRF::DomainObject::oilsException>
367
368 =cut
369
370
371 $status = 'Connect Request Failed';
372 $statusCode = STATUS_FORBIDDEN;
373
374 package OpenSRF::DomainObject::oilsMethodException;
375 use OpenSRF::DomainObject::oilsResponse qw/:status/;
376 use base 'OpenSRF::DomainObject::oilsException';
377 use vars qw/$status $statusCode/;
378 JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
379
380 =head1 NAME
381
382 OpenSRF::DomainObject::oilsMehtodException
383
384 =head1 SYNOPSIS
385
386 use OpenSRF::DomainObject::oilsResponse;
387
388 ...
389
390 # something breaks while looking up or starting
391 # a method call.
392
393 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException );
394
395 =head1 ABSTRACT
396
397 The class for Exceptions that occur durring the B<CONNECT> phase of a session.  This
398 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and 
399 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>.
400
401 =head1 SEE ALSO
402
403 B<OpenSRF::DomainObject::oilsException>
404
405 =cut
406
407
408 $status = 'Method not found';
409 $statusCode = STATUS_NOTFOUND;
410
411 # -------------------------------------------
412
413 package OpenSRF::DomainObject::oilsServerError;
414 use OpenSRF::DomainObject::oilsResponse qw/:status/;
415 use base 'OpenSRF::DomainObject::oilsException';
416 use vars qw/$status $statusCode/;
417 JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
418
419 $status = 'Internal Server Error';
420 $statusCode = STATUS_INTERNALSERVERERROR;
421
422 # -------------------------------------------
423
424
425
426
427
428 package OpenSRF::DomainObject::oilsBrokenSession;
429 use OpenSRF::DomainObject::oilsResponse qw/:status/;
430 use OpenSRF::EX;
431 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
432 use vars qw/$status $statusCode/;
433 JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
434 $status = "Request on Disconnected Session";
435 $statusCode = STATUS_EXPFAILED;
436
437 package OpenSRF::DomainObject::oilsXMLParseError;
438 use OpenSRF::DomainObject::oilsResponse qw/:status/;
439 use OpenSRF::EX;
440 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
441 use vars qw/$status $statusCode/;
442 JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
443 $status = "XML Parse Error";
444 $statusCode = STATUS_EXPFAILED;
445
446 package OpenSRF::DomainObject::oilsAuthException;
447 use OpenSRF::DomainObject::oilsResponse qw/:status/;
448 use OpenSRF::EX;
449 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
450 JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
451 use vars qw/$status $statusCode/;
452 $status = "Authentication Failure";
453 $statusCode = STATUS_FORBIDDEN;
454
455 1;