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_REDIRECTED { return 307 }
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 }
68 sub STATUS_INTERNALSERVERERROR { return 500 }
69 sub STATUS_NOTIMPLEMENTED { return 501 }
70 sub STATUS_VERSIONNOTSUPPORTED { return 505 }
72 my $log = 'OpenSRF::Utils::Logger';
77 return OpenSRF::Utils::JSON->perl2prettyJSON($self) if ($pretty);
78 return OpenSRF::Utils::JSON->perl2JSON($self);
83 $class = ref($class) || $class;
85 my $default_status = eval "\$${class}::status";
86 my $default_statusCode = eval "\$${class}::statusCode";
88 my %args = ( status => $default_status,
89 statusCode => $default_statusCode,
92 return bless( \%args => $class );
98 $self->{status} = $val if (defined $val);
99 return $self->{status};
105 $self->{statusCode} = $val if (defined $val);
106 return $self->{statusCode};
109 #-------------------------------------------------------------------------------
111 package OpenSRF::DomainObject::oilsStatus;
112 use OpenSRF::DomainObject::oilsResponse qw/:status/;
113 use base 'OpenSRF::DomainObject::oilsResponse';
114 use vars qw/$status $statusCode/;
115 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' );
119 OpenSRF::DomainObject::oilsException
123 use OpenSRF::DomainObject::oilsResponse;
129 $client->status( OpenSRF::DomainObject::oilsStatus->new );
133 The base class for Status messages sent between client and server. This
134 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
135 sets the default B<status> to C<Status> and B<statusCode> to C<STATUS_OK>.
140 $statusCode = STATUS_OK;
142 #-------------------------------------------------------------------------------
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 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' );
152 OpenSRF::DomainObject::oilsConnectStatus
156 use OpenSRF::DomainObject::oilsResponse;
162 $client->status( new OpenSRF::DomainObject::oilsConnectStatus );
166 The class for Stati relating to the connection status of a session. This
167 is implemented on top of the C<OpenSRF::DomainObject::oilsStatus> class, and
168 sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>.
172 B<OpenSRF::DomainObject::oilsStatus>
176 $status = 'Connection Successful';
177 $statusCode = STATUS_OK;
179 #-------------------------------------------------------------------------------
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 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
189 OpenSRF::DomainObject::oilsContinueStatus
193 use OpenSRF::DomainObject::oilsResponse;
199 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
203 Implements the STATUS_CONTINUE message, informing the client that it should
204 continue to wait for a response to it's request.
208 B<OpenSRF::DomainObject::oilsStatus>
212 $status = 'Please hold. Creating response...';
213 $statusCode = STATUS_CONTINUE;
217 #-------------------------------------------------------------------------------
219 package OpenSRF::DomainObject::oilsResult;
220 use OpenSRF::DomainObject::oilsResponse qw/:status/;
221 use base 'OpenSRF::DomainObject::oilsResponse';
222 use vars qw/$status $statusCode/;
223 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
227 $statusCode = STATUS_OK;
231 OpenSRF::DomainObject::oilsResult
235 use OpenSRF::DomainObject::oilsResponse;
237 .... do stuff, create $object ...
239 my $res = OpenSRF::DomainObject::oilsResult->new;
241 $res->content($object)
243 $session->respond( $res );
247 This is the base class for encapuslating RESULT messages send from the server
248 to a client. It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and
249 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
253 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
257 Sets or gets the content of the response. This should be exactly one object
258 of (sub)type domainObject or domainObjectCollection.
268 $self->{content} = $val if (defined $val);
269 return $self->{content};
274 B<OpenSRF::DomainObject::oilsResponse>
280 #-------------------------------------------------------------------------------
282 package OpenSRF::DomainObject::oilsException;
283 use OpenSRF::DomainObject::oilsResponse qw/:status/;
285 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
286 use vars qw/$status $statusCode/;
288 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
292 return '<' . $self->statusCode . '> ' . $self->status;
297 return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
303 OpenSRF::DomainObject::oilsException
307 use OpenSRF::DomainObject::oilsResponse;
313 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
317 The base class for Exception messages sent between client and server. This
318 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
319 sets the default B<status> to C<Exception occured> and B<statusCode> to C<STATUS_BADREQUEST>.
323 $status = 'Exception occured';
324 $statusCode = STATUS_INTERNALSERVERERROR;
326 #-------------------------------------------------------------------------------
328 package OpenSRF::DomainObject::oilsConnectException;
329 use OpenSRF::DomainObject::oilsResponse qw/:status/;
331 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
332 use vars qw/$status $statusCode/;
333 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
337 OpenSRF::DomainObject::oilsConnectException
341 use OpenSRF::DomainObject::oilsResponse;
345 # something breaks while connecting.
347 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
351 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
352 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
353 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
357 B<OpenSRF::DomainObject::oilsException>
362 $status = 'Connect Request Failed';
363 $statusCode = STATUS_FORBIDDEN;
365 #-------------------------------------------------------------------------------
367 package OpenSRF::DomainObject::oilsMethodException;
368 use OpenSRF::DomainObject::oilsResponse qw/:status/;
369 use base 'OpenSRF::DomainObject::oilsException';
370 use vars qw/$status $statusCode/;
371 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
375 OpenSRF::DomainObject::oilsMehtodException
379 use OpenSRF::DomainObject::oilsResponse;
383 # something breaks while looking up or starting
386 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException );
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>.
396 B<OpenSRF::DomainObject::oilsException>
401 $status = 'A server error occured during method execution';
402 $statusCode = STATUS_INTERNALSERVERERROR;
404 # -------------------------------------------
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 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
412 $status = 'Internal Server Error';
413 $statusCode = STATUS_INTERNALSERVERERROR;
415 # -------------------------------------------
417 package OpenSRF::DomainObject::oilsBrokenSession;
418 use OpenSRF::DomainObject::oilsResponse qw/:status/;
420 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
421 use vars qw/$status $statusCode/;
422 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
423 $status = "Request on Disconnected Session";
424 $statusCode = STATUS_EXPFAILED;
426 #-------------------------------------------------------------------------------
428 package OpenSRF::DomainObject::oilsXMLParseError;
429 use OpenSRF::DomainObject::oilsResponse qw/:status/;
431 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
432 use vars qw/$status $statusCode/;
433 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
434 $status = "XML Parse Error";
435 $statusCode = STATUS_EXPFAILED;
437 #-------------------------------------------------------------------------------
439 package OpenSRF::DomainObject::oilsAuthException;
440 use OpenSRF::DomainObject::oilsResponse qw/:status/;
442 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
443 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
444 use vars qw/$status $statusCode/;
445 $status = "Authentication Failure";
446 $statusCode = STATUS_FORBIDDEN;