示例#1
0
int main() {
	struct soap *mydlo = NULL;
	glite_gsplugin_Context gsplugin_ctx = NULL;
	int ok1;

	// test 1 - stdsoap2.c compatibility
	if ((mydlo = soap_new()) == NULL) {
		std::cerr << "Couldn't create soap" << std::endl;
		return 1;
	}
	soap_set_endpoint(mydlo, TEST_STR);
	std::cout << mydlo->endpoint << std::endl;
	ok1 = strcmp(mydlo->endpoint, TEST_STR);

	// test 2 - glite_gsplugin.c compatibility
	//
	// not real test, just may crash in bad test case on calling
	// soap->fdelete where will be other function
	if ( glite_gsplugin_init_context(&gsplugin_ctx) ) {
		std::cerr << "Couldn't create gSOAP plugin context" << std::endl;
		goto err;
	}
	if (soap_register_plugin_arg(mydlo, glite_gsplugin, gsplugin_ctx)) {
		std::cerr << "Couldn't register gSoap plugin" << std::endl;
		goto err;
	}

	soap_done(mydlo);
	free(mydlo);
	glite_gsplugin_free_context(gsplugin_ctx);
	return ok1;

err:
	if (gsplugin_ctx) glite_gsplugin_free_context(gsplugin_ctx);
	if (mydlo) soap_destroy(mydlo);
	return 1;
}
/**
 * List all replicas of a given InputDataType. A replica needs to contain
 * a valid SEId that is registered with the Information Service.
 *
 * @param inputDataType Defines one of the following InputDataTypes:
 *                      lfn   ... LogicalFileName
 *                      guid  ... GUID Global Unique Idenifier
 *                      lds   ... LogicalDataSet
 *                      query ... generic query to the catalogue
 *        Further InputDataTypes can be extended in the future but need to
 *        be understood by the remote catalogue. 
 *        Note that a catalogue does not need to implement all of the four
 *        InputDataTypes but is free to support any subset.
 * @param inputData     Actutual InputData variable
 *
 * @returns a vector of URLs that represent the locations of where
 *          the InputData is located. The URL can either be a full URL
 *          of the form    protocol://hostname/pathname
 *          or             hostname
 *          where hostname is a registered SEId.
 */
std::vector<std::string> 
dli::DataLocationInterfaceSOAP::listReplicas(std::string inputDataType,
					     std::string inputData,
                                             const classad::ClassAd & ad,
                                             const std::string& endpoint)
{
///////////////////...for using secure endpoint

   bool proxyInJdl = true;
   std::string proxy;
   try {
      proxy =  jdl::get_x509_user_proxy(ad);
   } catch(...) {
      proxyInJdl = false;
   }
                                                                                                                                   
   if(0 == strncasecmp(endpoint.c_str(), "https://", 8)) {
      if (proxyInJdl) {
         if (!m_ctx) {
            if ( glite_gsplugin_init_context(&m_ctx) ) {
               throw DLIerror("gsplugin_init_context FAILED");
            }
         }
         if (glite_gsplugin_set_credential(m_ctx, proxy.c_str(), proxy.c_str())) {
            std::string gss_err(m_ctx->error_msg); 
            glite_gsplugin_free_context(m_ctx);
            m_ctx = NULL;
            throw DLIerror("Cannot set credentials in the gsoap-plugin context: " + gss_err);
         }
      } else {
        throw DLIerror("UserProxy not specified in the ClassAd");
      }
                                                                                                                                   
      if (soap_register_plugin_arg(&m_soap, glite_gsplugin, m_ctx)) {
         std::stringstream ss;
         ss << m_soap.error;
         std::string soap_err = ss.str();

         throw DLIerror("soap_register_plugin_arg FAILED: " + soap_err);
      }
   }

   std::vector<std::string> urlVector;
   struct datalocationinterface__listReplicasResponse theList;
  
   // Call listReplicas and handle potential SOAP Faults
   if (soap_call_datalocationinterface__listReplicas(
     &m_soap,
     endpoint.c_str(),
     "",
     inputDataType, inputData, theList)) {

      std::string ex;
      if (m_soap.error) {
         soap_set_fault(&m_soap);

         const char** faultdetail_ptr = soap_faultdetail(&m_soap);
         std::string faultdetail;
         if (*faultdetail_ptr != NULL) {
           faultdetail = *faultdetail_ptr;
         } else {
           faultdetail = "unknown";
         }                                                                                                                   
         const char** faultcode_ptr = soap_faultcode(&m_soap);
         std::string faultcode;
         if ( *faultcode_ptr != NULL ) faultcode = *faultcode_ptr;
            else faultcode = "unknown";

         const char** faultstring_ptr = soap_faultstring(&m_soap);
         std::string faultstring;
         if (*faultstring_ptr != NULL ) faultstring = *faultstring_ptr;
            else faultstring = "unknown";

         std::string SOAP_FAULTCODE = "SOAP_FAULTCODE: ";
         std::string SOAP_FAULTSTRING = "SOAP_FAULTSTRING: ";
         std::string SOAP_FAULT_DETAIL = "SOAP_FAULT_DETAIL: ";
         std::string new_line = "\n";

         ex = new_line + SOAP_FAULTCODE + faultcode + new_line +
                         SOAP_FAULTSTRING +  faultstring + new_line +
                         SOAP_FAULT_DETAIL + faultdetail + new_line;
      } else {
         ex = "Error in soap request towards StorageIndex Catalog. Unknown error.";
      }
                                                                                                                             
      throw DLIerror(ex);
   }

   for (int i = 0; i < (theList.urlList)->__size; i++)  {
#ifdef GSOAP_279_TRICK
      std::string *thisS = *(theList.urlList->__ptritem);
#else
      std::string *thisS = (theList.urlList->__ptritem);
#endif
      //std::string str( ((theList.urlList)->__ptritem)[i] );
      std::string str( *(thisS + i) );
      urlVector.push_back( str );
   }

   return urlVector;
} // listReplicas