int getQuote (char *symbol, char *Result) { FlpCompDouble d; struct soap *soap; float result; int rc; char *addr = "http://services.xmethods.net/soap/"; soap = soap_new(); soap->namespaces = (struct Namespace *)namespaces; rc = soap_call_ns__getQuote(soap, addr, "", (char*)symbol, &result); soap_end(soap); free(soap); if (rc==SOAP_OK) { d.d= result; FlpFToA (d.fd,Result); StdEtoA(Result); } else { soap_set_fault(soap); strcpy (Result, soap->msgbuf); } return rc; }
static void _fault_to_error(glite_delegation_ctx *ctx, const char *method) { const char **code, **string, **detail; struct soap *soap = ctx->soap; soap_set_fault(soap); if (soap->fault) { /* Look for a SOAP 1.1 fault */ if (soap->fault->detail) decode_exception(ctx, soap->fault->detail, method); /* Look for a SOAP 1.2 fault */ if (soap->fault->SOAP_ENV__Detail) decode_exception(ctx, soap->fault->SOAP_ENV__Detail, method); } /* If we did not manage to decode the exception, try generic error * decoding */ if (!ctx->error) { code = soap_faultcode(soap); string = soap_faultstring(soap); detail = soap_faultdetail(soap); /* If the SOAP 1.1 detail is empty, try the SOAP 1.2 detail */ if (!detail && soap->fault && soap->fault->SOAP_ENV__Detail) detail = (const char **)&soap->fault->SOAP_ENV__Detail->__any; /* Provide default messages */ if (!code || !*code) { code = alloca(sizeof(*code)); *code = "(SOAP fault code missing)"; } if (!string || !*string) { string = alloca(sizeof(*string)); *string = "(SOAP fault string missing)"; } if (detail && *detail) glite_delegation_set_error(ctx, "%s: SOAP fault: %s - %s (%s)", method, *code, *string, *detail); else glite_delegation_set_error(ctx, "%s: SOAP fault: %s - %s", method, *code, *string); } soap_end(soap); }
/* * This method is used to print the SOAP fault to a string */ void soap_sprint_fault(struct soap *soap, char *fd) { if (soap->error) { const char *c, *v = NULL, *s, **d; d = soap_faultcode(soap); if (!*d) soap_set_fault(soap); c = *d; if (soap->version == 2) v = *soap_faultsubcode(soap); s = *soap_faultstring(soap); d = soap_faultdetail(soap); sprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]"); } }
void Request::Execute() { try { this->setEndpoint(); this->setHeader(); try { this->getRequest(); } catch (soap* soap) { if (soap_check_state(soap)) std::clog << "Error: soap struct state not initialized\n"; else if (soap->error) { const char *c, *v = NULL, *s, **d; d = soap_faultcode(soap); if (!*d) soap_set_fault(soap); c = *d; if (soap->version == 2) v = *soap_faultsubcode(soap); s = *soap_faultstring(soap); d = soap_faultdetail(soap); std::clog << (soap->version ? "SOAP 1." : "Error ") << (soap->version ? (int) soap->version : soap->error) << " fault: " << c << "[" << (v ? v : "no subcode") << "]" << std::endl << "\"" << (s ? s : "[no reason]") << "\"" << std::endl << "Detail: " << (d && *d ? *d : "[no detail]") << std::endl; ; } } } catch (int a) { if (a == 100) std::clog << "ERRORE: endpoint non trovato" << std::endl; } }
SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap *soap, std::ostream& msg) { if (soap->error) { if (!*soap_faultcode(soap)) soap_set_fault(soap); if (!*soap_faultstring(soap)) *soap_faultstring(soap) = ""; msg << "SOAP FAULT: " << *soap_faultcode(soap) << std::endl << "\"" << *soap_faultstring(soap) << "\"" << std::endl; if (*soap_faultdetail(soap)) msg << "Detail: " << *soap_faultdetail(soap) << std::endl; } }
int interoptA(const char *url) { struct soap *soap; int i, g; xsd__string so, si = "Hello World! <>&"; struct ArrayOfstring Asi, Aso; xsd__int no, ni = 1234567890; xsd__int n = 2147483647; struct ArrayOfint Ani, Ano; xsd__float f1 = 123.5678; xsd__float f2 = 3.14; xsd__float fo, fi = 123.5; #ifdef SYMBIAN const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; #endif xsd__float nan = FLT_NAN, inf = FLT_PINFTY, ninf = FLT_NINFTY; struct ArrayOffloat Afi, Afo; struct s__SOAPStruct sti, *p; struct ns__echoStructResponse sto; struct ArrayOfSOAPStruct Asti, Asto; struct ns__echoVoidResponse Rv; struct xsd__base64Binary b64i, b64o; xsd__dateTime dto, dti = "1967-12-29T01:02:03"; struct xsd__hexBinary hbi, hbo; xsd__decimal Do, Di = "1234567890.123456789"; xsd__boolean bo, bi = true; displayText("running test A on"); displayText((char*)url); soap = soap_new(); soap->namespaces = (struct Namespace *)namespaces; // soap.send_timeout = 30; // soap.recv_timeout = 30; Asi.__size = 8; Asi.__offset = 0; Asi.__ptr = (xsd__string*)malloc(Asi.__size*sizeof(xsd__string)); Asi.__ptr[0] = NULL; Asi.__ptr[1] = " Hello\tWorld"; Asi.__ptr[2] = NULL; Asi.__ptr[3] = "! "; Asi.__ptr[4] = NULL; Asi.__ptr[5] = si; Asi.__ptr[6] = NULL; Asi.__ptr[7] = si; Ani.__size = 0; Ani.__offset = 0; Ani.__ptr = NULL; // (xsd__int*)malloc(Ani.__size*sizeof(xsd__int)); Afi.__size = 5; Afi.__offset = 0; Afi.__ptr = (xsd__float**)malloc(Afi.__size*sizeof(xsd__float*)); Afi.__ptr[0] = &f1; Afi.__ptr[1] = &f1; // FLT_NAN; Afi.__ptr[2] = &inf; // FLT_PINFTY; Afi.__ptr[3] = &ninf; // FLT_NINFTY; Afi.__ptr[4] = &f2; sti.varString = "Hello"; sti.varInt = &n; sti.varFloat = &f1; Asti.__size = 3; Asti.__offset = 2; Asti.__ptr = (struct s__SOAPStruct**)malloc((Asti.__size+1)*sizeof(struct s__SOAPStruct*)); p = (struct s__SOAPStruct*)malloc(Asti.__size*sizeof(struct s__SOAPStruct)); Asti.__ptr[0] = p; Asti.__ptr[1] = p+1; Asti.__ptr[2] = p+2; Asti.__ptr[3] = p; Asti.__ptr[0]->varString = "Hello"; Asti.__ptr[0]->varInt = &n; Asti.__ptr[0]->varFloat = &f1; Asti.__ptr[1]->varString = "World"; Asti.__ptr[1]->varInt = &n; Asti.__ptr[1]->varFloat = &f2; Asti.__ptr[2]->varString = "!"; Asti.__ptr[2]->varInt = &n; Asti.__ptr[2]->varFloat = &f2; unsigned char b64data[4]={0x80, 0x81, 0x82, 0x83}; b64i.__ptr = b64data; b64i.__size = 4; hbi.__ptr = (unsigned char*)"This is an example HexBinary encoded string"; hbi.__size = strlen((char*)hbi.__ptr)+1; char *site=(char*)url; char* action = "http://soapinterop.org/"; bool ok=true; if (soap_call_ns__echoString(soap, site, action, si, so)) { displayText("echoString failed"); ok=false; } else if (!so || strcmp(si, so)) { ok=false; displayText("echoString mismatch"); } else displayText("echoString pass"); if (soap_call_ns__echoInteger(soap, site, "http://soapinterop.org/", ni, no)) { ok=false; displayText("echoInteger fail"); } else if (ni != no) { ok=false; displayText("echoInteger mismatch"); } else displayText("echoInteger pass"); if (soap_call_ns__echoFloat(soap, site, "http://soapinterop.org/", fi, fo)) { ok=false; displayText("echoFloat fail"); } else if (fi != fo) { ok=false; displayText("echoFloat mismatch"); } else displayText("echoFloat pass"); if (soap_call_ns__echoStruct(soap, site, "http://soapinterop.org/", sti, sto)) { ok=false; displayText("echoStruct fail"); } else if (!sto._return.varString || strcmp(sti.varString, sto._return.varString) || !sto._return.varInt || *sti.varInt != *sto._return.varInt || !sto._return.varFloat || *sti.varFloat != *sto._return.varFloat) { ok=false; displayText("echoStruct mismatch"); } else displayText("echoStruct pass"); if (soap_call_ns__echoStringArray(soap, site, "http://soapinterop.org/", Asi, Aso)) { soap_set_fault(soap); soap_faultdetail(soap); ok=false; displayText("echoStringArray fail"); } else { g = 0; if (Asi.__size != Aso.__size) g = 1; else for (i = 0; i < Asi.__size; i++) if (Asi.__ptr[i] && Aso.__ptr[i] && strcmp(Asi.__ptr[i], Aso.__ptr[i])) g = 1; else if (!Asi.__ptr[i]) ; else if (Asi.__ptr[i] && !Aso.__ptr[i]) g = 1; if (g) { ok=false; displayText("echoStringArray mismatch"); } else displayText("echoStringArray pass"); } if (soap_call_ns__echoIntegerArray(soap, site, "http://soapinterop.org/", Ani, Ano)) { displayText("echoIntegerArray fail"); ok=false; } else { g = 0; if (Ani.__size != Ano.__size) g = 1; else for (i = 0; i < Ani.__size; i++) if (Ani.__ptr[i] && (!Ano.__ptr[i] || *Ani.__ptr[i] != *Ano.__ptr[i])) g = 1; if (g) { displayText("echoIntegerArray mismatch"); ok=false; } else displayText("echoIntegerArray pass"); } if (soap_call_ns__echoFloatArray(soap, site, "http://soapinterop.org/", Afi, Afo)) { displayText("echoFloatArray fail"); ok=false; } else { g = 0; if (Afi.__size != Afo.__size) g = 1; else for (i = 0; i < Afi.__size; i++) if (Afi.__ptr[i] && Afo.__ptr[i] && soap_isnan(*Afi.__ptr[i]) && soap_isnan(*Afo.__ptr[i])) ; else if (Afi.__ptr[i] && (!Afo.__ptr[i] || *Afi.__ptr[i] != *Afo.__ptr[i])) g = 1; if (g) { displayText("echoFloatArray mismatch"); ok=false; } else displayText("echoFloatArray pass"); } if (soap_call_ns__echoStructArray(soap, site, "http://soapinterop.org/", Asti, Asto)) { displayText("echoStructArray fail"); ok=false; } else { g = 0; if (Asti.__size+Asti.__offset != Asto.__size+Asto.__offset) g = 1; else for (i = Asti.__offset; i < Asti.__size+Asti.__offset; i++) if (!Asto.__ptr[i-Asto.__offset] || !Asto.__ptr[i-Asto.__offset]->varString || strcmp(Asti.__ptr[i-Asti.__offset]->varString, Asto.__ptr[i-Asto.__offset]->varString) || !Asto.__ptr[i-Asto.__offset]->varInt || *Asti.__ptr[i-Asti.__offset]->varInt != *Asto.__ptr[i-Asto.__offset]->varInt || !Asto.__ptr[i-Asto.__offset]->varFloat || *Asti.__ptr[i-Asti.__offset]->varFloat != *Asto.__ptr[i-Asto.__offset]->varFloat) g = 1; if (g) { displayText("echoStructArray mismatch"); ok=false; } else displayText("echoStructArray pass"); } if (soap_call_ns__echoVoid(soap, site, "http://soapinterop.org/", Rv)) { displayText("echoVoid fail"); ok=false; } else displayText("echoVoid pass"); { int S1=sizeof(int); int S2= sizeof (size_t); int S3=sizeof(0); } if (soap_call_ns__echoBase64(soap, site, "http://soapinterop.org/", b64i, b64o)) { displayText("echoBase64 fail"); ok=false; } else if ((b64i.__size+2)/3 != (b64o.__size+2)/3 || strncmp((char*)b64i.__ptr, (char*)b64o.__ptr,b64i.__size)) { displayText("echoBase64 mismatch"); ok=false; } else displayText("echoBase64 pass"); if (soap_call_ns__echoDate(soap, site, "http://soapinterop.org/", dti, dto)) { displayText("echoDate fail"); ok=false; } else if (!dto || strncmp(dti, dto, 19)) { displayText("echoDate mismatch"); ok=false; } else displayText("echoDate pass"); if (soap_call_ns__echoHexBinary(soap, site, "http://soapinterop.org/", hbi, hbo)) { ok=false; displayText("echoHexBinary fail"); } else if (hbi.__size != hbo.__size || strcmp((char*)hbi.__ptr, (char*)hbo.__ptr)) { ok=false; displayText("echoHexBinary mismatch"); } else displayText("echoHexBinary pass"); if (soap_call_ns__echoDecimal(soap, site, "http://soapinterop.org/", Di, Do)) { ok=false; displayText("echoDecimal pass"); } else if (strcmp(Di, Do)) { ok=false; displayText("echoDecimal mismatch"); } else displayText("echoDecimal pass"); if (soap_call_ns__echoBoolean(soap, site, "http://soapinterop.org/", bi, bo)) { ok=false; displayText("echoBoolean fail"); } else if (bi != bo) { ok=false; displayText("echoBoolean mismatch"); } else displayText("echoBoolean pass"); soap_end(soap); soap_done(soap); if (ok) displayText("ALL PASS"); else displayText("FAILURES"); return 0; end: return 1; }
/***************************************************************************** 函 数 名 : ws_internal_call 功能描述 : 以内部方式调用一个web service方法 输入参数 : ws_env ---- web service执行环境 ws_req_res ---- web service参数结构 method ---- web service方法名 handle ---- web service处理函数所在so文件据柄 internal_env -- 内部执行环境 输出参数 : 无 返 回 值 : ERROR_SYSTEM 失败 ERR_SUCESS 成功,无错误 SOAP_FAULT 执行有错误,错误放soapFault中 调用函数 : 被调函数 : ============================================================================ 修改历史 : 1.日 期 : 2008年8月8日 修改内容 : 新生成函数 *****************************************************************************/ u_int32_t ws_internal_call(WS_ENV* ws_env, WS_REQ_RES* ws_req_res, char* method, void* handle, WS_INTERNAL_ENV *internal_env) { char* pchar; char* error; /* 向web service发送数据的管道 */ int file_to_ws[2]; /* 从web service接收数据的管道 */ int file_from_ws[2]; SOAP_SERVE_REQUEST *soap_serve_request; u_int32_t ret; if((NULL == ws_env) || (NULL == ws_req_res) || (NULL == method)) { return ERROR_SYSTEM; } do { /* 只执行一次 */ error = NULL; dlerror(); /* Clear any existing error */ /* 读入web service执行函数 */ soap_serve_request = dlsym(handle, "soap_serve_request"); if ((error = dlerror()) != NULL) { break; } #ifndef WITH_NOIDREF /* 读入各模块支持函数,在web_frame.so中引用 */ soap_putelement_ext = dlsym(handle, "soap_putelement"); if ((error = dlerror()) != NULL) { break; } #endif soap_ignore_element_ext = dlsym(handle, "soap_ignore_element"); if ((error = dlerror()) != NULL) { break; } soap_default_int_ext = dlsym(handle, "soap_default_int"); if ((error = dlerror()) != NULL) { break; } #ifndef WITH_NOIDREF soap_getindependent_ext = dlsym(handle, "soap_getindependent"); if ((error = dlerror()) != NULL) { break; } #endif soap_in_int_ext = dlsym(handle, "soap_in_int"); if ((error = dlerror()) != NULL) { break; } #ifndef WITH_NOIDREF soap_getelement_ext = dlsym(handle, "soap_getelement"); if ((error = dlerror()) != NULL) { break; } soap_putindependent_ext = dlsym(handle, "soap_putindependent"); if ((error = dlerror()) != NULL) { break; } #endif soap_out_int_ext = dlsym(handle, "soap_out_int"); if ((error = dlerror()) != NULL) { break; } #ifndef WITH_NOIDREF soap_markelement_ext = dlsym(handle, "soap_markelement"); if ((error = dlerror()) != NULL) { break; } #endif error = NULL; break; }while(error); if (NULL != error) { s8 err_info[200]; /* 发生错误 */ WEB_SEND_DEBUG_s(error); snprintf(err_info, sizeof(err_info), "Load web service method %s failed:%s", method, error); return (u32)ws_send_soap_error(ws_env, err_info); } /* 建立管道,准备向web service发送信息 */ (void)pipe((int *)file_to_ws); /* 建立管道,准备向从web service接收信息 */ (void)pipe((int *)file_from_ws); /* 通知web service要执行的方法,格式形如<ws:getSegmentById/> */ pchar = "<ws:"; ret = (u_int32_t)write(file_to_ws[1], pchar, strlen(pchar)); pchar = method; write(file_to_ws[1], pchar, strlen(pchar)); // pchar = "/>"; // <nop/>用于表示参数,让gsoap可以正常处理 pchar = "><nop/></ws:"; write(file_to_ws[1], pchar, strlen(pchar)); pchar = method; write(file_to_ws[1], pchar, strlen(pchar)); pchar = ">"; write(file_to_ws[1], pchar, strlen(pchar)); close(file_to_ws[1]); /* 准备执行web service */ ws_begin_exe(ws_env); /* 设置web service执行时的输入输出流 */ ws_env->recvfd = file_to_ws[0]; ws_env->sendfd = file_from_ws[1]; /* 生成内部执行环境 */ // memset(internal_env, 0, sizeof(WS_INTERNAL_ENV)); 不能清0,只能做自己的赋值 internal_env->internal_run = BOOL_TRUE; internal_env->ws_req_res = ws_req_res; /* web service执行环境挂入内部执行环境 */ ws_plug_intl_env(ws_env, internal_env); /* 执行 web service */ ret = (u_int32_t)soap_serve_request(ws_env); if (WS_OK != ret) { soap_set_fault(ws_env); ret = WS_OK; } /* 关闭web service输入流 */ close(file_from_ws[1]); close(file_from_ws[0]); close(file_to_ws[0]); ws_env->user = NULL; return ret; }
/** * 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