Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/Logger.h"
#include "MantidDataHandling/SNSDataArchive.h"
#include "MantidAPI/ArchiveSearchFactory.h"
#include <Poco/File.h>
#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/Context.h>
#include <Poco/Net/NetException.h>
#include <Poco/URI.h>
#include <boost/algorithm/string.hpp>
#include <iostream>
using Poco::Net::HTTPSClientSession;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;
using Poco::Net::HTTPMessage;
using Poco::Net::ConnectionRefusedException;
using Poco::URI;
namespace Mantid
{
namespace DataHandling
{
// Get a reference to the logger
Mantid::Kernel::Logger & SNSDataArchive::g_log = Mantid::Kernel::Logger::get("SNSDataArchive");
DECLARE_ARCHIVESEARCH(SNSDataArchive,SNSDataSearch);
/**
* Calls a web service to get a full path to a file
* @param fName :: The file name.
* @return The path to the file or empty string in case of error.
*/
std::string SNSDataArchive::getPath(const std::string& fName) const
{
std::string baseURL(
"https://prod.sns.gov/sns-icat-ws/icat-location/fileName/");
std::string URL(baseURL + fName);
g_log.debug() << "SNSDataArchive URL = \'" << URL << "\'\n";
std::string wsResult = "";
//#ifdef _WIN32
// // Return an empty string
//#else
//
//#endif
Poco::URI uri(URL);
std::string path(uri.getPathAndQuery());
Poco::Net::Context::Ptr context = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "",
"", Poco::Net::Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
try { // workaround for ubuntu 11.04
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context); // this line is broken
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
char buff[300];
std::streamsize n;
do
{
rs.read(&buff[0], 300);
n = rs.gcount();
wsResult.append(&buff[0], n);
} while (n == 300);
} catch (ConnectionRefusedException &) {
g_log.information() << "Connection refused by prod.sns.gov\n";
throw;
} catch(Poco::IOException &e) {
g_log.debug() << e.name() << " thrown.\n";
g_log.information() << e.message() << "\n";