1 package OpenSRF::DomainObject::oilsResponse;
2 use vars qw/@EXPORT_OK %EXPORT_TAGS/;
5 use base qw/OpenSRF::DomainObject Exporter/;
6 use OpenSRF::Utils::Logger qw/:level/;
9 @EXPORT_OK = qw/STATUS_CONTINUE STATUS_OK STATUS_ACCEPTED
10 STATUS_BADREQUEST STATUS_UNAUTHORIZED STATUS_FORBIDDEN
11 STATUS_NOTFOUND STATUS_NOTALLOWED STATUS_TIMEOUT
12 STATUS_INTERNALSERVERERROR STATUS_NOTIMPLEMENTED
13 STATUS_VERSIONNOTSUPPORTED STATUS_REDIRECTED
14 STATUS_EXPFAILED STATUS_COMPLETE/;
17 status => [ qw/STATUS_CONTINUE STATUS_OK STATUS_ACCEPTED
18 STATUS_BADREQUEST STATUS_UNAUTHORIZED STATUS_FORBIDDEN
19 STATUS_NOTFOUND STATUS_NOTALLOWED STATUS_TIMEOUT
20 STATUS_INTERNALSERVERERROR STATUS_NOTIMPLEMENTED
21 STATUS_VERSIONNOTSUPPORTED STATUS_REDIRECTED
22 STATUS_EXPFAILED STATUS_COMPLETE/ ],
29 OpenSRF::DomainObject::oilsResponse
33 use OpenSRF::DomainObject::oilsResponse qw/:status/;
35 my $resp = OpenSRF::DomainObject::oilsResponse->new;
37 $resp->status( 'a status message' );
39 $resp->statusCode( STATUS_CONTINUE );
41 $client->respond( $resp );
45 OpenSRF::DomainObject::oilsResponse implements the base class for all Application
46 layer messages send between the client and server.
50 sub STATUS_CONTINUE { return 100 }
52 sub STATUS_OK { return 200 }
53 sub STATUS_ACCEPTED { return 202 }
54 sub STATUS_COMPLETE { return 205 }
56 sub STATUS_REDIRECTED { return 307 }
58 sub STATUS_BADREQUEST { return 400 }
59 sub STATUS_UNAUTHORIZED { return 401 }
60 sub STATUS_FORBIDDEN { return 403 }
61 sub STATUS_NOTFOUND { return 404 }
62 sub STATUS_NOTALLOWED { return 405 }
63 sub STATUS_TIMEOUT { return 408 }
64 sub STATUS_EXPFAILED { return 417 }
66 sub STATUS_INTERNALSERVERERROR { return 500 }
67 sub STATUS_NOTIMPLEMENTED { return 501 }
68 sub STATUS_VERSIONNOTSUPPORTED { return 505 }
70 my $log = 'OpenSRF::Utils::Logger';
74 $class = ref($class) || $class;
76 my $default_status = eval "\$${class}::status";
77 my $default_statusCode = eval "\$${class}::statusCode";
79 my %args = ( status => $default_status,
80 statusCode => $default_statusCode,
83 return $class->SUPER::new( %args );
88 return $self->_attr_get_set( status => shift );
93 return $self->_attr_get_set( statusCode => shift );
97 #-------------------------------------------------------------------------------
101 package OpenSRF::DomainObject::oilsStatus;
102 use OpenSRF::DomainObject::oilsResponse qw/:status/;
103 use base 'OpenSRF::DomainObject::oilsResponse';
104 use vars qw/$status $statusCode/;
108 OpenSRF::DomainObject::oilsException
112 use OpenSRF::DomainObject::oilsResponse;
118 $client->status( OpenSRF::DomainObject::oilsStatus->new );
122 The base class for Status messages sent between client and server. This
123 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
124 sets the default B<status> to C<Status> and B<statusCode> to C<STATUS_OK>.
129 $statusCode = STATUS_OK;
131 package OpenSRF::DomainObject::oilsConnectStatus;
132 use OpenSRF::DomainObject::oilsResponse qw/:status/;
133 use base 'OpenSRF::DomainObject::oilsStatus';
134 use vars qw/$status $statusCode/;
138 OpenSRF::DomainObject::oilsConnectStatus
142 use OpenSRF::DomainObject::oilsResponse;
148 $client->status( new OpenSRF::DomainObject::oilsConnectStatus );
152 The class for Stati relating to the connection status of a session. This
153 is implemented on top of the C<OpenSRF::DomainObject::oilsStatus> class, and
154 sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>.
158 B<OpenSRF::DomainObject::oilsStatus>
162 $status = 'Connection Successful';
163 $statusCode = STATUS_OK;
168 package OpenSRF::DomainObject::oilsContinueStatus;
169 use OpenSRF::DomainObject::oilsResponse qw/:status/;
170 use base 'OpenSRF::DomainObject::oilsStatus';
171 use vars qw/$status $statusCode/;
175 OpenSRF::DomainObject::oilsContinueStatus
179 use OpenSRF::DomainObject::oilsResponse;
185 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
189 Implements the STATUS_CONTINUE message, informing the client that it should
190 continue to wait for a response to it's request.
194 B<OpenSRF::DomainObject::oilsStatus>
198 $status = 'Please hold. Creating response...';
199 $statusCode = STATUS_CONTINUE;
205 #-------------------------------------------------------------------------------
209 package OpenSRF::DomainObject::oilsResult;
210 use OpenSRF::DomainObject::oilsResponse qw/:status/;
211 use OpenSRF::DomainObject::oilsPrimitive;
212 use base 'OpenSRF::DomainObject::oilsResponse';
213 use vars qw/$status $statusCode/;
217 $statusCode = STATUS_OK;
221 OpenSRF::DomainObject::oilsResult
225 use OpenSRF::DomainObject::oilsResponse;
227 .... do stuff, create $object ...
229 my $res = OpenSRF::DomainObject::oilsResult->new;
231 $res->content($object)
233 $session->respond( $res );
237 This is the base class for encapuslating RESULT messages send from the server
238 to a client. It is a subclass of B<OpenSRF::DomainObject::oilsResponse>, and
239 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
243 =head2 OpenSRF::DomainObject::oilsMessage->content( [$new_content] )
247 Sets or gets the content of the response. This should be exactly one object
248 of (sub)type domainObject or domainObjectCollection.
256 my $new_content = shift;
258 my ($content) = $self->getChildrenByTagName('oils:domainObject');
260 if (defined $new_content) {
261 $new_content = OpenSRF::DomainObject::oilsScalar->new( JSON->perl2JSON( $new_content ) );
263 $self->removeChild($content) if ($content);
264 $self->appendChild($new_content);
268 $new_content = $content if ($content);
270 return JSON->JSON2perl($new_content->textContent) if $new_content;
275 B<OpenSRF::DomainObject::oilsResponse>
283 #-------------------------------------------------------------------------------
287 package OpenSRF::DomainObject::oilsException;
288 use OpenSRF::DomainObject::oilsResponse qw/:status/;
290 use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
291 use vars qw/$status $statusCode/;
296 return '<' . $self->statusCode . '> ' . $self->status;
301 return $class->OpenSRF::DomainObject::oilsResponse::new( @_ );
307 OpenSRF::DomainObject::oilsException
311 use OpenSRF::DomainObject::oilsResponse;
317 $client->send( 'ERROR', OpenSRF::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
321 The base class for Exception messages sent between client and server. This
322 is implemented on top of the C<OpenSRF::DomainObject::oilsResponse> class, and
323 sets the default B<status> to C<Exception occured> and B<statusCode> to C<STATUS_BADREQUEST>.
327 $status = 'Exception occured';
328 $statusCode = STATUS_INTERNALSERVERERROR;
330 package OpenSRF::DomainObject::oilsConnectException;
331 use OpenSRF::DomainObject::oilsResponse qw/:status/;
333 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
334 use vars qw/$status $statusCode/;
338 OpenSRF::DomainObject::oilsConnectException
342 use OpenSRF::DomainObject::oilsResponse;
346 # something breaks while connecting.
348 $client->send( 'ERROR', new OpenSRF::DomainObject::oilsConnectException );
352 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
353 is implemented on top of the C<OpenSRF::DomainObject::oilsException> class, and
354 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
358 B<OpenSRF::DomainObject::oilsException>
363 $status = 'Connect Request Failed';
364 $statusCode = STATUS_FORBIDDEN;
366 package OpenSRF::DomainObject::oilsMethodException;
367 use OpenSRF::DomainObject::oilsResponse qw/:status/;
368 use base 'OpenSRF::DomainObject::oilsException';
369 use vars qw/$status $statusCode/;
373 OpenSRF::DomainObject::oilsMehtodException
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 durring 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 = 'Method not found';
400 $statusCode = STATUS_NOTFOUND;
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/;
409 $status = 'Internal Server Error';
410 $statusCode = STATUS_INTERNALSERVERERROR;
412 # -------------------------------------------
418 package OpenSRF::DomainObject::oilsBrokenSession;
419 use OpenSRF::DomainObject::oilsResponse qw/:status/;
421 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
422 use vars qw/$status $statusCode/;
423 $status = "Request on Disconnected Session";
424 $statusCode = STATUS_EXPFAILED;
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 $status = "XML Parse Error";
432 $statusCode = STATUS_EXPFAILED;
434 package OpenSRF::DomainObject::oilsAuthException;
435 use OpenSRF::DomainObject::oilsResponse qw/:status/;
437 use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
438 use vars qw/$status $statusCode/;
439 $status = "Authentication Failure";
440 $statusCode = STATUS_FORBIDDEN;