]> git.evergreen-ils.org Git - working/Evergreen.git/blob - OpenSRF/src/perlmods/OpenSRF/DomainObject/oilsResponse.pm
59f6138667772454b4f385426fef3516efc195fa
[working/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', class => 'OpenSRF::DomainObject::oilsResponse' );
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
119 =head1 NAME
120
121 OpenSRF::DomainObject::oilsException
122
123 =head1 SYNOPSIS
124
125 use OpenSRF::DomainObject::oilsResponse;
126
127 ...
128
129 # something happens.
130
131 $client->status( OpenSRF::DomainObject::oilsStatus->new );
132
133 =head1 ABSTRACT
134
135 The base class for Status messages sent between client and server.  This
136 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and 
137 sets the default B<status> to C<Status> and B<statusCode> to C<STATUS_OK>.
138
139 =cut
140
141 $status = 'Status';
142 $statusCode = STATUS_OK;
143
144 package OpenSRF::DomainObject::oilsConnectStatus;
145 use OpenSRF::DomainObject::oilsResponse qw/:status/;
146 use base 'OpenSRF::DomainObject::oilsStatus';
147 use vars qw/$status $statusCode/;
148
149 =head1 NAME
150
151 OpenSRF::DomainObject::oilsConnectStatus
152
153 =head1 SYNOPSIS
154
155 use OpenSRF::DomainObject::oilsResponse;
156
157 ...
158
159 # something happens.
160
161 $client->status( new OpenSRF::DomainObject::oilsConnectStatus );
162
163 =head1 ABSTRACT
164
165 The class for Stati relating to the connection status of a session.  This
166 is implemented on top of the C<OpenSRF::DomainObject::oilsStatus> class, and 
167 sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>.
168
169 =head1 SEE ALSO
170
171 B<OpenSRF::DomainObject::oilsStatus>
172
173 =cut
174
175 $status = 'Connection Successful';
176 $statusCode = STATUS_OK;
177
178
179
180
181 package OpenSRF::DomainObject::oilsContinueStatus;
182 use OpenSRF::DomainObject::oilsResponse qw/:status/;
183 use base 'OpenSRF::DomainObject::oilsStatus';
184 use vars qw/$status $statusCode/;
185
186 =head1 NAME
187
188 OpenSRF::DomainObject::oilsContinueStatus
189
190 =head1 SYNOPSIS
191
192 use OpenSRF::DomainObject::oilsResponse;
193
194 ...
195
196 # something happens.
197
198 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
199
200 =head1 ABSTRACT
201
202 Implements the STATUS_CONTINUE message, informing the client that it should
203 continue to wait for a response to it's request.
204
205 =head1 SEE ALSO
206
207 B<OpenSRF::DomainObject::oilsStatus>
208
209 =cut
210
211 $status = 'Please hold.  Creating response...';
212 $statusCode = STATUS_CONTINUE;
213
214 1;
215
216
217
218 #-------------------------------------------------------------------------------
219
220
221
222 package OpenSRF::DomainObject::oilsResult;
223 use OpenSRF::DomainObject::oilsResponse qw/:status/;
224 use OpenSRF::DomainObject::oilsPrimitive;
225 use base 'OpenSRF::DomainObject::oilsResponse';
226 use vars qw/$status $statusCode/;
227
228
229 $status = 'OK';
230 $statusCode = STATUS_OK;
231
232 =head1 NAME
233
234 OpenSRF::DomainObject::oilsResult
235
236 =head1 SYNOPSIS
237
238 use OpenSRF::DomainObject::oilsResponse;
239
240  .... do stuff, create $object ...
241
242 my $res = OpenSRF::DomainObject::oilsResult->new;
243
244 $res->content($object)
245
246 $session->respond( $res );
247
248 =head1 ABSTRACT
249
250 This is the base class for encapuslating RESULT messages send from the server
251 to a client.  It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and
252 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
253
254 =head1 METHODS
255
256 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
257
258 =over 4
259
260 Sets or gets the content of the response.  This should be exactly one object
261 of (sub)type domainObject or domainObjectCollection.
262
263 =back
264
265 =cut
266
267 sub content {
268         my $self = shift;
269         my $val = shift;
270
271         $self->{content} = $val if (defined $val);
272         return $self->{content};
273 }
274
275 =head1 SEE ALSO
276
277 B<OpenSRF::DomainObject::oilsResponse>
278
279 =cut
280
281 1;
282
283
284
285 #-------------------------------------------------------------------------------
286
287
288
289 package OpenSRF::DomainObject::oilsException;
290 use OpenSRF::DomainObject::oilsResponse qw/:status/;
291 use OpenSRF::EX;
292 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
293 use vars qw/$status $statusCode/;
294 use Error;
295
296 sub message {
297         my $self = shift;
298         return '<' . $self->statusCode . '>  ' . $self->status;
299 }
300
301 sub new {
302         my $class = shift;
303         return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
304 }
305
306
307 =head1 NAME
308
309 OpenSRF::DomainObject::oilsException
310
311 =head1 SYNOPSIS
312
313 use OpenSRF::DomainObject::oilsResponse;
314
315 ...
316
317 # something breaks.
318
319 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
320
321 =head1 ABSTRACT
322
323 The base class for Exception messages sent between client and server.  This
324 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and 
325 sets the default B<status> to C<Exception occured> and B<statusCode> to C<STATUS_BADREQUEST>.
326
327 =cut
328
329 $status = 'Exception occured';
330 $statusCode = STATUS_INTERNALSERVERERROR;
331
332 package OpenSRF::DomainObject::oilsConnectException;
333 use OpenSRF::DomainObject::oilsResponse qw/:status/;
334 use OpenSRF::EX;
335 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
336 use vars qw/$status $statusCode/;
337
338 =head1 NAME
339
340 OpenSRF::DomainObject::oilsConnectException
341
342 =head1 SYNOPSIS
343
344 use OpenSRF::DomainObject::oilsResponse;
345
346 ...
347
348 # something breaks while connecting.
349
350 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
351
352 =head1 ABSTRACT
353
354 The class for Exceptions that occur durring the B<CONNECT> phase of a session.  This
355 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and 
356 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
357
358 =head1 SEE ALSO
359
360 B<OpenSRF::DomainObject::oilsException>
361
362 =cut
363
364
365 $status = 'Connect Request Failed';
366 $statusCode = STATUS_FORBIDDEN;
367
368 package OpenSRF::DomainObject::oilsMethodException;
369 use OpenSRF::DomainObject::oilsResponse qw/:status/;
370 use base 'OpenSRF::DomainObject::oilsException';
371 use vars qw/$status $statusCode/;
372
373 =head1 NAME
374
375 OpenSRF::DomainObject::oilsMehtodException
376
377 =head1 SYNOPSIS
378
379 use OpenSRF::DomainObject::oilsResponse;
380
381 ...
382
383 # something breaks while looking up or starting
384 # a method call.
385
386 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException );
387
388 =head1 ABSTRACT
389
390 The class for Exceptions that occur durring the B<CONNECT> phase of a session.  This
391 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and 
392 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>.
393
394 =head1 SEE ALSO
395
396 B<OpenSRF::DomainObject::oilsException>
397
398 =cut
399
400
401 $status = 'Method not found';
402 $statusCode = STATUS_NOTFOUND;
403
404 # -------------------------------------------
405
406 package OpenSRF::DomainObject::oilsServerError;
407 use OpenSRF::DomainObject::oilsResponse qw/:status/;
408 use base 'OpenSRF::DomainObject::oilsException';
409 use vars qw/$status $statusCode/;
410
411 $status = 'Internal Server Error';
412 $statusCode = STATUS_INTERNALSERVERERROR;
413
414 # -------------------------------------------
415
416
417
418
419
420 package OpenSRF::DomainObject::oilsBrokenSession;
421 use OpenSRF::DomainObject::oilsResponse qw/:status/;
422 use OpenSRF::EX;
423 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
424 use vars qw/$status $statusCode/;
425 $status = "Request on Disconnected Session";
426 $statusCode = STATUS_EXPFAILED;
427
428 package OpenSRF::DomainObject::oilsXMLParseError;
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 $status = "XML Parse Error";
434 $statusCode = STATUS_EXPFAILED;
435
436 package OpenSRF::DomainObject::oilsAuthException;
437 use OpenSRF::DomainObject::oilsResponse qw/:status/;
438 use OpenSRF::EX;
439 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
440 use vars qw/$status $statusCode/;
441 $status = "Authentication Failure";
442 $statusCode = STATUS_FORBIDDEN;
443
444 1;