Back to index

nordugrid-arc-nox  1.1.0~rc6
http_test_withtls.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <string>
00006 #include <iostream>
00007 
00008 #include <arc/loader/Loader.h>
00009 #include <arc/message/PayloadRaw.h>
00010 #include <arc/ArcConfig.h>
00011 #include <arc/StringConv.h>
00012 #include <arc/URL.h>
00013 
00014 void test1(void) {
00015   std::cout<<"------ Testing simple file download ------"<<std::endl;
00016 
00017   Arc::URL url("https://download.nordugrid.org/index.html");
00018 
00019   Arc::NS ns;
00020   Arc::Config c(ns);
00021   Arc::XMLNode cfg = c;
00022   Arc::XMLNode mgr = cfg.NewChild("ModuleManager");
00023   Arc::XMLNode pth1 = mgr.NewChild("Path");
00024   pth1 = "../tcp/.libs";
00025   Arc::XMLNode pth2 = mgr.NewChild("Path");
00026   pth2 = "../tls/.libs";
00027   Arc::XMLNode pth3 = mgr.NewChild("Path");
00028   pth3 = ".libs";
00029   Arc::XMLNode plg1 = cfg.NewChild("Plugins");
00030   Arc::XMLNode mcctcp = plg1.NewChild("Name");
00031   mcctcp = "mcctcp";
00032   Arc::XMLNode plg2 = cfg.NewChild("Plugins");
00033   Arc::XMLNode mcctls = plg2.NewChild("Name");
00034   mcctls = "mcctls";
00035   Arc::XMLNode plg3 = cfg.NewChild("Plugins");
00036   Arc::XMLNode mcchttp = plg3.NewChild("Name");
00037   mcchttp = "mcchttp";
00038   Arc::XMLNode chn = cfg.NewChild("Chain");
00039 
00040   Arc::XMLNode tcp = chn.NewChild("Component");
00041   Arc::XMLNode tcpname = tcp.NewAttribute("name");
00042   tcpname = "tcp.client";
00043   Arc::XMLNode tcpid = tcp.NewAttribute("id");
00044   tcpid = "tcp";
00045   Arc::XMLNode tcpcnt = tcp.NewChild("Connect");
00046   Arc::XMLNode tcphost = tcpcnt.NewChild("Host");
00047   tcphost = url.Host();
00048   Arc::XMLNode tcpport = tcpcnt.NewChild("Port");
00049   tcpport = Arc::tostring(url.Port());
00050 
00051   Arc::XMLNode tls = chn.NewChild("Component");
00052   Arc::XMLNode tlsname = tls.NewAttribute("name");
00053   tlsname = "tls.client";
00054   Arc::XMLNode tlsid = tls.NewAttribute("id");
00055   tlsid = "tls";
00056   Arc::XMLNode tlsnext = tls.NewChild("next");
00057   Arc::XMLNode tlsnextid = tlsnext.NewAttribute("id");
00058   tlsnextid = "tcp";
00059 
00060   Arc::XMLNode http = chn.NewChild("Component");
00061   Arc::XMLNode httpname = http.NewAttribute("name");
00062   httpname = "http.client";
00063   Arc::XMLNode httpid = http.NewAttribute("id");
00064   httpid = "http";
00065   Arc::XMLNode httpentry = http.NewAttribute("entry");
00066   httpentry = "http";
00067   Arc::XMLNode httpnext = http.NewChild("next");
00068   Arc::XMLNode httpnextid = httpnext.NewAttribute("id");
00069   httpnextid = "tls";
00070   Arc::XMLNode httpmeth = http.NewChild("Method");
00071   httpmeth = "GET";
00072   Arc::XMLNode httpep = http.NewChild("Endpoint");
00073   httpep = url.str();
00074 
00075   std::cout<<"------ Configuration ------"<<std::endl;
00076   std::string cfgstr;
00077   c.GetXML(cfgstr);
00078   std::cerr << cfgstr << std::endl;
00079 
00080   Arc::Loader l(c);
00081 
00082   Arc::Message request;
00083   Arc::PayloadRaw msg;
00084   Arc::MessageAttributes attributes;
00085   Arc::MessageContext context;
00086   request.Payload(&msg);
00087   request.Attributes(&attributes);
00088   request.Context(&context);
00089   Arc::Message response;
00090 
00092 
00093   std::cout<<"*** RESPONSE ***"<<std::endl;
00094   Arc::PayloadRaw& payload =
00095     dynamic_cast<Arc::PayloadRaw&>(*response.Payload());
00096   for(int n = 0;n<payload.Size();++n) std::cout<<payload[n];
00097   std::cout<<std::endl;
00098 }
00099 
00100 int main(void) {
00101   test1();
00102   return 0;
00103 }