]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIPResponder.pm
Merge Alan's NCIP.pm and NCIPResponder.pm.
[working/NCIPServer.git] / lib / NCIPResponder.pm
1 package NCIPResponder;
2 use Modern::Perl;
3 use NCIP;
4
5 use FileHandle;
6
7 use Apache2::Const -compile => qw(OK :log :http :methods :cmd_how :override);
8 use Apache2::RequestRec ();
9 use Apache2::RequestIO ();
10 use NCIPServer::NCIP;
11
12 sub handler {
13     my $r = shift;
14
15     return Apache2::Const::HTTP_METHOD_NOT_ALLOWED unless $r->method_number eq Apache2::Const::M_POST;
16
17     my $NCIPConfigFile = $r->dir_config('NCIPConfigFile');
18
19     if (!defined($NCIPConfigFile)) {
20         die sprintf "error: There is no NCIPConfigFile defined\n";
21     } else {
22         if (! (-r $NCIPConfigFile)) {
23             die sprintf "error: NCIPConfigFile %s does not exist or is not readable\n", $NCIPConfigFile;
24         }
25     }
26
27     my $ncip = NCIP->new($NCIPConfigFile);
28
29     $r->content_type('text/html');
30     my $tmp_buf;
31     my $input_xml;
32
33     while ($r->read($tmp_buf, 1024)) {
34         $input_xml .= $tmp_buf;
35     }
36
37     my $response_xml = $ncip->process_request($input_xml);
38
39     $r->print($response_xml);
40     return Apache2::Const::OK;
41 }
42
43 1;