Back to index

nordugrid-arc-nox  1.1.0~rc6
test_client.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <iostream>
00006 #include <signal.h>
00007 
00008 #include <arc/ArcConfig.h>
00009 #include <arc/Logger.h>
00010 #include <arc/message/SOAPEnvelope.h>
00011 #include <arc/message/PayloadSOAP.h>
00012 #include <arc/message/MCC.h>
00013 #include <arc/message/MCCLoader.h>
00014 #ifdef WIN32
00015 #include <arc/win32.h>
00016 #endif
00017 
00018 int main(void) {
00019   signal(SIGTTOU,SIG_IGN);
00020   signal(SIGTTIN,SIG_IGN);
00021   Arc::Logger logger(Arc::Logger::rootLogger, "Test");
00022   Arc::LogStream logcerr(std::cerr);
00023   Arc::Logger::rootLogger.addDestination(logcerr);
00024   logger.msg(Arc::INFO, "Creating client side chain");
00025   // Create client chain
00026   Arc::XMLNode client_doc("\
00027     <ArcConfig\
00028       xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\"\
00029       xmlns:tcp=\"http://www.nordugrid.org/schemas/ArcMCCTCP/2007\">\
00030      <ModuleManager>\
00031         <Path>.libs/</Path>\
00032         <Path>../../hed/mcc/http/.libs/</Path>\
00033         <Path>../../hed/mcc/soap/.libs/</Path>\
00034         <Path>../../hed/mcc/tls/.libs/</Path>\
00035         <Path>../../hed/mcc/tcp/.libs/</Path>\
00036         <Path>../../hed/shc/.libs/</Path>\
00037      </ModuleManager>\
00038      <Plugins><Name>mcctcp</Name></Plugins>\
00039      <Plugins><Name>mcctls</Name></Plugins>\
00040      <Plugins><Name>mcchttp</Name></Plugins>\
00041      <Plugins><Name>mccsoap</Name></Plugins>\
00042      <Plugins><Name>arcshc</Name></Plugins>\
00043      <Chain>\
00044       <Component name='tcp.client' id='tcp'><tcp:Connect><tcp:Host>127.0.0.1</tcp:Host><tcp:Port>50000</tcp:Port></tcp:Connect></Component>\
00045       <Component name='tls.client' id='tls'><next id='tcp'/>\
00046         <!--For proxy certificate, KeyPath and CertificatePath are supposed to be the same-->\
00047         <KeyPath>./testkey-nopass.pem</KeyPath>\
00048         <CertificatePath>./testcert.pem</CertificatePath>\
00049         <CACertificatePath>./testcacert.pem</CACertificatePath>\
00050       </Component>\
00051       <Component name='http.client' id='http'><next id='tcp'/>\
00052         <Method>POST</Method>\
00053         <Endpoint>/Echo</Endpoint>\
00054       </Component>\
00055       <Component name='soap.client' id='soap' entry='soap'>\
00056         <next id='http'/>\
00057       </Component>\
00058      </Chain>\
00059     </ArcConfig>");
00060   Arc::Config client_config(client_doc);
00061   if(!client_config) {
00062     logger.msg(Arc::ERROR, "Failed to load client configuration");
00063     return -1;
00064   };
00065   Arc::MCCLoader client_loader(client_config);
00066   logger.msg(Arc::INFO, "Client side MCCs are loaded");
00067   Arc::MCC* client_entry = client_loader["soap"];
00068   if(!client_entry) {
00069     logger.msg(Arc::ERROR, "Client chain does not have entry point");
00070     return -1;
00071   };
00072 
00073   // for (int i = 0; i < 10; i++) {
00074   // Create and send echo request
00075   logger.msg(Arc::INFO, "Creating and sending request");
00076   Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo";
00077   Arc::PayloadSOAP req(echo_ns);
00078   req.NewChild("echo").NewChild("say")="HELLO";
00079   Arc::Message reqmsg;
00080   Arc::Message repmsg;
00081   reqmsg.Payload(&req);
00082   // It is a responsibility of code initiating first Message to
00083   // provide Context and Attributes as well.
00084   Arc::MessageAttributes attributes_req;
00085   Arc::MessageAttributes attributes_rep;
00086   Arc::MessageContext context;
00087   reqmsg.Attributes(&attributes_req);
00088   reqmsg.Context(&context);
00089   repmsg.Attributes(&attributes_rep);
00090   repmsg.Context(&context);
00091   Arc::MCC_Status status = client_entry->process(reqmsg,repmsg);
00092   if(!status) {
00093     logger.msg(Arc::ERROR, "Request failed");
00094     std::cerr << "Status: " << std::string(status) << std::endl;
00095     return -1;
00096   };
00097   Arc::PayloadSOAP* resp = NULL;
00098   if(repmsg.Payload() == NULL) {
00099     logger.msg(Arc::ERROR, "There is no response");
00100     return -1;
00101   };
00102   try {
00103     resp = dynamic_cast<Arc::PayloadSOAP*>(repmsg.Payload());
00104   } catch(std::exception&) { };
00105   if(resp == NULL) {
00106     logger.msg(Arc::ERROR, "Response is not SOAP");
00107     return -1;
00108   };
00109   std::string xml;
00110   resp->GetXML(xml);
00111   std::cout << "XML: "<< xml << std::endl;
00112   std::cout << "Response: " << (std::string)((*resp)["echoResponse"]["hear"]) << std::endl;
00113   //}    
00114   return 0;
00115 }