Back to index

nordugrid-arc-nox  1.1.0~rc6
test_ClientInterface.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 #include <stdexcept>
00008 
00009 #include <arc/GUID.h>
00010 #include <arc/ArcConfig.h>
00011 #include <arc/Logger.h>
00012 #include <arc/URL.h>
00013 #include <arc/message/PayloadSOAP.h>
00014 #include <arc/message/MCC.h>
00015 #include <arc/client/ClientInterface.h>
00016 #ifdef WIN32
00017 #include <arc/win32.h>
00018 #endif
00019 
00020 int main(void) {
00021   signal(SIGTTOU,SIG_IGN);
00022   signal(SIGTTIN,SIG_IGN);
00023   Arc::Logger logger(Arc::Logger::rootLogger, "Test");
00024   Arc::LogStream logcerr(std::cerr);
00025   Arc::Logger::rootLogger.addDestination(logcerr);
00026 
00027   std::string url_str("https://charged.uio.no:60000/echo");
00028   Arc::URL url(url_str);
00029 
00030   Arc::MCCConfig mcc_cfg;
00031   mcc_cfg.AddPrivateKey("../echo/userkey-nopass.pem");
00032   mcc_cfg.AddCertificate("../echo/usercert.pem");
00033   mcc_cfg.AddCAFile("../echo/testcacert.pem");
00034   mcc_cfg.AddCADir("../echo/certificates");
00035 
00036   Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo";
00037 
00038   //Create a SOAP client
00039   logger.msg(Arc::INFO, "Creating a soap client");
00040 
00041   
00042   //Configuration for the security handler of usernametoken and x509token
00043   Arc::XMLNode sechanlder_nd_ut("\
00044         <SecHandler name='usernametoken.handler' id='usernametoken' event='outgoing'>\
00045             <Process>generate</Process>\
00046             <PasswordEncoding>digest</PasswordEncoding>\
00047             <Username>user</Username>\
00048             <Password>passwd</Password>\
00049         </SecHandler>");
00050 
00051   Arc::XMLNode sechanlder_nd_xt("\
00052         <SecHandler name='x509token.handler' id='x509token' event='outgoing'>\
00053             <Process>generate</Process>\
00054             <CertificatePath>../echo/testcert.pem</CertificatePath>\
00055             <KeyPath>../echo/testkey-nopass.pem</KeyPath>\
00056         </SecHandler>");
00057 
00058   Arc::XMLNode sechanlder_nd_st("\
00059         <SecHandler name='samltoken.handler' id='samltoken' event='outgoing'>\
00060             <Process>generate</Process>\
00061             <CertificatePath>../echo/usercert.pem</CertificatePath>\
00062             <KeyPath>../echo/userkey-nopass.pem</KeyPath>\
00063             <CACertificatePath>../echo/testcacert.pem</CACertificatePath>\
00064             <CACertificatesDir>../echo/certificates</CACertificatesDir>\
00065             <AAService>https://squark.uio.no:60001/aaservice</AAService>\
00066         </SecHandler>");
00067 
00068   Arc::ClientSOAP *client;
00069   client = new Arc::ClientSOAP(mcc_cfg,url,60);
00070 
00071   //client->AddSecHandler(sechanlder_nd_ut, "arcshc");
00072   //client->AddSecHandler(sechanlder_nd_xt, "arcshc");
00073   client->AddSecHandler(sechanlder_nd_st, "arcshc");
00074 
00075   // Create and send echo request
00076   logger.msg(Arc::INFO, "Creating and sending request");
00077   Arc::PayloadSOAP req(echo_ns);
00078   req.NewChild("echo").NewChild("say")="HELLO";
00079 
00080   Arc::PayloadSOAP* resp = NULL;
00081 
00082   if(client) {
00083     std::string str;
00084     req.GetXML(str);
00085     std::cout<<"request: "<<str<<std::endl;
00086     Arc::MCC_Status status = client->process(&req,&resp);
00087     if(!status) {
00088       logger.msg(Arc::ERROR, "SOAP invokation failed");
00089       throw std::runtime_error("SOAP invokation failed");
00090     }
00091     if(resp == NULL) {
00092       logger.msg(Arc::ERROR,"There was no SOAP response");
00093       throw std::runtime_error("There was no SOAP response");
00094     }
00095   }
00096 
00097   std::string xml;
00098   resp->GetXML(xml);
00099   std::cout << "XML: "<< xml << std::endl;
00100   std::cout << "Response: " << (std::string)((*resp)["echoResponse"]["hear"]) << std::endl;
00101 
00102   if(resp) delete resp;
00103   if(client) delete client;
00104 
00105   return 0;
00106 }