From b9eb15a575432bc8c48401594fcf06c045e817a7 Mon Sep 17 00:00:00 2001 From: wangkx Date: Tue, 1 Aug 2023 09:04:14 -0400 Subject: [PATCH] HPCC-30353 Export SDS data using PTree content streaming Before this change, the data read from Dali stores into a temporary file before streaming to an ESP client. With this change, the data is directly streamed to the client. Signed-off-by: wangkx --- esp/services/ws_dali/ws_daliservice.cpp | 26 ++++++------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/esp/services/ws_dali/ws_daliservice.cpp b/esp/services/ws_dali/ws_daliservice.cpp index 02ce003665d..dafeee79f5e 100644 --- a/esp/services/ws_dali/ws_daliservice.cpp +++ b/esp/services/ws_dali/ws_daliservice.cpp @@ -28,9 +28,6 @@ using namespace daadmin; #define REQPATH_EXPORTSDSDATA "/WSDali/Export" -const char* daliFolder = "tempdalifiles" PATHSEPSTR; -const unsigned daliFolderLength = strlen(daliFolder); - void CWSDaliEx::init(IPropertyTree* cfg, const char* process, const char* service) { espProcess.set(process); @@ -74,29 +71,18 @@ void CWSDaliSoapBindingEx::exportSDSData(CHttpRequest* request, CHttpResponse* r throw makeStringException(ECLWATCH_CANNOT_CONNECT_DALI, "Failed to connect Dali."); Owned root = conn->getRoot(); + response->setContent(root); - Owned workingDir = createIFile(daliFolder); - if (!workingDir->exists()) - workingDir->createDirectory(); - - StringBuffer peer, outFileNameWithPath; - VStringBuffer prefix("sds_for_%s", request->getPeer(peer).str()); - Owned io = createUniqueFile(daliFolder, prefix, nullptr, outFileNameWithPath, IFOcreaterw); - { //Force the fios to finish - Owned fios = createBufferedIOStream(io); - toXML(root, *fios); - } - - VStringBuffer headerStr("attachment;filename=%s", outFileNameWithPath.str() + daliFolderLength); + //Set "Content-disposition" header + CDateTime dt; + dt.setNow(); + StringBuffer headerStr; + headerStr.appendf("attachment;filename=sds_%u.%u.tmp", (unsigned)GetCurrentProcessId(), (unsigned)dt.getSimple()); IEspContext* context = request->queryContext(); context->addCustomerHeader("Content-disposition", headerStr.str()); - response->setContent(createIOStream(io)); response->setContentType(HTTP_TYPE_OCTET_STREAM); response->send(); - - io.clear(); - removeFileTraceIfFail(outFileNameWithPath); } void CWSDaliEx::checkAccess(IEspContext& context)