bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp) { resp.updateStatus().setCode(0); StringAttr target(req.getTarget()); StringAttr name(req.getPackageMap()); if (target.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "Target cluster parameter required"); if (name.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "PackageMap name parameter required"); DBGLOG("%s adding packagemap %s to target %s", context.queryUserId(), name.str(), target.str()); StringBuffer pmid; if (!req.getGlobalScope()) pmid.append(target).append("::"); pmid.append(name.get()); bool activate = req.getActivate(); unsigned updateFlags = 0; if (req.getOverWrite()) updateFlags |= (DALI_UPDATEF_PACKAGEMAP | DALI_UPDATEF_REPLACE_FILE | DALI_UPDATEF_CLONE_FROM | DALI_UPDATEF_SUPERFILES); if (req.getReplacePackageMap()) updateFlags |= DALI_UPDATEF_PACKAGEMAP; if (req.getUpdateCloneFrom()) updateFlags |= DALI_UPDATEF_CLONE_FROM; if (req.getUpdateSuperFiles()) updateFlags |= DALI_UPDATEF_SUPERFILES; if (req.getAppendCluster()) updateFlags |= DALI_UPDATEF_APPEND_CLUSTER; StringAttr processName(req.getProcess()); Owned<IUserDescriptor> userdesc; const char *user = context.queryUserId(); const char *password = context.queryPassword(); if (user && *user && *password && *password) { userdesc.setown(createUserDescriptor()); userdesc->set(user, password); } StringBuffer srcCluster; StringBuffer daliip; StringBuffer prefix; splitDerivedDfsLocation(req.getDaliIp(), srcCluster, daliip, prefix, req.getSourceProcess(), req.getSourceProcess(), NULL, NULL); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, processName.get()); StringArray filesNotFound; addPackageMapInfo(updateFlags, req.getInfo(), filesNotFound, processName, target, pmid, pkgSetId, daliip, srcCluster, prefix, activate, userdesc, req.getAllowForeignFiles(), req.getPreloadAllPackages()); resp.setFilesNotFound(filesNotFound); StringBuffer msg; msg.append("Successfully loaded ").append(name.get()); resp.updateStatus().setDescription(msg.str()); return true; }
bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp) { PackageMapUpdater updater; updater.setFlag(PKGADD_MAP_CREATE); updater.setFlag(PKGADD_MAP_ACTIVATE, req.getActivate()); updater.setFlag(PKGADD_MAP_REPLACE, req.getOverWrite()); updater.setFlag(PKGADD_ALLOW_FOREIGN, req.getAllowForeignFiles()); updater.setFlag(PKGADD_PRELOAD_ALL, req.getPreloadAllPackages()); updater.setPMID(req.getTarget(), req.getPackageMap(), req.getGlobalScope()); updater.setProcess(req.getProcess()); updater.setUser(context.queryUserId(), context.queryPassword()); updater.setDerivedDfsLocation(req.getDaliIp(), req.getSourceProcess()); unsigned updateFlags = 0; if (req.getOverWrite()) updateFlags |= (DALI_UPDATEF_PACKAGEMAP | DALI_UPDATEF_REPLACE_FILE | DALI_UPDATEF_CLONE_FROM | DALI_UPDATEF_SUPERFILES); if (req.getReplacePackageMap()) updateFlags |= DALI_UPDATEF_PACKAGEMAP; if (req.getUpdateCloneFrom()) updateFlags |= DALI_UPDATEF_CLONE_FROM; if (req.getUpdateSuperFiles()) updateFlags |= DALI_UPDATEF_SUPERFILES; if (req.getAppendCluster()) updateFlags |= DALI_UPDATEF_APPEND_CLUSTER; StringArray filesNotFound; updater.create(req.getPackageMap(), req.getInfo(), updateFlags, filesNotFound); resp.setFilesNotFound(filesNotFound); resp.updateStatus().setCode(0); resp.updateStatus().setDescription(StringBuffer("Successfully loaded ").append(req.getPackageMap())); return true; }
bool CWsPackageProcessEx::onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp) { resp.updateStatus().setCode(0); StringAttr target(req.getTarget()); StringAttr name(req.getPackageMap()); if (target.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "Target cluster parameter required"); if (name.isEmpty()) throw MakeStringExceptionDirect(PKG_MISSING_PARAM, "PackageMap name parameter required"); StringBuffer pmid; if (!req.getGlobalScope()) pmid.append(target).append("::"); pmid.append(name.get()); bool activate = req.getActivate(); bool overWrite = req.getOverWrite(); StringAttr processName(req.getProcess()); Owned<IUserDescriptor> userdesc; const char *user = context.queryUserId(); const char *password = context.queryPassword(); if (user && *user && *password && *password) { userdesc.setown(createUserDescriptor()); userdesc->set(user, password); } StringBuffer srcCluster; StringBuffer daliip; StringBuffer prefix; splitDerivedDfsLocation(req.getDaliIp(), srcCluster, daliip, prefix, req.getSourceProcess(), req.getSourceProcess(), NULL, NULL); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, processName.get()); StringArray filesNotFound; addPackageMapInfo(req.getInfo(), filesNotFound, processName, target, pmid, pkgSetId, daliip, srcCluster, prefix, activate, overWrite, userdesc, req.getAllowForeignFiles(), req.getPreloadAllPackages()); resp.setFilesNotFound(filesNotFound); StringBuffer msg; msg.append("Successfully loaded ").append(name.get()); resp.updateStatus().setDescription(msg.str()); return true; }
int onGetInstantQuery(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method) { if(!stricmp(method, "LogoutUser")||!stricmp(method, "LogoutUserRequest")) { CEspCookie* logincookie = request->queryCookie("RELOGIN"); if(logincookie == NULL || stricmp(logincookie->getValue(), "1") == 0) { response->addCookie(new CEspCookie("RELOGIN", "0")); StringBuffer content( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" "<head>" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" "<title>Enterprise Services Platform</title>" "</head>" "<body onLoad=\"location.href='/ws_account/LogoutUserCancel'\">" "</body>" "</html>"); response->sendBasicChallenge("ESP", content.str()); } else { response->addCookie(new CEspCookie("RELOGIN", "1")); response->setContentType("text/html; charset=UTF-8"); StringBuffer content( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" "<head>" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" "<title>Enterprise Services Platform</title>" "</head>" "<body>" "<br/><b>Relogin successful, you're now logged in as "); content.append(context.queryUserId()).append( "</b>" "</body>" "</html>"); response->setContent(content.str()); response->send(); } return 0; } else if(!stricmp(method, "LogoutUserCancel")||!stricmp(method, "LogoutUserRequest")) { CEspCookie* logincookie = request->queryCookie("RELOGIN"); response->addCookie(new CEspCookie("RELOGIN", "1")); response->setContentType("text/html; charset=UTF-8"); StringBuffer content( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" "<head>" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" "<title>Enterprise Services Platform</title>" "<script type='text/javascript'>" "function closeWin() { top.opener=top; top.close(); }" "</script>" "</head>" "<body onload=\"javascript:closeWin();\">" "<br/><b>Relogin canceled, you're now still logged in as "); content.append(context.queryUserId()).append( "</b>" "</body>" "</html>"); response->setContent(content.str()); response->send(); return 0; } else return Cws_accountSoapBinding::onGetInstantQuery(context, request, response, service, method); }
bool CEclDirectEx::onRunEcl(IEspContext &context, IEspRunEclRequest & req, IEspRunEclResponse & resp) { if (!context.validateFeatureAccess(ECLDIRECT_ACCESS, SecAccess_Full, false)) throw MakeStringException(-1, "EclDirect access permission denied."); StringBuffer user; if (!context.getUserID(user).length()) user.append(req.getUserName()); Owned <IWorkUnitFactory> factory = getWorkUnitFactory(context.querySecManager(), context.queryUser()); Owned <IWorkUnit> workunit; if (!user.length()) workunit.setown(factory->createWorkUnit(NULL, "ECL-Direct", "")); else { workunit.setown(factory->createWorkUnit(NULL, "ECL-Direct", user.str())); workunit->setUser(user.str()); } Owned<IWUQuery> query = workunit->updateQuery(); query->setQueryText(req.getEclText()); query.clear(); const char* clustername = req.getCluster(); if (!clustername || !*clustername || strieq(clustername, "default")) clustername = defaultCluster.str(); if (!clustername || !*clustername) throw MakeStringException(-1, "No Cluster Specified"); if (!isValidCluster(clustername)) throw MakeStringException(-1, "Invalid TargetCluster %s Specified", clustername); workunit->setClusterName(clustername); if (req.getLimitResults()) workunit->setResultLimit(100); const char* snapshot = req.getSnapshot(); if (snapshot && *snapshot) workunit->setSnapshot(snapshot); // Execute it SCMStringBuffer wuid; workunit->getWuid(wuid); workunit->setAction(WUActionRun); workunit->setState(WUStateSubmitted); workunit.clear(); submitWorkUnit(wuid.str(), context.querySecManager(), context.queryUser()); if (waitForWorkUnitToComplete(wuid.str(), defaultWait)) { Owned<IConstWorkUnit> cw = factory->openWorkUnit(wuid.str(), false); SCMStringBuffer resultXML; getFullWorkUnitResultsXML(context.queryUserId(), context.queryPassword(), cw.get(), resultXML); resp.setResults(resultXML.str()); cw.clear(); if (deleteWorkunits) deleteEclDirectWorkunit(factory, wuid.str()); } else { // Don't delete these ones... DBGLOG("WorkUnit %s timed out", wuid.str()); StringBuffer result; result.appendf("<Exception><Source>ESP</Source><Message>Timed out waiting for job to complete: %s</Message></Exception>", wuid.str()); resp.setResults(result.str()); } return true; }
int CSoapService::processRequest(ISoapMessage &req, ISoapMessage& resp) { ESP_TIME_SECTION("CSoapService::processRequest()"); CSoapRequest& request = *(dynamic_cast<CSoapRequest*>(&req)); CSoapResponse& response = *(dynamic_cast<CSoapResponse*>(&resp)); IEspContext* ctx = req.queryContext(); StringBuffer requeststr; Owned<CMimeMultiPart> multipart; if(Utils::strncasecmp(request.get_content_type(), HTTP_TYPE_SOAP, strlen(HTTP_TYPE_SOAP))==0 || Utils::strncasecmp(request.get_content_type(), HTTP_TYPE_TEXT_XML, strlen(HTTP_TYPE_TEXT_XML))==0) { requeststr.append(request.get_text()); } else if(!Utils::strncasecmp(request.get_content_type(), HTTP_TYPE_MULTIPART_RELATED, strlen(HTTP_TYPE_MULTIPART_RELATED))) { multipart.setown(LINK(request.queryMultiPart())); CMimeBodyPart* rootpart = multipart->queryRootPart(); if(rootpart != NULL) rootpart->getContent(requeststr); else throw MakeStringException(-1, "MultiPart root is NULL"); } else { throw MakeStringException(-1, "Request type %s not supported", request.get_content_type()); } //Parse the content auto_ptr<XmlPullParser> xpp(new XmlPullParser()); int bufSize = requeststr.length(); xpp->setSupportNamespaces(true); xpp->setInput(requeststr.str(), bufSize); int type; StartTag stag; EndTag etag; Owned<CEnvelope> req_envelope; req_envelope.setown(new CEnvelope); while((type = xpp->next()) != XmlPullParser::END_DOCUMENT) { if(type == XmlPullParser::START_TAG) { xpp->readStartTag(stag); if(!stricmp(stag.getLocalName(), SOAP_ENVELOPE_NAME)) { req_envelope->unmarshall(xpp.get()); break; } } } CHeader* req_header = req_envelope->get_header(); if(req_header != NULL) { // As headers are normally for common uses like authentication and routing, let's process it here // instead of in binding. int ret = processHeader(req_header, ctx); if(ret != 0 ) { response.set_status(ret); return 0; } } StringBuffer peerStr; ctx->getPeer(peerStr); const char* userId = ctx->queryUserId(); CBody* req_body = req_envelope->get_body(); Owned<CRpcResponse> rpc_response; rpc_response.setown(new CRpcResponse); rpc_response->setContext(req.queryContext()); Owned<CRpcCall>rpc_call; rpc_call.setown(new CRpcCall); rpc_call->setContext(req.queryContext()); try { req_body->nextRpcMessage(rpc_call.get()); rpc_call->unmarshall(xpp.get(), multipart.get()); } catch (XmlPullParserException& e) { response.set_status(SOAP_CLIENT_ERROR); response.set_err(e.getMessage().c_str()); DBGLOG("SOAP request from %s@%s. Parsing xml error: %s. Offending XML: [%s]", (userId&&*userId)?userId:"unknown", (peerStr.length()>0)?peerStr.str():"unknown", e.getMessage().c_str(), requeststr.str()); return 0; } catch (...) { response.set_status(SOAP_CLIENT_ERROR); response.set_err("Unknown error when parsing soap body XML"); ERRLOG("SOAP request from %s@%s. Unknown error when parsing: %s", (userId&&*userId)?userId:"unknown", (peerStr.length()>0)?peerStr.str():"unknown", requeststr.str()); return 0; } DBGLOG("SOAP method <%s> from %s@%s.", rpc_call->get_name(), (userId&&*userId)?userId:"unknown", (peerStr.length()>0)?peerStr.str():"unknown"); // call the rpc and set the response if(m_soapbinding != NULL) m_soapbinding->processRequest(rpc_call, rpc_response); response.set_status(rpc_response->get_status()); response.set_err(rpc_response->get_err()); Owned<CBody> res_body = new CBody; res_body->add_rpcmessage(rpc_response.get()); Owned<CEnvelope> res_envelope; res_envelope.setown(new CEnvelope(NULL, res_body.getLink())); Owned<CMimeMultiPart> resp_multipart; resp_multipart.setown(new CMimeMultiPart("1.0", "", "MIME_boundary", "text/xml", "soaproot")); res_envelope->marshall(resp_multipart); StringBuffer contenttype; StringBuffer responsestr; resp_multipart->serialize(contenttype, responsestr); response.set_content_type(contenttype.str()); response.set_text(responsestr.str()); return 0; }