void test1(void) { std::cout<<"------ Testing simple file download ------"<<std::endl; Arc::URL url("http://grid.uio.no/index.html"); Arc::NS ns; Arc::Config c(ns); Arc::XMLNode cfg = c; Arc::XMLNode mgr = cfg.NewChild("ModuleManager"); Arc::XMLNode pth1 = mgr.NewChild("Path"); pth1 = "../tcp/.libs"; Arc::XMLNode pth2 = mgr.NewChild("Path"); pth2 = ".libs"; Arc::XMLNode plg1 = cfg.NewChild("Plugins"); Arc::XMLNode mcctcp = plg1.NewChild("Name"); mcctcp = "mcctcp"; Arc::XMLNode plg2 = cfg.NewChild("Plugins"); Arc::XMLNode mcchttp = plg2.NewChild("Name"); mcchttp = "mcchttp"; Arc::XMLNode chn = cfg.NewChild("Chain"); Arc::XMLNode tcp = chn.NewChild("Component"); Arc::XMLNode tcpname = tcp.NewAttribute("name"); tcpname = "tcp.client"; Arc::XMLNode tcpid = tcp.NewAttribute("id"); tcpid = "tcp"; Arc::XMLNode tcpcnt = tcp.NewChild("Connect"); Arc::XMLNode tcphost = tcpcnt.NewChild("Host"); tcphost = url.Host(); Arc::XMLNode tcpport = tcpcnt.NewChild("Port"); tcpport = Arc::tostring(url.Port()); Arc::XMLNode http = chn.NewChild("Component"); Arc::XMLNode httpname = http.NewAttribute("name"); httpname = "http.client"; Arc::XMLNode httpid = http.NewAttribute("id"); httpid = "http"; Arc::XMLNode httpentry = http.NewAttribute("entry"); httpentry = "http"; Arc::XMLNode httpnext = http.NewChild("next"); Arc::XMLNode httpnextid = httpnext.NewAttribute("id"); httpnextid = "tcp"; Arc::XMLNode httpmeth = http.NewChild("Method"); httpmeth = "GET"; Arc::XMLNode httpep = http.NewChild("Endpoint"); httpep = url.str(); std::cout<<"------ Configuration ------"<<std::endl; std::string cfgstr; c.GetXML(cfgstr); std::cerr << cfgstr << std::endl; Arc::Loader l(c); Arc::Message request; Arc::PayloadRaw msg; Arc::MessageAttributes attributes; Arc::MessageContext context; request.Payload(&msg); request.Attributes(&attributes); request.Context(&context); Arc::Message response; //!! l["http"]->process(request,response); std::cout<<"*** RESPONSE ***"<<std::endl; Arc::PayloadRaw& payload = dynamic_cast<Arc::PayloadRaw&>(*response.Payload()); for(int n = 0;n<payload.Size();++n) std::cout<<payload[n]; std::cout<<std::endl; }
int main(void) { signal(SIGTTOU,SIG_IGN); signal(SIGTTIN,SIG_IGN); Arc::Logger logger(Arc::Logger::rootLogger, "Test"); Arc::LogStream logcerr(std::cerr); Arc::Logger::rootLogger.addDestination(logcerr); logger.msg(Arc::INFO, "Creating client side chain"); // Create client chain Arc::XMLNode client_doc("\ <ArcConfig\ xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\"\ xmlns:tcp=\"http://www.nordugrid.org/schemas/ArcMCCTCP/2007\">\ <ModuleManager>\ <Path>.libs/</Path>\ <Path>../../hed/mcc/http/.libs/</Path>\ <Path>../../hed/mcc/soap/.libs/</Path>\ <Path>../../hed/mcc/tls/.libs/</Path>\ <Path>../../hed/mcc/tcp/.libs/</Path>\ <Path>../../hed/shc/.libs/</Path>\ </ModuleManager>\ <Plugins><Name>mcctcp</Name></Plugins>\ <Plugins><Name>mcctls</Name></Plugins>\ <Plugins><Name>mcchttp</Name></Plugins>\ <Plugins><Name>mccsoap</Name></Plugins>\ <Plugins><Name>arcshc</Name></Plugins>\ <Chain>\ <Component name='tcp.client' id='tcp'><tcp:Connect><tcp:Host>127.0.0.1</tcp:Host><tcp:Port>50000</tcp:Port></tcp:Connect></Component>\ <Component name='tls.client' id='tls'><next id='tcp'/>\ <!--For proxy certificate, KeyPath and CertificatePath are supposed to be the same-->\ <KeyPath>./testkey-nopass.pem</KeyPath>\ <CertificatePath>./testcert.pem</CertificatePath>\ <CACertificatePath>./testcacert.pem</CACertificatePath>\ </Component>\ <Component name='http.client' id='http'><next id='tcp'/>\ <Method>POST</Method>\ <Endpoint>/Echo</Endpoint>\ </Component>\ <Component name='soap.client' id='soap' entry='soap'>\ <next id='http'/>\ </Component>\ </Chain>\ </ArcConfig>"); Arc::Config client_config(client_doc); if(!client_config) { logger.msg(Arc::ERROR, "Failed to load client configuration"); return -1; }; Arc::MCCLoader client_loader(client_config); logger.msg(Arc::INFO, "Client side MCCs are loaded"); Arc::MCC* client_entry = client_loader["soap"]; if(!client_entry) { logger.msg(Arc::ERROR, "Client chain does not have entry point"); return -1; }; // for (int i = 0; i < 10; i++) { // Create and send echo request logger.msg(Arc::INFO, "Creating and sending request"); Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo"; Arc::PayloadSOAP req(echo_ns); req.NewChild("echo").NewChild("say")="HELLO"; Arc::Message reqmsg; Arc::Message repmsg; reqmsg.Payload(&req); // It is a responsibility of code initiating first Message to // provide Context and Attributes as well. Arc::MessageAttributes attributes_req; Arc::MessageAttributes attributes_rep; Arc::MessageContext context; reqmsg.Attributes(&attributes_req); reqmsg.Context(&context); repmsg.Attributes(&attributes_rep); repmsg.Context(&context); Arc::MCC_Status status = client_entry->process(reqmsg,repmsg); if(!status) { logger.msg(Arc::ERROR, "Request failed"); std::cerr << "Status: " << std::string(status) << std::endl; return -1; }; Arc::PayloadSOAP* resp = NULL; if(repmsg.Payload() == NULL) { logger.msg(Arc::ERROR, "There is no response"); return -1; }; try { resp = dynamic_cast<Arc::PayloadSOAP*>(repmsg.Payload()); } catch(std::exception&) { }; if(resp == NULL) { logger.msg(Arc::ERROR, "Response is not SOAP"); return -1; }; std::string xml; resp->GetXML(xml); std::cout << "XML: "<< xml << std::endl; std::cout << "Response: " << (std::string)((*resp)["echoResponse"]["hear"]) << std::endl; //} return 0; }