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';
76 return OpenSRF::Utils::JSON->perl2JSON($self);
81 $class = ref($class) || $class;
83 my $default_status = eval "\$${class}::status";
84 my $default_statusCode = eval "\$${class}::statusCode";
86 my %args = ( status => $default_status,
87 statusCode => $default_statusCode,
90 return bless( \%args => $class );
96 $self->{status} = $val if (defined $val);
97 return $self->{status};
103 $self->{statusCode} = $val if (defined $val);
104 return $self->{statusCode};
107 #-------------------------------------------------------------------------------
109 package OpenSRF::DomainObject::oilsStatus;
110 use OpenSRF::DomainObject::oilsResponse qw/:status/;
111 use base 'OpenSRF::DomainObject::oilsResponse';
112 use vars qw/$status $statusCode/;
113 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' );
117 OpenSRF::DomainObject::oilsException
121 use OpenSRF::DomainObject::oilsResponse;
127 $client->status( OpenSRF::DomainObject::oilsStatus->new );
131 The base class for Status messages sent between client and server. This
132 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
133 sets the default B<status> to C<Status> and B<statusCode> to C<STATUS_OK>.
138 $statusCode = STATUS_OK;
140 #-------------------------------------------------------------------------------
142 package OpenSRF::DomainObject::oilsConnectStatus;
143 use OpenSRF::DomainObject::oilsResponse qw/:status/;
144 use base 'OpenSRF::DomainObject::oilsStatus';
145 use vars qw/$status $statusCode/;
146 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' );
150 OpenSRF::DomainObject::oilsConnectStatus
154 use OpenSRF::DomainObject::oilsResponse;
160 $client->status( new OpenSRF::DomainObject::oilsConnectStatus );
164 The class for Stati relating to the connection status of a session. This
165 is implemented on top of the C<OpenSRF::DomainObject::oilsStatus> class, and
166 sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>.
170 B<OpenSRF::DomainObject::oilsStatus>
174 $status = 'Connection Successful';
175 $statusCode = STATUS_OK;
177 #-------------------------------------------------------------------------------
179 package OpenSRF::DomainObject::oilsContinueStatus;
180 use OpenSRF::DomainObject::oilsResponse qw/:status/;
181 use base 'OpenSRF::DomainObject::oilsStatus';
182 use vars qw/$status $statusCode/;
183 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
187 OpenSRF::DomainObject::oilsContinueStatus
191 use OpenSRF::DomainObject::oilsResponse;
197 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
201 Implements the STATUS_CONTINUE message, informing the client that it should
202 continue to wait for a response to its request.
206 B<OpenSRF::DomainObject::oilsStatus>
210 $status = 'Please hold. Creating response...';
211 $statusCode = STATUS_CONTINUE;
215 #-------------------------------------------------------------------------------
217 package OpenSRF::DomainObject::oilsResult;
218 use OpenSRF::DomainObject::oilsResponse qw/:status/;
219 use base 'OpenSRF::DomainObject::oilsResponse';
220 use vars qw/$status $statusCode/;
221 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
225 $statusCode = STATUS_OK;
229 OpenSRF::DomainObject::oilsResult
233 use OpenSRF::DomainObject::oilsResponse;
235 .... do stuff, create $object ...
237 my $res = OpenSRF::DomainObject::oilsResult->new;
239 $res->content($object)
241 $session->respond( $res );
245 This is the base class for encapuslating RESULT messages send from the server
246 to a client. It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and
247 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
251 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
255 Sets or gets the content of the response. This should be exactly one object
256 of (sub)type domainObject or domainObjectCollection.
266 $self->{content} = $val if (defined $val);
267 return $self->{content};
272 B<OpenSRF::DomainObject::oilsResponse>
278 #-------------------------------------------------------------------------------
280 package OpenSRF::DomainObject::oilsException;
281 use OpenSRF::DomainObject::oilsResponse qw/:status/;
283 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
284 use vars qw/$status $statusCode/;
286 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
290 return '<' . $self->statusCode . '> ' . $self->status;
295 return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
301 OpenSRF::DomainObject::oilsException
305 use OpenSRF::DomainObject::oilsResponse;
311 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
315 The base class for Exception messages sent between client and server. This
316 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
317 sets the default B<status> to C<Exception occurred> and B<statusCode> to C<STATUS_BADREQUEST>.
321 $status = 'Exception occurred';
322 $statusCode = STATUS_INTERNALSERVERERROR;
324 #-------------------------------------------------------------------------------
326 package OpenSRF::DomainObject::oilsConnectException;
327 use OpenSRF::DomainObject::oilsResponse qw/:status/;
329 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
330 use vars qw/$status $statusCode/;
331 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
335 OpenSRF::DomainObject::oilsConnectException
339 use OpenSRF::DomainObject::oilsResponse;
343 # something breaks while connecting.
345 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
349 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
350 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
351 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
355 B<OpenSRF::DomainObject::oilsException>
360 $status = 'Connect Request Failed';
361 $statusCode = STATUS_FORBIDDEN;
363 #-------------------------------------------------------------------------------
365 package OpenSRF::DomainObject::oilsMethodException;
366 use OpenSRF::DomainObject::oilsResponse qw/:status/;
367 use base 'OpenSRF::DomainObject::oilsException';
368 use vars qw/$status $statusCode/;
369 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
373 OpenSRF::DomainObject::oilsMethodException
377 use OpenSRF::DomainObject::oilsResponse;
381 # something breaks while looking up or starting
384 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsMethodException );
388 The class for Exceptions that occur during the B<CONNECT> phase of a session. This
389 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
390 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>.
394 B<OpenSRF::DomainObject::oilsException>
399 $status = 'A server error occurred during method execution';
400 $statusCode = STATUS_INTERNALSERVERERROR;
402 # -------------------------------------------
404 package OpenSRF::DomainObject::oilsServerError;
405 use OpenSRF::DomainObject::oilsResponse qw/:status/;
406 use base 'OpenSRF::DomainObject::oilsException';
407 use vars qw/$status $statusCode/;
408 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
410 $status = 'Internal Server Error';
411 $statusCode = STATUS_INTERNALSERVERERROR;
413 # -------------------------------------------
415 package OpenSRF::DomainObject::oilsBrokenSession;
416 use OpenSRF::DomainObject::oilsResponse qw/:status/;
418 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
419 use vars qw/$status $statusCode/;
420 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
421 $status = "Request on Disconnected Session";
422 $statusCode = STATUS_EXPFAILED;
424 #-------------------------------------------------------------------------------
426 package OpenSRF::DomainObject::oilsXMLParseError;
427 use OpenSRF::DomainObject::oilsResponse qw/:status/;
429 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
430 use vars qw/$status $statusCode/;
431 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
432 $status = "XML Parse Error";
433 $statusCode = STATUS_EXPFAILED;
435 #-------------------------------------------------------------------------------
437 package OpenSRF::DomainObject::oilsAuthException;
438 use OpenSRF::DomainObject::oilsResponse qw/:status/;
440 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
441 OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
442 use vars qw/$status $statusCode/;
443 $status = "Authentication Failure";
444 $statusCode = STATUS_FORBIDDEN;