1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-10 22:14:35 +00:00

fix: wip - requires new mp_chop() macro to parse long JSON response

This commit is contained in:
Allan Bowe
2022-04-25 22:19:46 +00:00
parent 8bd31e6c97
commit 8484c752ed

View File

@@ -63,7 +63,7 @@
viyaresult=WEBOUT_JSON,
viyacontext=SAS Job Execution compute context
)/*/STORE SOURCE*/;
%local dbg pcnt fref1 webref i webcount var platform;
%local dbg pcnt fref1 fref2 webref i webcount var platform;
%if &mdebug=1 %then %do;
%put &sysmacroname entry vars:;
%put _local_;
@@ -106,8 +106,10 @@
%let fref1=%mf_getuniquefileref();
%let fref2=%mf_getuniquefileref();
%let webref=%mf_getuniquefileref();
%let platform=%mf_getplatform();
%if &platform=SASMETA %then %do;
/* parse the input files */
@@ -262,6 +264,83 @@
mdebug=&mdebug
)
%end;
%else %if &platform=SASJS %then %do;
/* avoid sending bom marker to API */
%local optval;
%let optval=%sysfunc(getoption(bomfile));
options nobomfile;
data _null_;
file &fname0 termstr=crlf;
infile &inref end=eof;
if _n_ = 1 then do;
put "--&boundary.";
put 'Content-Disposition: form-data; name="filePath"';
put ;
put "&driveloc";
put "--&boundary";
put 'Content-Disposition: form-data; name="file"; filename="ignore.sas"';
put "Content-Type: text/plain";
put ;
end;
input;
put _infile_; /* add the actual file to be sent */
if eof then do;
put ;
put "--&boundary--";
end;
run;
data _null_;
file &fname1 lrecl=1000;
infile "&_sasjs_tokenfile" lrecl=1000;
input;
put "Content-Type: multipart/form-data; boundary=&boundary";
put "Authorization: Bearer " _infile_;
run;
%if &mdebug=1 %then %do;
data _null_;
infile &fname0;
input;
put _infile_;
data _null_;
infile &fname1;
input;
put _infile_;
run;
%end;
proc http method='POST' in=&fname0 headerin=&fname1 out=&webref
url="&_sasjs_apiserverurl/SASjsApi/drive/file";
%if &mdebug=1 %then %do;
debug level=1;
%end;
run;
/* reset options */
options &optval;
/* SASjs services have the _webout embedded in wrapper JSON */
/* Files can also be very large - so use a dedicated macro to chop it out */
%local matchstr;
%let matchstr={"status":"success","_webout":{;
%mp_chop(&webref,match=matchstr,keep=RIGHT,offset=-1,outref=&fref1)
%let matchstr=},"log":[{;
%mp_chop(&fref1,match=matchstr,keep=LEFT,offset=1,outref=&fref2)
%if &outlib ne 0 %then %do;
libname &outlib json (&fref2);
%end;
%if &outref ne 0 %then %do;
filename &outref temp;
%mp_binarycopy(inref=&webref,outref=&outref)
%end;
%end;
%else %do;
%put %str(ERR)OR: Unrecognised platform: &platform;
@@ -269,6 +348,8 @@
%if &mdebug=0 %then %do;
filename &webref clear;
filename &fref1 clear;
filename &fref2 clear;
%end;
%else %do;
%put &sysmacroname exit vars:;