Skip to content

Commit

Permalink
Merge pull request #17814 from wangkx/wsdali_export_streaming_master
Browse files Browse the repository at this point in the history
HPCC-30353 Export SDS data using PTree content streaming

Reviewed-By: Anthony Fishbeck <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Oct 24, 2023
2 parents d6980eb + b9eb15a commit e22c97b
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions esp/services/ws_dali/ws_daliservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -74,29 +71,18 @@ void CWSDaliSoapBindingEx::exportSDSData(CHttpRequest* request, CHttpResponse* r
throw makeStringException(ECLWATCH_CANNOT_CONNECT_DALI, "Failed to connect Dali.");

Owned<IPropertyTree> root = conn->getRoot();
response->setContent(root);

Owned<IFile> workingDir = createIFile(daliFolder);
if (!workingDir->exists())
workingDir->createDirectory();

StringBuffer peer, outFileNameWithPath;
VStringBuffer prefix("sds_for_%s", request->getPeer(peer).str());
Owned<IFileIO> io = createUniqueFile(daliFolder, prefix, nullptr, outFileNameWithPath, IFOcreaterw);
{ //Force the fios to finish
Owned<IFileIOStream> 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)
Expand Down

0 comments on commit e22c97b

Please sign in to comment.