1 package OpenSRF::DomainObject::oilsResponse;
2 use vars qw/@EXPORT_OK %EXPORT_TAGS/;
6 use OpenSRF::Utils::Logger qw/:level/;
8 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 JSON->perl2prettyJSON($self) if ($pretty);
78 return JSON->perl2JSON($self);
83 $name = 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};
110 #-------------------------------------------------------------------------------
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 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 package OpenSRF::DomainObject::oilsConnectStatus;
146 use OpenSRF::DomainObject::oilsResponse qw/:status/;
147 use base 'OpenSRF::DomainObject::oilsStatus';
148 use vars qw/$status $statusCode/;
149 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;
183 package OpenSRF::DomainObject::oilsContinueStatus;
184 use OpenSRF::DomainObject::oilsResponse qw/:status/;
185 use base 'OpenSRF::DomainObject::oilsStatus';
186 use vars qw/$status $statusCode/;
187 JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
191 OpenSRF::DomainObject::oilsContinueStatus
195 use OpenSRF::DomainObject::oilsResponse;
201 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
205 Implements the STATUS_CONTINUE message, informing the client that it should
206 continue to wait for a response to it's request.
210 B<OpenSRF::DomainObject::oilsStatus>
214 $status = 'Please hold. Creating response...';
215 $statusCode = STATUS_CONTINUE;
221 #-------------------------------------------------------------------------------
225 package OpenSRF::DomainObject::oilsResult;
226 use OpenSRF::DomainObject::oilsResponse qw/:status/;
227 use OpenSRF::DomainObject::oilsPrimitive;
228 use base 'OpenSRF::DomainObject::oilsResponse';
229 use vars qw/$status $statusCode/;
230 JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
234 $statusCode = STATUS_OK;
238 OpenSRF::DomainObject::oilsResult
242 use OpenSRF::DomainObject::oilsResponse;
244 .... do stuff, create $object ...
246 my $res = OpenSRF::DomainObject::oilsResult->new;
248 $res->content($object)
250 $session->respond( $res );
254 This is the base class for encapuslating RESULT messages send from the server
255 to a client. It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and
256 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
260 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
264 Sets or gets the content of the response. This should be exactly one object
265 of (sub)type domainObject or domainObjectCollection.
275 $self->{content} = $val if (defined $val);
276 return $self->{content};
281 B<OpenSRF::DomainObject::oilsResponse>
289 #-------------------------------------------------------------------------------
293 package OpenSRF::DomainObject::oilsException;
294 use OpenSRF::DomainObject::oilsResponse qw/:status/;
296 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
297 use vars qw/$status $statusCode/;
299 JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
303 return '<' . $self->statusCode . '> ' . $self->status;
308 return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
314 OpenSRF::DomainObject::oilsException
318 use OpenSRF::DomainObject::oilsResponse;
324 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
328 The base class for Exception messages sent between client and server. This
329 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
330 sets the default B<status> to C<Exception occured> and B<statusCode> to C<STATUS_BADREQUEST>.
334 $status = 'Exception occured';
335 $statusCode = STATUS_INTERNALSERVERERROR;
337 package OpenSRF::DomainObject::oilsConnectException;
338 use OpenSRF::DomainObject::oilsResponse qw/:status/;
340 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
341 use vars qw/$status $statusCode/;
342 JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
346 OpenSRF::DomainObject::oilsConnectException
350 use OpenSRF::DomainObject::oilsResponse;
354 # something breaks while connecting.
356 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
360 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
361 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
362 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
366 B<OpenSRF::DomainObject::oilsException>
371 $status = 'Connect Request Failed';
372 $statusCode = STATUS_FORBIDDEN;
374 package OpenSRF::DomainObject::oilsMethodException;
375 use OpenSRF::DomainObject::oilsResponse qw/:status/;
376 use base 'OpenSRF::DomainObject::oilsException';
377 use vars qw/$status $statusCode/;
378 JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
382 OpenSRF::DomainObject::oilsMehtodException
386 use OpenSRF::DomainObject::oilsResponse;
390 # something breaks while looking up or starting
393 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException );
397 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
398 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
399 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>.
403 B<OpenSRF::DomainObject::oilsException>
408 $status = 'Method not found';
409 $statusCode = STATUS_NOTFOUND;
411 # -------------------------------------------
413 package OpenSRF::DomainObject::oilsServerError;
414 use OpenSRF::DomainObject::oilsResponse qw/:status/;
415 use base 'OpenSRF::DomainObject::oilsException';
416 use vars qw/$status $statusCode/;
417 JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
419 $status = 'Internal Server Error';
420 $statusCode = STATUS_INTERNALSERVERERROR;
422 # -------------------------------------------
428 package OpenSRF::DomainObject::oilsBrokenSession;
429 use OpenSRF::DomainObject::oilsResponse qw/:status/;
431 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
432 use vars qw/$status $statusCode/;
433 JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
434 $status = "Request on Disconnected Session";
435 $statusCode = STATUS_EXPFAILED;
437 package OpenSRF::DomainObject::oilsXMLParseError;
438 use OpenSRF::DomainObject::oilsResponse qw/:status/;
440 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
441 use vars qw/$status $statusCode/;
442 JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
443 $status = "XML Parse Error";
444 $statusCode = STATUS_EXPFAILED;
446 package OpenSRF::DomainObject::oilsAuthException;
447 use OpenSRF::DomainObject::oilsResponse qw/:status/;
449 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
450 JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
451 use vars qw/$status $statusCode/;
452 $status = "Authentication Failure";
453 $statusCode = STATUS_FORBIDDEN;