1 package OpenSRF::DomainObject::oilsResponse;
2 use vars qw/@EXPORT_OK %EXPORT_TAGS/;
4 use OpenSRF::Utils::JSON;
6 use OpenSRF::Utils::Logger qw/:level/;
8 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResponse', name => 'OpenSRF::DomainObject::oilsResponse', type => 'hash' );
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 STATUS_PARTIAL
20 status => [ qw/STATUS_CONTINUE STATUS_OK STATUS_ACCEPTED
21 STATUS_BADREQUEST STATUS_UNAUTHORIZED STATUS_FORBIDDEN
22 STATUS_NOTFOUND STATUS_NOTALLOWED STATUS_TIMEOUT
23 STATUS_INTERNALSERVERERROR STATUS_NOTIMPLEMENTED
24 STATUS_VERSIONNOTSUPPORTED STATUS_REDIRECTED
25 STATUS_EXPFAILED STATUS_COMPLETE STATUS_PARTIAL
33 OpenSRF::DomainObject::oilsResponse
37 use OpenSRF::DomainObject::oilsResponse qw/:status/;
39 my $resp = OpenSRF::DomainObject::oilsResponse->new;
41 $resp->status( 'a status message' );
43 $resp->statusCode( STATUS_CONTINUE );
45 $client->respond( $resp );
49 OpenSRF::DomainObject::oilsResponse implements the base class for all Application
50 layer messages send between the client and server.
54 sub STATUS_CONTINUE { return 100 }
56 sub STATUS_OK { return 200 }
57 sub STATUS_ACCEPTED { return 202 }
58 sub STATUS_COMPLETE { return 205 }
60 sub STATUS_PARTIAL { return 206 }
61 sub STATUS_NOCONTENT { return 204 }
63 sub STATUS_REDIRECTED { return 307 }
65 sub STATUS_BADREQUEST { return 400 }
66 sub STATUS_UNAUTHORIZED { return 401 }
67 sub STATUS_FORBIDDEN { return 403 }
68 sub STATUS_NOTFOUND { return 404 }
69 sub STATUS_NOTALLOWED { return 405 }
70 sub STATUS_TIMEOUT { return 408 }
71 sub STATUS_EXPFAILED { return 417 }
73 sub STATUS_INTERNALSERVERERROR { return 500 }
74 sub STATUS_NOTIMPLEMENTED { return 501 }
75 sub STATUS_VERSIONNOTSUPPORTED { return 505 }
77 my $log = 'OpenSRF::Utils::Logger';
81 return OpenSRF::Utils::JSON->perl2JSON($self);
86 $class = ref($class) || $class;
88 my $default_status = eval "\$${class}::status";
89 my $default_statusCode = eval "\$${class}::statusCode";
91 my %args = ( status => $default_status,
92 statusCode => $default_statusCode,
95 return bless( \%args => $class );
101 $self->{status} = $val if (defined $val);
102 return $self->{status};
108 $self->{statusCode} = $val if (defined $val);
109 return $self->{statusCode};
112 #-------------------------------------------------------------------------------
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 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' );
122 OpenSRF::DomainObject::oilsException
126 use OpenSRF::DomainObject::oilsResponse;
132 $client->status( OpenSRF::DomainObject::oilsStatus->new );
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>.
143 $statusCode = STATUS_OK;
145 #-------------------------------------------------------------------------------
147 package OpenSRF::DomainObject::oilsConnectStatus;
148 use OpenSRF::DomainObject::oilsResponse qw/:status/;
149 use base 'OpenSRF::DomainObject::oilsStatus';
150 use vars qw/$status $statusCode/;
151 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' );
155 OpenSRF::DomainObject::oilsConnectStatus
159 use OpenSRF::DomainObject::oilsResponse;
165 $client->status( new OpenSRF::DomainObject::oilsConnectStatus );
169 The class for Stati relating to the connection status of a session. This
170 is implemented on top of the C<OpenSRF::DomainObject::oilsStatus> class, and
171 sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>.
175 B<OpenSRF::DomainObject::oilsStatus>
179 $status = 'Connection Successful';
180 $statusCode = STATUS_OK;
182 #-------------------------------------------------------------------------------
184 package OpenSRF::DomainObject::oilsContinueStatus;
185 use OpenSRF::DomainObject::oilsResponse qw/:status/;
186 use base 'OpenSRF::DomainObject::oilsStatus';
187 use vars qw/$status $statusCode/;
188 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
192 OpenSRF::DomainObject::oilsContinueStatus
196 use OpenSRF::DomainObject::oilsResponse;
202 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
206 Implements the STATUS_CONTINUE message, informing the client that it should
207 continue to wait for a response to its request.
211 B<OpenSRF::DomainObject::oilsStatus>
215 $status = 'Please hold. Creating response...';
216 $statusCode = STATUS_CONTINUE;
220 #-------------------------------------------------------------------------------
222 package OpenSRF::DomainObject::oilsResult;
223 use OpenSRF::DomainObject::oilsResponse qw/:status/;
224 use base 'OpenSRF::DomainObject::oilsResponse';
225 use vars qw/$status $statusCode/;
226 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
230 $statusCode = STATUS_OK;
234 OpenSRF::DomainObject::oilsResult
238 use OpenSRF::DomainObject::oilsResponse;
240 .... do stuff, create $object ...
242 my $res = OpenSRF::DomainObject::oilsResult->new;
244 $res->content($object)
246 $session->respond( $res );
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>.
256 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
260 Sets or gets the content of the response. This should be exactly one object
261 of (sub)type domainObject or domainObjectCollection.
271 $self->{content} = $val if (defined $val);
272 return $self->{content};
277 B<OpenSRF::DomainObject::oilsResponse>
283 #-------------------------------------------------------------------------------
285 package OpenSRF::DomainObject::oilsResult::Partial;
286 use OpenSRF::DomainObject::oilsResponse qw/:status/;
287 use base 'OpenSRF::DomainObject::oilsResult';
288 use vars qw/$status $statusCode/;
289 OpenSRF::Utils::JSON->register_class_hint(
290 hint => 'osrfResultPartial',
291 name => 'OpenSRF::DomainObject::oilsResult::Partial',
295 $status = 'Partial Response';
296 $statusCode = STATUS_PARTIAL;
300 OpenSRF::DomainObject::oilsResult::Partial
304 This class is used internally to break apart large OpenSRF messages into small
305 chunks, to reduce the maximum possible stanza size when sending a message over
314 $self->{content} = $val if (defined $val);
315 return $self->{content};
320 B<OpenSRF::DomainObject::oilsResponse>
326 #-------------------------------------------------------------------------------
328 package OpenSRF::DomainObject::oilsResult::PartialComplete;
329 use OpenSRF::DomainObject::oilsResponse qw/:status/;
330 use base 'OpenSRF::DomainObject::oilsResult';
331 use vars qw/$status $statusCode/;
332 OpenSRF::Utils::JSON->register_class_hint(
333 hint => 'osrfResultPartialComplete',
334 name => 'OpenSRF::DomainObject::oilsResult::PartialComplete',
338 $status = 'Partial Response Finalized';
339 $statusCode = STATUS_NOCONTENT;
343 OpenSRF::DomainObject::oilsResult::PartialComplete
347 This class is used internally to mark the end of a stream of small partial
348 OpenSRF messages of type OpenSRF::DomainObject::oilsResult::Partial.
356 $self->{content} = $val if (defined $val);
357 return $self->{content};
362 B<OpenSRF::DomainObject::oilsResponse>
368 #-------------------------------------------------------------------------------
370 package OpenSRF::DomainObject::oilsException;
371 use OpenSRF::DomainObject::oilsResponse qw/:status/;
373 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
374 use vars qw/$status $statusCode/;
376 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
380 return '<' . $self->statusCode . '> ' . $self->status;
385 return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
391 OpenSRF::DomainObject::oilsException
395 use OpenSRF::DomainObject::oilsResponse;
401 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
405 The base class for Exception messages sent between client and server. This
406 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
407 sets the default B<status> to C<Exception occurred> and B<statusCode> to C<STATUS_BADREQUEST>.
411 $status = 'Exception occurred';
412 $statusCode = STATUS_INTERNALSERVERERROR;
414 #-------------------------------------------------------------------------------
416 package OpenSRF::DomainObject::oilsConnectException;
417 use OpenSRF::DomainObject::oilsResponse qw/:status/;
419 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
420 use vars qw/$status $statusCode/;
421 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
425 OpenSRF::DomainObject::oilsConnectException
429 use OpenSRF::DomainObject::oilsResponse;
433 # something breaks while connecting.
435 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
439 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
440 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
441 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
445 B<OpenSRF::DomainObject::oilsException>
450 $status = 'Connect Request Failed';
451 $statusCode = STATUS_FORBIDDEN;
453 #-------------------------------------------------------------------------------
455 package OpenSRF::DomainObject::oilsMethodException;
456 use OpenSRF::DomainObject::oilsResponse qw/:status/;
457 use base 'OpenSRF::DomainObject::oilsException';
458 use vars qw/$status $statusCode/;
459 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
463 OpenSRF::DomainObject::oilsMethodException
467 use OpenSRF::DomainObject::oilsResponse;
471 # something breaks while looking up or starting
474 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException );
478 The class for Exceptions that occur during the B<CONNECT> phase of a session. This
479 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
480 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>.
484 B<OpenSRF::DomainObject::oilsException>
489 $status = 'A server error occurred during method execution';
490 $statusCode = STATUS_INTERNALSERVERERROR;
492 # -------------------------------------------
494 package OpenSRF::DomainObject::oilsServerError;
495 use OpenSRF::DomainObject::oilsResponse qw/:status/;
496 use base 'OpenSRF::DomainObject::oilsException';
497 use vars qw/$status $statusCode/;
498 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
500 $status = 'Internal Server Error';
501 $statusCode = STATUS_INTERNALSERVERERROR;
503 # -------------------------------------------
505 package OpenSRF::DomainObject::oilsBrokenSession;
506 use OpenSRF::DomainObject::oilsResponse qw/:status/;
508 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
509 use vars qw/$status $statusCode/;
510 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
511 $status = "Request on Disconnected Session";
512 $statusCode = STATUS_EXPFAILED;
514 #-------------------------------------------------------------------------------
516 package OpenSRF::DomainObject::oilsXMLParseError;
517 use OpenSRF::DomainObject::oilsResponse qw/:status/;
519 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
520 use vars qw/$status $statusCode/;
521 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
522 $status = "XML Parse Error";
523 $statusCode = STATUS_EXPFAILED;
525 #-------------------------------------------------------------------------------
527 package OpenSRF::DomainObject::oilsAuthException;
528 use OpenSRF::DomainObject::oilsResponse qw/:status/;
530 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
531 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
532 use vars qw/$status $statusCode/;
533 $status = "Authentication Failure";
534 $statusCode = STATUS_FORBIDDEN;