Back to index

nordugrid-arc-nox  1.1.0~rc6
arex2.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <iostream>
00006 
00007 #include <sys/types.h>
00008 #include <unistd.h>
00009 
00010 #include <arc/message/PayloadSOAP.h>
00011 #include <arc/message/PayloadRaw.h>
00012 #include <arc/message/PayloadStream.h>
00013 #include <arc/ws-addressing/WSA.h>
00014 #include <arc/Thread.h>
00015 
00016 #include "arex2.h"
00017 
00018 namespace ARex2 {
00019 
00020 static Arc::LogStream logcerr(std::cerr);
00021 
00022 // Static initializator
00023 static Arc::Plugin* get_service(Arc::PluginArgument* arg) {
00024     Arc::ServicePluginArgument* srvarg =
00025             arg?dynamic_cast<Arc::ServicePluginArgument*>(arg):NULL;
00026     if(!srvarg) return NULL;
00027     return new ARex2Service((Arc::Config*)(*srvarg));
00028 }
00029 
00030 Arc::MCC_Status ARex2Service::CreateActivity(Arc::XMLNode /*in*/,
00031                                              Arc::XMLNode /*out*/) 
00032 {
00033     return Arc::MCC_Status();
00034 }
00035 
00036 Arc::MCC_Status ARex2Service::GetActivityStatuses(Arc::XMLNode /*in*/,
00037                                                   Arc::XMLNode /*out*/) 
00038 {
00039     return Arc::MCC_Status();
00040 }
00041 
00042 Arc::MCC_Status ARex2Service::TerminateActivities(Arc::XMLNode /*in*/,
00043                                                  Arc::XMLNode /*out*/) 
00044 {
00045     return Arc::MCC_Status();
00046 }
00047 
00048 Arc::MCC_Status ARex2Service::GetActivityDocuments(Arc::XMLNode /*in*/,
00049                                                    Arc::XMLNode /*out*/) 
00050 {
00051     return Arc::MCC_Status();
00052 }
00053 
00054 Arc::MCC_Status ARex2Service::GetFactoryAttributesDocument(Arc::XMLNode /*in*/,
00055                                                           Arc::XMLNode /*out*/)
00056 {
00057     return Arc::MCC_Status();
00058 }
00059 
00060 
00061 Arc::MCC_Status ARex2Service::StopAcceptingNewActivities(Arc::XMLNode /*in*/, 
00062                                                          Arc::XMLNode /*out*/) 
00063 {
00064     return Arc::MCC_Status();
00065 }
00066 
00067 Arc::MCC_Status ARex2Service::StartAcceptingNewActivities(Arc::XMLNode /*in*/,
00068                                                           Arc::XMLNode /*out*/) 
00069 {
00070     return Arc::MCC_Status();
00071 }
00072 
00073 Arc::MCC_Status ARex2Service::ChangeActivityStatus(Arc::XMLNode /*in*/,
00074                                                    Arc::XMLNode /*out*/) 
00075 {
00076     return Arc::MCC_Status();
00077 }
00078 
00079 // Create Faults
00080 Arc::MCC_Status ARex2Service::make_soap_fault(Arc::Message& outmsg) 
00081 {
00082   Arc::PayloadSOAP* outpayload = new Arc::PayloadSOAP(ns_,true);
00083   Arc::SOAPFault* fault = outpayload?outpayload->Fault():NULL;
00084   if(fault) {
00085     fault->Code(Arc::SOAPFault::Sender);
00086     fault->Reason("Failed processing request");
00087   };
00088   outmsg.Payload(outpayload);
00089   return Arc::MCC_Status(Arc::STATUS_OK);
00090 }
00091 
00092 Arc::MCC_Status ARex2Service::make_fault(Arc::Message& /*outmsg*/) 
00093 {
00094   return Arc::MCC_Status();
00095 }
00096 
00097 Arc::MCC_Status ARex2Service::make_response(Arc::Message& outmsg) 
00098 {
00099   Arc::PayloadRaw* outpayload = new Arc::PayloadRaw();
00100   outmsg.Payload(outpayload);
00101   return Arc::MCC_Status(Arc::STATUS_OK);
00102 }
00103 
00104 // Main process 
00105 Arc::MCC_Status ARex2Service::process(Arc::Message& inmsg,Arc::Message& outmsg) {
00106     // Both input and output are supposed to be SOAP
00107     // Extracting payload
00108     Arc::PayloadSOAP* inpayload = NULL;
00109     try {
00110       inpayload = dynamic_cast<Arc::PayloadSOAP*>(inmsg.Payload());
00111     } catch(std::exception& e) { };
00112     if(!inpayload) {
00113       logger_.msg(Arc::ERROR, "input is not SOAP");
00114       return make_soap_fault(outmsg);
00115     };
00116 
00117     // Get operation
00118     Arc::XMLNode op = inpayload->Child(0);
00119     if(!op) {
00120       logger_.msg(Arc::ERROR, "input does not define operation");
00121       return make_soap_fault(outmsg);
00122     };
00123     logger_.msg(Arc::VERBOSE, "process: operation: %s",op.Name());
00124     // BES Factory operations
00125     Arc::PayloadSOAP* outpayload = new Arc::PayloadSOAP(ns_);
00126     Arc::PayloadSOAP& res = *outpayload;
00127     Arc::MCC_Status ret;
00128     if(MatchXMLName(op, "CreateActivity")) {
00129         res.NewChild("bes-factory:CreateActivityResponse");
00130         ret = CreateActivity(op, res);
00131     } else if(MatchXMLName(op, "GetActivityStatuses")) {
00132         res.NewChild("bes-factory:GetActivityStatusesResponse");
00133         ret = GetActivityStatuses(op, res);
00134     } else if(MatchXMLName(op, "TerminateActivities")) {
00135         res.NewChild("bes-factory:TerminateActivitiesResponse");
00136         ret = TerminateActivities(op, res);
00137     } else if(MatchXMLName(op, "GetActivityDocuments")) {
00138         res.NewChild("bes-factory:GetActivityDocumentsResponse");
00139         ret = GetActivityDocuments(op, res);
00140     } else if(MatchXMLName(op, "GetFactoryAttributesDocument")) {
00141         res.NewChild("bes-factory:GetFactoryAttributesDocumentResponse");
00142         ret = GetFactoryAttributesDocument(op, res);
00143     } else if(MatchXMLName(op, "StopAcceptingNewActivities")) {
00144         res.NewChild("bes-factory:StopAcceptingNewActivitiesResponse");
00145         ret = StopAcceptingNewActivities(op, res);
00146     } else if(MatchXMLName(op, "StartAcceptingNewActivities")) {
00147         res.NewChild("bes-factory:StartAcceptingNewActivitiesResponse");
00148         ret = StartAcceptingNewActivities(op, res);
00149     } else if(MatchXMLName(op, "ChangeActivityStatus")) {
00150         res.NewChild("bes-factory:ChangeActivityStatusResponse");
00151         ret = ChangeActivityStatus(op, res);
00152       // Delegation
00153     } else if(MatchXMLName(op, "DelegateCredentialsInit")) {
00154         if(!delegations_.DelegateCredentialsInit(*inpayload,*outpayload)) {
00155           delete outpayload;
00156           return make_soap_fault(outmsg);
00157         };
00158       // WS-Property
00159     } else if(MatchXMLNamespace(op,"http://docs.oasis-open.org/wsrf/rp-2")) {
00160         Arc::SOAPEnvelope* out_ = infodoc_.Process(*inpayload);
00161         if(out_) {
00162           *outpayload=*out_;
00163           delete out_;
00164         } else {
00165           delete outpayload;
00166           return make_soap_fault(outmsg);
00167         };
00168     } else {
00169         logger_.msg(Arc::ERROR, "SOAP operation is not supported: %s", op.Name());
00170         delete outpayload;
00171         return make_soap_fault(outmsg);
00172     };
00173     {
00174         // VERBOSE 
00175         std::string str;
00176         outpayload->GetXML(str);
00177         logger_.msg(Arc::VERBOSE, "process: response=%s",str);
00178     };
00179     // Set output
00180     outmsg.Payload(outpayload);
00181     return Arc::MCC_Status(Arc::STATUS_OK);
00182 }
00183 
00184 // Start information collector 
00185 /*
00186 static void thread_starter(void* arg) 
00187 {
00188   if(!arg) return;
00189   ((ARex2Service*)arg)->InformationCollector();
00190 }
00191 */
00192 
00193 // Constructor
00194 
00195 ARex2Service::ARex2Service(Arc::Config *cfg):Service(cfg),logger_(Arc::Logger::rootLogger, "A-REX2") 
00196 {
00197   logger_.addDestination(logcerr);
00198   // Define supported namespaces
00199   ns_["a-rex"]="http://www.nordugrid.org/schemas/a-rex";
00200   ns_["bes-factory"]="http://schemas.ggf.org/bes/2006/08/bes-factory";
00201   ns_["deleg"]="http://www.nordugrid.org/schemas/delegation";
00202   ns_["wsa"]="http://www.w3.org/2005/08/addressing";
00203   ns_["jsdl"]="http://schemas.ggf.org/jsdl/2005/11/jsdl";
00204   ns_["wsrf-bf"]="http://docs.oasis-open.org/wsrf/bf-2";
00205   ns_["wsrf-r"]="http://docs.oasis-open.org/wsrf/r-2";
00206   ns_["wsrf-rw"]="http://docs.oasis-open.org/wsrf/rw-2";
00207   // CreateThreadFunction(&thread_starter,this);
00208 }
00209 
00210 // Destructor
00211 ARex2Service::~ARex2Service(void) 
00212 {
00213     // NOP
00214 }
00215 
00216 } // namespace ARex2
00217 
00218 Arc::PluginDescriptor PLUGINS_TABLE_NAME[] = {
00219     { "a-rex2", "HED:SERVICE", 0, &ARex2::get_service },
00220     { NULL, NULL, 0, NULL }
00221 };
00222