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_SERVICEUNAVAILABLE
16 STATUS_VERSIONNOTSUPPORTED STATUS_REDIRECTED
17 STATUS_EXPFAILED STATUS_COMPLETE STATUS_PARTIAL
21 status => [ qw/STATUS_CONTINUE STATUS_OK STATUS_ACCEPTED
22 STATUS_BADREQUEST STATUS_UNAUTHORIZED STATUS_FORBIDDEN
23 STATUS_NOTFOUND STATUS_NOTALLOWED STATUS_TIMEOUT
24 STATUS_INTERNALSERVERERROR STATUS_NOTIMPLEMENTED
25 STATUS_SERVICEUNAVAILABLE
26 STATUS_VERSIONNOTSUPPORTED STATUS_REDIRECTED
27 STATUS_EXPFAILED STATUS_COMPLETE STATUS_PARTIAL
35 OpenSRF::DomainObject::oilsResponse
39 use OpenSRF::DomainObject::oilsResponse qw/:status/;
41 my $resp = OpenSRF::DomainObject::oilsResponse->new;
43 $resp->status( 'a status message' );
45 $resp->statusCode( STATUS_CONTINUE );
47 $client->respond( $resp );
51 OpenSRF::DomainObject::oilsResponse implements the base class for all Application
52 layer messages send between the client and server.
56 sub STATUS_CONTINUE { return 100 }
58 sub STATUS_OK { return 200 }
59 sub STATUS_ACCEPTED { return 202 }
60 sub STATUS_COMPLETE { return 205 }
62 sub STATUS_PARTIAL { return 206 }
63 sub STATUS_NOCONTENT { return 204 }
65 sub STATUS_REDIRECTED { return 307 }
67 sub STATUS_BADREQUEST { return 400 }
68 sub STATUS_UNAUTHORIZED { return 401 }
69 sub STATUS_FORBIDDEN { return 403 }
70 sub STATUS_NOTFOUND { return 404 }
71 sub STATUS_NOTALLOWED { return 405 }
72 sub STATUS_TIMEOUT { return 408 }
73 sub STATUS_EXPFAILED { return 417 }
75 sub STATUS_INTERNALSERVERERROR { return 500 }
76 sub STATUS_NOTIMPLEMENTED { return 501 }
77 sub STATUS_SERVICEUNAVAILABLE { return 503 }
78 sub STATUS_VERSIONNOTSUPPORTED { return 505 }
80 my $log = 'OpenSRF::Utils::Logger';
84 return OpenSRF::Utils::JSON->perl2JSON($self);
89 $class = ref($class) || $class;
91 my $default_status = eval "\$${class}::status";
92 my $default_statusCode = eval "\$${class}::statusCode";
94 my %args = ( status => $default_status,
95 statusCode => $default_statusCode,
98 return bless( \%args => $class );
104 $self->{status} = $val if (defined $val);
105 return $self->{status};
111 $self->{statusCode} = $val if (defined $val);
112 return $self->{statusCode};
115 #-------------------------------------------------------------------------------
117 package OpenSRF::DomainObject::oilsStatus;
118 use OpenSRF::DomainObject::oilsResponse qw/:status/;
119 use base 'OpenSRF::DomainObject::oilsResponse';
120 use vars qw/$status $statusCode/;
121 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' );
125 OpenSRF::DomainObject::oilsException
129 use OpenSRF::DomainObject::oilsResponse;
135 $client->status( OpenSRF::DomainObject::oilsStatus->new );
139 The base class for Status messages sent between client and server. This
140 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
141 sets the default B<status> to C<Status> and B<statusCode> to C<STATUS_OK>.
146 $statusCode = STATUS_OK;
148 #-------------------------------------------------------------------------------
150 package OpenSRF::DomainObject::oilsConnectStatus;
151 use OpenSRF::DomainObject::oilsResponse qw/:status/;
152 use base 'OpenSRF::DomainObject::oilsStatus';
153 use vars qw/$status $statusCode/;
154 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' );
158 OpenSRF::DomainObject::oilsConnectStatus
162 use OpenSRF::DomainObject::oilsResponse;
168 $client->status( new OpenSRF::DomainObject::oilsConnectStatus );
172 The class for Stati relating to the connection status of a session. This
173 is implemented on top of the C<OpenSRF::DomainObject::oilsStatus> class, and
174 sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>.
178 B<OpenSRF::DomainObject::oilsStatus>
182 $status = 'Connection Successful';
183 $statusCode = STATUS_OK;
185 #-------------------------------------------------------------------------------
187 package OpenSRF::DomainObject::oilsContinueStatus;
188 use OpenSRF::DomainObject::oilsResponse qw/:status/;
189 use base 'OpenSRF::DomainObject::oilsStatus';
190 use vars qw/$status $statusCode/;
191 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
195 OpenSRF::DomainObject::oilsContinueStatus
199 use OpenSRF::DomainObject::oilsResponse;
205 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
209 Implements the STATUS_CONTINUE message, informing the client that it should
210 continue to wait for a response to its request.
214 B<OpenSRF::DomainObject::oilsStatus>
218 $status = 'Please hold. Creating response...';
219 $statusCode = STATUS_CONTINUE;
223 #-------------------------------------------------------------------------------
225 package OpenSRF::DomainObject::oilsResult;
226 use OpenSRF::DomainObject::oilsResponse qw/:status/;
227 use base 'OpenSRF::DomainObject::oilsResponse';
228 use vars qw/$status $statusCode/;
229 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
233 $statusCode = STATUS_OK;
237 OpenSRF::DomainObject::oilsResult
241 use OpenSRF::DomainObject::oilsResponse;
243 .... do stuff, create $object ...
245 my $res = OpenSRF::DomainObject::oilsResult->new;
247 $res->content($object)
249 $session->respond( $res );
253 This is the base class for encapuslating RESULT messages send from the server
254 to a client. It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and
255 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
259 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
263 Sets or gets the content of the response. This should be exactly one object
264 of (sub)type domainObject or domainObjectCollection.
274 $self->{content} = $val if (defined $val);
275 return $self->{content};
280 B<OpenSRF::DomainObject::oilsResponse>
286 #-------------------------------------------------------------------------------
288 package OpenSRF::DomainObject::oilsResult::Partial;
289 use OpenSRF::DomainObject::oilsResponse qw/:status/;
290 use base 'OpenSRF::DomainObject::oilsResult';
291 use vars qw/$status $statusCode/;
292 OpenSRF::Utils::JSON->register_class_hint(
293 hint => 'osrfResultPartial',
294 name => 'OpenSRF::DomainObject::oilsResult::Partial',
298 $status = 'Partial Response';
299 $statusCode = STATUS_PARTIAL;
303 OpenSRF::DomainObject::oilsResult::Partial
307 This class is used internally to break apart large OpenSRF messages into small
308 chunks, to reduce the maximum possible stanza size when sending a message over
317 $self->{content} = $val if (defined $val);
318 return $self->{content};
323 B<OpenSRF::DomainObject::oilsResponse>
329 #-------------------------------------------------------------------------------
331 package OpenSRF::DomainObject::oilsResult::PartialComplete;
332 use OpenSRF::DomainObject::oilsResponse qw/:status/;
333 use base 'OpenSRF::DomainObject::oilsResult';
334 use vars qw/$status $statusCode/;
335 OpenSRF::Utils::JSON->register_class_hint(
336 hint => 'osrfResultPartialComplete',
337 name => 'OpenSRF::DomainObject::oilsResult::PartialComplete',
341 $status = 'Partial Response Finalized';
342 $statusCode = STATUS_NOCONTENT;
346 OpenSRF::DomainObject::oilsResult::PartialComplete
350 This class is used internally to mark the end of a stream of small partial
351 OpenSRF messages of type OpenSRF::DomainObject::oilsResult::Partial.
359 $self->{content} = $val if (defined $val);
360 return $self->{content};
365 B<OpenSRF::DomainObject::oilsResponse>
371 #-------------------------------------------------------------------------------
373 package OpenSRF::DomainObject::oilsException;
374 use OpenSRF::DomainObject::oilsResponse qw/:status/;
376 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
377 use vars qw/$status $statusCode/;
379 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
383 return '<' . $self->statusCode . '> ' . $self->status;
388 return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
394 OpenSRF::DomainObject::oilsException
398 use OpenSRF::DomainObject::oilsResponse;
404 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
408 The base class for Exception messages sent between client and server. This
409 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
410 sets the default B<status> to C<Exception occurred> and B<statusCode> to C<STATUS_BADREQUEST>.
414 $status = 'Exception occurred';
415 $statusCode = STATUS_INTERNALSERVERERROR;
417 #-------------------------------------------------------------------------------
419 package OpenSRF::DomainObject::oilsConnectException;
420 use OpenSRF::DomainObject::oilsResponse qw/:status/;
422 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
423 use vars qw/$status $statusCode/;
424 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
428 OpenSRF::DomainObject::oilsConnectException
432 use OpenSRF::DomainObject::oilsResponse;
436 # something breaks while connecting.
438 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
442 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
443 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
444 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
448 B<OpenSRF::DomainObject::oilsException>
453 $status = 'Connect Request Failed';
454 $statusCode = STATUS_FORBIDDEN;
456 #-------------------------------------------------------------------------------
458 package OpenSRF::DomainObject::oilsMethodException;
459 use OpenSRF::DomainObject::oilsResponse qw/:status/;
460 use base 'OpenSRF::DomainObject::oilsException';
461 use vars qw/$status $statusCode/;
462 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
466 OpenSRF::DomainObject::oilsMethodException
470 use OpenSRF::DomainObject::oilsResponse;
474 # something breaks while looking up or starting
477 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException );
481 The class for Exceptions that occur during the B<CONNECT> phase of a session. This
482 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
483 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>.
487 B<OpenSRF::DomainObject::oilsException>
492 $status = 'A server error occurred during method execution';
493 $statusCode = STATUS_INTERNALSERVERERROR;
495 # -------------------------------------------
497 package OpenSRF::DomainObject::oilsServerError;
498 use OpenSRF::DomainObject::oilsResponse qw/:status/;
499 use base 'OpenSRF::DomainObject::oilsException';
500 use vars qw/$status $statusCode/;
501 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
503 $status = 'Internal Server Error';
504 $statusCode = STATUS_INTERNALSERVERERROR;
506 # -------------------------------------------
508 package OpenSRF::DomainObject::oilsBrokenSession;
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 => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
514 $status = "Request on Disconnected Session";
515 $statusCode = STATUS_EXPFAILED;
517 #-------------------------------------------------------------------------------
519 package OpenSRF::DomainObject::oilsXMLParseError;
520 use OpenSRF::DomainObject::oilsResponse qw/:status/;
522 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
523 use vars qw/$status $statusCode/;
524 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
525 $status = "XML Parse Error";
526 $statusCode = STATUS_EXPFAILED;
528 #-------------------------------------------------------------------------------
530 package OpenSRF::DomainObject::oilsAuthException;
531 use OpenSRF::DomainObject::oilsResponse qw/:status/;
533 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
534 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
535 use vars qw/$status $statusCode/;
536 $status = "Authentication Failure";
537 $statusCode = STATUS_FORBIDDEN;