Back to index

nordugrid-arc-nox  1.1.0~rc6
test.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 #include <arc/client/ClientInterface.h>
00015 #ifdef WIN32
00016 #include <arc/win32.h>
00017 #endif
00018 
00019 int main(void) {
00020   signal(SIGTTOU,SIG_IGN);
00021   signal(SIGTTIN,SIG_IGN);
00022   Arc::Logger logger(Arc::Logger::rootLogger, "Test");
00023   Arc::LogStream logcerr1(std::cerr, "C");
00024   Arc::Logger::rootLogger.addDestination(logcerr1);
00025   Arc::LogStream logcerr2(std::cerr, "sv_SE.UTF8");
00026   Arc::Logger::rootLogger.addDestination(logcerr2);
00027   // Load service chain
00028   logger.msg(Arc::INFO, "Creating service side chain");
00029   Arc::Config service_config("service.xml");
00030   if(!service_config) {
00031     logger.msg(Arc::ERROR, "Failed to load service configuration");
00032     return -1;
00033   };
00034   Arc::MCCLoader service_loader(service_config);
00035   logger.msg(Arc::INFO, "Service side MCCs are loaded");
00036 
00037   logger.msg(Arc::INFO, "Creating client interface");
00038   Arc::MCCConfig client_cfg;
00039   // Paths to plugins in source tree
00040   client_cfg.AddPluginsPath("../../hed/mcc/http/.libs");
00041   client_cfg.AddPluginsPath("../../hed/mcc/soap/.libs");
00042   client_cfg.AddPluginsPath("../../hed/mcc/tls/.libs");
00043   client_cfg.AddPluginsPath("../../hed/mcc/tcp/.libs");
00044   client_cfg.AddPluginsPath("../../hed/shc/.libs");
00045   // Specify credentials
00046   client_cfg.AddPrivateKey("./testkey-nopass.pem");
00047   client_cfg.AddCertificate("./testcert.pem");
00048   client_cfg.AddCAFile("./testcacert.pem");
00049   // Create client instance for contacting echo service
00050   Arc::ClientSOAP client(client_cfg,Arc::URL("https://127.0.0.1:60000/echo"),60);
00051   // Add SecHandler to chain at TLS location to accept only
00052   // connection to server with specified DN
00053   std::list<std::string> dns;
00054   // Making a list of allowed hosts. To make this test
00055   // fail change DN below.
00056   dns.push_back("/O=Grid/O=Test/CN=localhost");
00057   // Creating SecHandler configuration with allowed DNs
00058   Arc::DNListHandlerConfig dncfg(dns,"outgoing");
00059   // Adding SecHandler to client at TLS level.
00060   // We have to explicitely specify method of ClientTCP 
00061   // class to attach SecHandler at proper location.
00062   client.Arc::ClientTCP::AddSecHandler(dncfg,Arc::TLSSec); 
00063   logger.msg(Arc::INFO, "Client side MCCs are loaded");
00064 
00065   for(int n = 0;n<1;n++) {
00066   // Create and send echo request
00067   logger.msg(Arc::INFO, "Creating and sending request");
00068   Arc::NS echo_ns;
00069   Arc::PayloadSOAP req(echo_ns);
00070   // Making echo namespace appear at operation level only
00071   // This is probably not needed and is here for demonstration
00072   // purposes only.
00073   echo_ns["echo"]="http://www.nordugrid.org/schemas/echo";
00074   Arc::XMLNode op = req.NewChild("echo:echo",echo_ns);
00075   op.NewChild("echo:say")="HELLO";
00076   Arc::PayloadSOAP* resp = NULL;
00077   Arc::MCC_Status status = client.process(&req,&resp);
00078   if(!status) {
00079     logger.msg(Arc::ERROR, "Request failed");
00080     if(resp) delete resp;
00081     return -1;
00082   };
00083   if(resp == NULL) {
00084     logger.msg(Arc::ERROR, "There is no response");
00085     return -1;
00086   };
00087   logger.msg(Arc::INFO, "Request succeed!!!");
00088   std::cout << "Response: " << (std::string)((*resp)["echoResponse"]["hear"])
00089            << std::endl;
00090   delete resp;
00091   };
00092  
00093   return 0;
00094 }