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/;
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/ ],
31 OpenSRF::DomainObject::oilsResponse
35 use OpenSRF::DomainObject::oilsResponse qw/:status/;
37 my $resp = OpenSRF::DomainObject::oilsResponse->new;
39 $resp->status( 'a status message' );
41 $resp->statusCode( STATUS_CONTINUE );
43 $client->respond( $resp );
47 OpenSRF::DomainObject::oilsResponse implements the base class for all Application
48 layer messages send between the client and server.
52 sub STATUS_CONTINUE { return 100 }
54 sub STATUS_OK { return 200 }
55 sub STATUS_ACCEPTED { return 202 }
56 sub STATUS_COMPLETE { return 205 }
58 sub STATUS_PARTIAL { return 206 }
59 sub STATUS_NOCONTENT { return 204 }
61 sub STATUS_REDIRECTED { return 307 }
63 sub STATUS_BADREQUEST { return 400 }
64 sub STATUS_UNAUTHORIZED { return 401 }
65 sub STATUS_FORBIDDEN { return 403 }
66 sub STATUS_NOTFOUND { return 404 }
67 sub STATUS_NOTALLOWED { return 405 }
68 sub STATUS_TIMEOUT { return 408 }
69 sub STATUS_EXPFAILED { return 417 }
71 sub STATUS_INTERNALSERVERERROR { return 500 }
72 sub STATUS_NOTIMPLEMENTED { return 501 }
73 sub STATUS_VERSIONNOTSUPPORTED { return 505 }
75 my $log = 'OpenSRF::Utils::Logger';
79 return OpenSRF::Utils::JSON->perl2JSON($self);
84 $class = ref($class) || $class;
86 my $default_status = eval "\$${class}::status";
87 my $default_statusCode = eval "\$${class}::statusCode";
89 my %args = ( status => $default_status,
90 statusCode => $default_statusCode,
93 return bless( \%args => $class );
99 $self->{status} = $val if (defined $val);
100 return $self->{status};
106 $self->{statusCode} = $val if (defined $val);
107 return $self->{statusCode};
110 #-------------------------------------------------------------------------------
112 package OpenSRF::DomainObject::oilsStatus;
113 use OpenSRF::DomainObject::oilsResponse qw/:status/;
114 use base 'OpenSRF::DomainObject::oilsResponse';
115 use vars qw/$status $statusCode/;
116 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' );
120 OpenSRF::DomainObject::oilsException
124 use OpenSRF::DomainObject::oilsResponse;
130 $client->status( OpenSRF::DomainObject::oilsStatus->new );
134 The base class for Status messages sent between client and server. This
135 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
136 sets the default B<status> to C<Status> and B<statusCode> to C<STATUS_OK>.
141 $statusCode = STATUS_OK;
143 #-------------------------------------------------------------------------------
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 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' );
153 OpenSRF::DomainObject::oilsConnectStatus
157 use OpenSRF::DomainObject::oilsResponse;
163 $client->status( new OpenSRF::DomainObject::oilsConnectStatus );
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>.
173 B<OpenSRF::DomainObject::oilsStatus>
177 $status = 'Connection Successful';
178 $statusCode = STATUS_OK;
180 #-------------------------------------------------------------------------------
182 package OpenSRF::DomainObject::oilsContinueStatus;
183 use OpenSRF::DomainObject::oilsResponse qw/:status/;
184 use base 'OpenSRF::DomainObject::oilsStatus';
185 use vars qw/$status $statusCode/;
186 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
190 OpenSRF::DomainObject::oilsContinueStatus
194 use OpenSRF::DomainObject::oilsResponse;
200 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
204 Implements the STATUS_CONTINUE message, informing the client that it should
205 continue to wait for a response to its request.
209 B<OpenSRF::DomainObject::oilsStatus>
213 $status = 'Please hold. Creating response...';
214 $statusCode = STATUS_CONTINUE;
218 #-------------------------------------------------------------------------------
220 package OpenSRF::DomainObject::oilsResult;
221 use OpenSRF::DomainObject::oilsResponse qw/:status/;
222 use base 'OpenSRF::DomainObject::oilsResponse';
223 use vars qw/$status $statusCode/;
224 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
228 $statusCode = STATUS_OK;
232 OpenSRF::DomainObject::oilsResult
236 use OpenSRF::DomainObject::oilsResponse;
238 .... do stuff, create $object ...
240 my $res = OpenSRF::DomainObject::oilsResult->new;
242 $res->content($object)
244 $session->respond( $res );
248 This is the base class for encapuslating RESULT messages send from the server
249 to a client. It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and
250 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
254 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
258 Sets or gets the content of the response. This should be exactly one object
259 of (sub)type domainObject or domainObjectCollection.
269 $self->{content} = $val if (defined $val);
270 return $self->{content};
275 B<OpenSRF::DomainObject::oilsResponse>
281 #-------------------------------------------------------------------------------
283 package OpenSRF::DomainObject::oilsResult::Partial;
284 use OpenSRF::DomainObject::oilsResponse qw/:status/;
285 use base 'OpenSRF::DomainObject::oilsResult';
286 use vars qw/$status $statusCode/;
287 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult::Partial', type => 'hash' );
290 $status = 'Partial Response';
291 $statusCode = STATUS_PARTIAL;
295 OpenSRF::DomainObject::oilsResult::Partial
299 This class is used internally to break apart large OpenSRF messages into small
300 chunks, to reduce the maximum possible stanza size when sending a message over
309 $self->{content} = $val if (defined $val);
310 return $self->{content};
315 B<OpenSRF::DomainObject::oilsResponse>
321 #-------------------------------------------------------------------------------
323 package OpenSRF::DomainObject::oilsResult::PartialComplete;
324 use OpenSRF::DomainObject::oilsResponse qw/:status/;
325 use base 'OpenSRF::DomainObject::oilsResult';
326 use vars qw/$status $statusCode/;
327 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult::Partial', type => 'hash' );
330 $status = 'Partial Response Finalized';
331 $statusCode = STATUS_NOCONTENT;
335 OpenSRF::DomainObject::oilsResult::Partial
339 This class is used internally to mark the end of a stream of small partial
340 OpenSRF messages of type OpenSRF::DomainObject::oilsResult::Partial.
348 $self->{content} = $val if (defined $val);
349 return $self->{content};
354 B<OpenSRF::DomainObject::oilsResponse>
360 #-------------------------------------------------------------------------------
362 package OpenSRF::DomainObject::oilsException;
363 use OpenSRF::DomainObject::oilsResponse qw/:status/;
365 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
366 use vars qw/$status $statusCode/;
368 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
372 return '<' . $self->statusCode . '> ' . $self->status;
377 return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
383 OpenSRF::DomainObject::oilsException
387 use OpenSRF::DomainObject::oilsResponse;
393 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
397 The base class for Exception messages sent between client and server. This
398 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
399 sets the default B<status> to C<Exception occurred> and B<statusCode> to C<STATUS_BADREQUEST>.
403 $status = 'Exception occurred';
404 $statusCode = STATUS_INTERNALSERVERERROR;
406 #-------------------------------------------------------------------------------
408 package OpenSRF::DomainObject::oilsConnectException;
409 use OpenSRF::DomainObject::oilsResponse qw/:status/;
411 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
412 use vars qw/$status $statusCode/;
413 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
417 OpenSRF::DomainObject::oilsConnectException
421 use OpenSRF::DomainObject::oilsResponse;
425 # something breaks while connecting.
427 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
431 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
432 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
433 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
437 B<OpenSRF::DomainObject::oilsException>
442 $status = 'Connect Request Failed';
443 $statusCode = STATUS_FORBIDDEN;
445 #-------------------------------------------------------------------------------
447 package OpenSRF::DomainObject::oilsMethodException;
448 use OpenSRF::DomainObject::oilsResponse qw/:status/;
449 use base 'OpenSRF::DomainObject::oilsException';
450 use vars qw/$status $statusCode/;
451 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
455 OpenSRF::DomainObject::oilsMethodException
459 use OpenSRF::DomainObject::oilsResponse;
463 # something breaks while looking up or starting
466 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException );
470 The class for Exceptions that occur during the B<CONNECT> phase of a session. This
471 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
472 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>.
476 B<OpenSRF::DomainObject::oilsException>
481 $status = 'A server error occurred during method execution';
482 $statusCode = STATUS_INTERNALSERVERERROR;
484 # -------------------------------------------
486 package OpenSRF::DomainObject::oilsServerError;
487 use OpenSRF::DomainObject::oilsResponse qw/:status/;
488 use base 'OpenSRF::DomainObject::oilsException';
489 use vars qw/$status $statusCode/;
490 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
492 $status = 'Internal Server Error';
493 $statusCode = STATUS_INTERNALSERVERERROR;
495 # -------------------------------------------
497 package OpenSRF::DomainObject::oilsBrokenSession;
498 use OpenSRF::DomainObject::oilsResponse qw/:status/;
500 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
501 use vars qw/$status $statusCode/;
502 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
503 $status = "Request on Disconnected Session";
504 $statusCode = STATUS_EXPFAILED;
506 #-------------------------------------------------------------------------------
508 package OpenSRF::DomainObject::oilsXMLParseError;
509 use OpenSRF::DomainObject::oilsResponse qw/:status/;
511 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
512 use vars qw/$status $statusCode/;
513 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
514 $status = "XML Parse Error";
515 $statusCode = STATUS_EXPFAILED;
517 #-------------------------------------------------------------------------------
519 package OpenSRF::DomainObject::oilsAuthException;
520 use OpenSRF::DomainObject::oilsResponse qw/:status/;
522 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
523 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
524 use vars qw/$status $statusCode/;
525 $status = "Authentication Failure";
526 $statusCode = STATUS_FORBIDDEN;