Attachment 'test_client_ipv4.cpp'
Download 1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include <iostream>
6 #include <signal.h>
7
8 #include <arc/ArcConfig.h>
9 #include <arc/Logger.h>
10 #include <arc/loader/Loader.h>
11 #include <arc/message/SOAPEnvelope.h>
12 #include <arc/message/PayloadSOAP.h>
13
14 int main(void) {
15 #ifndef WIN32
16 signal(SIGTTOU,SIG_IGN);
17 signal(SIGTTIN,SIG_IGN);
18 #endif
19 Arc::Logger logger(Arc::Logger::rootLogger, "Test");
20 Arc::LogStream logcerr(std::cerr);
21 Arc::Logger::rootLogger.addDestination(logcerr);
22 logger.msg(Arc::INFO, "Creating client side chain");
23 // Create client chain
24 Arc::XMLNode client_doc("\
25 <ArcConfig\
26 xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\"\
27 xmlns:tcp=\"http://www.nordugrid.org/schemas/ArcMCCTCP/2007\">\
28 <ModuleManager>\
29 <Path>.libs/</Path>\
30 <Path>../../hed/mcc/http/.libs/</Path>\
31 <Path>../../hed/mcc/soap/.libs/</Path>\
32 <Path>../../hed/mcc/tls/.libs/</Path>\
33 <Path>../../hed/mcc/tcp/.libs/</Path>\
34 </ModuleManager>\
35 <Plugins><Name>mcctcp</Name></Plugins>\
36 <Plugins><Name>mcctls</Name></Plugins>\
37 <Plugins><Name>mcchttp</Name></Plugins>\
38 <Plugins><Name>mccsoap</Name></Plugins>\
39 <Chain>\
40 <Component name='tcp.client' id='tcp'><tcp:Connect><tcp:Host>127.0.0.1</tcp:Host><tcp:Port>60000</tcp:Port></tcp:Connect></Component>\
41 <Component name='http.client' id='http'><next id='tcp'/><Method>POST</Method><Endpoint>/Echo</Endpoint></Component>\
42 <Component name='soap.client' id='soap' entry='soap'><next id='http'/></Component>\
43 </Chain>\
44 </ArcConfig>");
45 Arc::Config client_config(client_doc);
46 if(!client_config) {
47 logger.msg(Arc::ERROR, "Failed to load client configuration");
48 return -1;
49 };
50 Arc::Loader client_loader(&client_config);
51 logger.msg(Arc::INFO, "Client side MCCs are loaded");
52 Arc::MCC* client_entry = client_loader["soap"];
53 if(!client_entry) {
54 logger.msg(Arc::ERROR, "Client chain does not have entry point");
55 return -1;
56 };
57
58 // for (int i = 0; i < 10; i++) {
59 // Create and send echo request
60 logger.msg(Arc::INFO, "Creating and sending request");
61 Arc::NS echo_ns; echo_ns["echo"]="urn:echo";
62 Arc::PayloadSOAP req(echo_ns);
63 req.NewChild("echo").NewChild("say")="HELLO";
64 Arc::Message reqmsg;
65 Arc::Message repmsg;
66 reqmsg.Payload(&req);
67 // It is a responsibility of code initiating first Message to
68 // provide Context and Attributes as well.
69 Arc::MessageAttributes attributes_req;
70 Arc::MessageAttributes attributes_rep;
71 Arc::MessageContext context;
72 reqmsg.Attributes(&attributes_req);
73 reqmsg.Context(&context);
74 repmsg.Attributes(&attributes_rep);
75 repmsg.Context(&context);
76 Arc::MCC_Status status = client_entry->process(reqmsg,repmsg);
77 if(!status) {
78 logger.msg(Arc::ERROR, "Request failed");
79 std::cerr << "Status: " << std::string(status) << std::endl;
80 return -1;
81 };
82 Arc::PayloadSOAP* resp = NULL;
83 if(repmsg.Payload() == NULL) {
84 logger.msg(Arc::ERROR, "There is no response");
85 return -1;
86 };
87 try {
88 resp = dynamic_cast<Arc::PayloadSOAP*>(repmsg.Payload());
89 } catch(std::exception&) { };
90 if(resp == NULL) {
91 logger.msg(Arc::ERROR, "Response is not SOAP");
92 return -1;
93 };
94 std::string xml;
95 resp->GetXML(xml);
96 std::cout << "XML: "<< xml << std::endl;
97 std::cout << "Response: " << (std::string)((*resp)["echoResponse"]["hear"]) << std::endl;
98 //}
99 return 0;
100 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.