1 package OpenILS::WWW::AddedContent;
2 use strict; use warnings;
4 use lib qw(/usr/lib/perl5/Bundle/);
9 use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
10 use APR::Const -compile => qw(:error SUCCESS);
11 use Apache2::RequestRec ();
12 use Apache2::RequestIO ();
13 use Apache2::RequestUtil;
16 use OpenSRF::EX qw(:try);
17 use OpenSRF::Utils::Cache;
19 use OpenSRF::Utils::Logger qw/$logger/;
23 # set the bootstrap config when this module is loaded
37 OpenSRF::System->bootstrap_client( config_file => $bs_config );
39 my $sclient = OpenSRF::Utils::SettingsClient->new();
40 my $ac_data = $sclient->config_value("added_content");
42 return unless $ac_data;
44 $cache = OpenSRF::Utils::Cache->new;
46 my $ac_handler = $ac_data->{module};
47 $net_timeout = $ac_data->{timeout} || 3;
49 return unless $ac_handler;
51 $logger->debug("Attempting to load Added Content handler: $ac_handler");
53 eval "use $ac_handler";
56 $logger->error("Unable to load Added Content handler [$ac_handler]: $@");
60 $handler = $ac_handler->new($ac_data);
61 $logger->debug("added content loaded handler: $handler");
69 my $path = $r->path_info;
71 child_init() unless $handler; # why isn't apache doing this for us?
72 return Apache2::Const::NOT_FOUND unless $handler;
74 # if this memcache key is set, added content lookups are disabled
75 if( $cache->get_cache('ac.no_lookup') ) {
76 $logger->info("added content lookup disabled");
77 return Apache2::Const::NOT_FOUND;
81 my( undef, $data, $format, $key ) = split(/\//, $r->path_info);
85 my $method = "${data}_${format}";
88 $success = $handler->$method($key);
91 $logger->error("added content handler failed: $method($key) => $err");
94 return Apache2::Const::NOT_FOUND if $err or !$success;
95 return Apache2::Const::OK;
102 my( $self, $url ) = @_;
103 $logger->info("added content getting [timeout=$net_timeout] URL = $url");
104 my $agent = LWP::UserAgent->new(timeout => $net_timeout);
105 my $res = $agent->get($url);
106 die "added content request failed: " . $res->status_line ."\n" unless $res->is_success;
107 return $res->content;