1 package OpenILS::DomainObject::oilsResponse;
2 use vars qw/@EXPORT_OK %EXPORT_TAGS/;
5 use base qw/OpenILS::DomainObject Exporter/;
6 use OpenILS::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 OpenILS::DomainObject::oilsResponse
33 use OpenILS::DomainObject::oilsResponse qw/:status/;
35 my $resp = OpenILS::DomainObject::oilsResponse->new;
37 $resp->status( 'a status message' );
39 $resp->statusCode( STATUS_CONTINUE );
41 $client->respond( $resp );
45 OpenILS::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 = 'OpenILS::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 OpenILS::DomainObject::oilsStatus;
102 use OpenILS::DomainObject::oilsResponse qw/:status/;
103 use base 'OpenILS::DomainObject::oilsResponse';
104 use vars qw/$status $statusCode/;
108 OpenILS::DomainObject::oilsException
112 use OpenILS::DomainObject::oilsResponse;
118 $client->status( OpenILS::DomainObject::oilsStatus->new );
122 The base class for Status messages sent between client and server. This
123 is implemented on top of the C<OpenILS::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 OpenILS::DomainObject::oilsConnectStatus;
132 use OpenILS::DomainObject::oilsResponse qw/:status/;
133 use base 'OpenILS::DomainObject::oilsStatus';
134 use vars qw/$status $statusCode/;
138 OpenILS::DomainObject::oilsConnectStatus
142 use OpenILS::DomainObject::oilsResponse;
148 $client->status( new OpenILS::DomainObject::oilsConnectStatus );
152 The class for Stati relating to the connection status of a session. This
153 is implemented on top of the C<OpenILS::DomainObject::oilsStatus> class, and
154 sets the default B<status> to C<Connection Successful> and B<statusCode> to C<STATUS_OK>.
158 B<OpenILS::DomainObject::oilsStatus>
162 $status = 'Connection Successful';
163 $statusCode = STATUS_OK;
169 #-------------------------------------------------------------------------------
173 package OpenILS::DomainObject::oilsResult;
174 use OpenILS::DomainObject::oilsResponse qw/:status/;
175 use OpenILS::DomainObject::oilsPrimitive;
176 use base 'OpenILS::DomainObject::oilsResponse';
177 use vars qw/$status $statusCode/;
181 $statusCode = STATUS_OK;
185 OpenILS::DomainObject::oilsResult
189 use OpenILS::DomainObject::oilsResponse;
191 .... do stuff, create $object ...
193 my $res = OpenILS::DomainObject::oilsResult->new;
195 $res->content($object)
197 $session->respond( $res );
201 This is the base class for encapuslating RESULT messages send from the server
202 to a client. It is a subclass of B<OpenILS::DomainObject::oilsResponse>, and
203 sets B<status> to C<OK> and B<statusCode> to C<STATUS_OK>.
207 =head2 OpenILS::DomainObject::oilsMessage->content( [$new_content] )
211 Sets or gets the content of the response. This should be exactly one object
212 of (sub)type domainObject or domainObjectCollection.
220 my $new_content = shift;
222 my ($content) = $self->getChildrenByTagName('oils:domainObject');
225 $new_content = OpenILS::DomainObject::oilsScalar->new( JSON->perl2JSON( $new_content ) );
227 $self->removeChild($content) if ($content);
228 $self->appendChild($new_content);
232 $new_content = $content if ($content);
234 return JSON->JSON2perl($new_content->textContent) if $new_content;
239 B<OpenILS::DomainObject::oilsResponse>
247 #-------------------------------------------------------------------------------
251 package OpenILS::DomainObject::oilsException;
252 use OpenILS::DomainObject::oilsResponse qw/:status/;
254 use base qw/OpenILS::EX OpenILS::DomainObject::oilsResponse/;
255 use vars qw/$status $statusCode/;
260 return '<' . $self->statusCode . '> ' . $self->status;
265 return $class->OpenILS::DomainObject::oilsResponse::new( @_ );
271 OpenILS::DomainObject::oilsException
275 use OpenILS::DomainObject::oilsResponse;
281 $client->send( 'ERROR', OpenILS::DomainObject::oilsException->new( status => "ARRRRRRG!" ) );
285 The base class for Exception messages sent between client and server. This
286 is implemented on top of the C<OpenILS::DomainObject::oilsResponse> class, and
287 sets the default B<status> to C<Exception occured> and B<statusCode> to C<STATUS_BADREQUEST>.
291 $status = 'Exception occured';
292 $statusCode = STATUS_INTERNALSERVERERROR;
294 package OpenILS::DomainObject::oilsConnectException;
295 use OpenILS::DomainObject::oilsResponse qw/:status/;
297 use base qw/OpenILS::DomainObject::oilsException OpenILS::EX::ERROR/;
298 use vars qw/$status $statusCode/;
302 OpenILS::DomainObject::oilsConnectException
306 use OpenILS::DomainObject::oilsResponse;
310 # something breaks while connecting.
312 $client->send( 'ERROR', new OpenILS::DomainObject::oilsConnectException );
316 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
317 is implemented on top of the C<OpenILS::DomainObject::oilsException> class, and
318 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_FORBIDDEN>.
322 B<OpenILS::DomainObject::oilsException>
327 $status = 'Connect Request Failed';
328 $statusCode = STATUS_FORBIDDEN;
330 package OpenILS::DomainObject::oilsMethodException;
331 use OpenILS::DomainObject::oilsResponse qw/:status/;
332 use base 'OpenILS::DomainObject::oilsException';
333 use vars qw/$status $statusCode/;
337 OpenILS::DomainObject::oilsMehtodException
341 use OpenILS::DomainObject::oilsResponse;
345 # something breaks while looking up or starting
348 $client->send( 'ERROR', new OpenILS::DomainObject::oilsMethodException );
352 The class for Exceptions that occur durring the B<CONNECT> phase of a session. This
353 is implemented on top of the C<OpenILS::DomainObject::oilsException> class, and
354 sets the default B<status> to C<Connect Request Failed> and B<statusCode> to C<STATUS_NOTFOUND>.
358 B<OpenILS::DomainObject::oilsException>
363 $status = 'Method not found';
364 $statusCode = STATUS_NOTFOUND;
366 # -------------------------------------------
368 package OpenILS::DomainObject::oilsServerError;
369 use OpenILS::DomainObject::oilsResponse qw/:status/;
370 use base 'OpenILS::DomainObject::oilsException';
371 use vars qw/$status $statusCode/;
373 $status = 'Internal Server Error';
374 $statusCode = STATUS_INTERNALSERVERERROR;
376 # -------------------------------------------
382 package OpenILS::DomainObject::oilsBrokenSession;
383 use OpenILS::DomainObject::oilsResponse qw/:status/;
385 use base qw/OpenILS::DomainObject::oilsException OpenILS::EX::ERROR/;
386 use vars qw/$status $statusCode/;
387 $status = "Request on Disconnected Session";
388 $statusCode = STATUS_EXPFAILED;
390 package OpenILS::DomainObject::oilsXMLParseError;
391 use OpenILS::DomainObject::oilsResponse qw/:status/;
393 use base qw/OpenILS::DomainObject::oilsException OpenILS::EX::ERROR/;
394 use vars qw/$status $statusCode/;
395 $status = "XML Parse Error";
396 $statusCode = STATUS_EXPFAILED;
398 package OpenILS::DomainObject::oilsAuthException;
399 use OpenILS::DomainObject::oilsResponse qw/:status/;
401 use base qw/OpenILS::DomainObject::oilsException OpenILS::EX::ERROR/;
402 use vars qw/$status $statusCode/;
403 $status = "Authentication Failure";
404 $statusCode = STATUS_FORBIDDEN;