Back to index

nordugrid-arc-nox  1.1.0~rc6
http_test.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("http://grid.uio.no/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 = ".libs";
00027   Arc::XMLNode plg1 = cfg.NewChild("Plugins");
00028   Arc::XMLNode mcctcp = plg1.NewChild("Name");
00029   mcctcp = "mcctcp";
00030   Arc::XMLNode plg2 = cfg.NewChild("Plugins");
00031   Arc::XMLNode mcchttp = plg2.NewChild("Name");
00032   mcchttp = "mcchttp";
00033   Arc::XMLNode chn = cfg.NewChild("Chain");
00034 
00035   Arc::XMLNode tcp = chn.NewChild("Component");
00036   Arc::XMLNode tcpname = tcp.NewAttribute("name");
00037   tcpname = "tcp.client";
00038   Arc::XMLNode tcpid = tcp.NewAttribute("id");
00039   tcpid = "tcp";
00040   Arc::XMLNode tcpcnt = tcp.NewChild("Connect");
00041   Arc::XMLNode tcphost = tcpcnt.NewChild("Host");
00042   tcphost = url.Host();
00043   Arc::XMLNode tcpport = tcpcnt.NewChild("Port");
00044   tcpport = Arc::tostring(url.Port());
00045 
00046   Arc::XMLNode http = chn.NewChild("Component");
00047   Arc::XMLNode httpname = http.NewAttribute("name");
00048   httpname = "http.client";
00049   Arc::XMLNode httpid = http.NewAttribute("id");
00050   httpid = "http";
00051   Arc::XMLNode httpentry = http.NewAttribute("entry");
00052   httpentry = "http";
00053   Arc::XMLNode httpnext = http.NewChild("next");
00054   Arc::XMLNode httpnextid = httpnext.NewAttribute("id");
00055   httpnextid = "tcp";
00056   Arc::XMLNode httpmeth = http.NewChild("Method");
00057   httpmeth = "GET";
00058   Arc::XMLNode httpep = http.NewChild("Endpoint");
00059   httpep = url.str();
00060 
00061   std::cout<<"------ Configuration ------"<<std::endl;
00062   std::string cfgstr;
00063   c.GetXML(cfgstr);
00064   std::cerr << cfgstr << std::endl;
00065 
00066   Arc::Loader l(c);
00067 
00068   Arc::Message request;
00069   Arc::PayloadRaw msg;
00070   Arc::MessageAttributes attributes;
00071   Arc::MessageContext context;
00072   request.Payload(&msg);
00073   request.Attributes(&attributes);
00074   request.Context(&context);
00075   Arc::Message response;
00076 
00078 
00079   std::cout<<"*** RESPONSE ***"<<std::endl;
00080   Arc::PayloadRaw& payload =
00081     dynamic_cast<Arc::PayloadRaw&>(*response.Payload());
00082   for(int n = 0;n<payload.Size();++n) std::cout<<payload[n];
00083   std::cout<<std::endl;
00084 }
00085 
00086 int main(void) {
00087   test1();
00088   return 0;
00089 }