19 #include <metaproxy/xmlutil.hpp>
22 #include <yaz/wrbuf.h>
25 #include <metaproxy/util.hpp>
31 std::string url_template,
const std::string &db,
32 const std::string &query,
33 const std::string &realm,
34 const std::string &proxy,
43 found = url_template.find(
"%query");
44 if (found != std::string::npos)
45 url_template.replace(found, 6, mp::util::uri_encode(query));
47 found = url_template.find(
"%db");
48 if (found != std::string::npos)
49 url_template.replace(found, 3, mp::util::uri_encode(db));
51 found = url_template.find(
"%realm");
52 if (found != std::string::npos)
53 url_template.replace(found, 6, mp::util::uri_encode(realm));
55 Z_HTTP_Header *http_headers = 0;
58 z_HTTP_header_add(odr, &http_headers,
"Accept",
"application/xml");
60 yaz_url_t url_p = yaz_url_create();
62 yaz_url_set_proxy(url_p, proxy.c_str());
64 Z_HTTP_Response *http_response = yaz_url_exec(url_p,
71 if (http_response && http_response->code == 200 &&
72 http_response->content_buf)
74 doc = xmlParseMemory(http_response->content_buf,
75 http_response->content_len);
77 package.log(
"zoom", YLOG_LOG,
"Torus: %s OK",
78 url_template.c_str());
81 package.log(
"zoom", YLOG_WARN,
"Torus: %s FAIL. XML parse failed",
82 url_template.c_str());
83 addinfo =
"Torus: XML parse failed";
91 package.log(
"zoom", YLOG_WARN,
"Torus: %s FAIL. HTTP code %d",
92 url_template.c_str(), http_response->code);
93 addinfo += std::string(http_response->content_buf,
94 http_response->content_len);
98 addinfo +=
"unknown error";
99 package.log(
"zoom", YLOG_WARN,
"Torus: %s FAIL. No HTTP response",
100 url_template.c_str());
104 if (http_response && http_response->content_buf)
106 package.log(
"zoom", YLOG_LOG,
"HTTP content");
107 package.log_write(http_response->content_buf,
108 http_response->content_len);
110 yaz_url_destroy(url_p);