Hi Roger
You are right, "ACTIVATE" creates a new instance if none already exists under the name.
We also have a REST interface and everything is hidden in "real" instances. Even for UHTTP, a separate instance is created via NEWINSTANCE :-)
Ingo
here is a detail from the lowest level
IF($AAK_HND_UHTTP$=="")
newinstance "UHTTP", $AAK_HND_UHTTP$
$AAK_HND_UHTTP$->"SET_FLAGS"(8) ; Send headers with all methods. By default, headers are sent only on the POST and PUT methods.
ENDIF
IF($AAK_TOKEN$!="")
putitem/id/case v_HEADER, "access_token",$AAK_TOKEN$
ENDIF
IF(0) putitem/id/case v_HEADER, "Content-Type", "text/xml; charset=UTF-8"
IF(0)
IF($USE_JSON$)
putitem/id/case v_HEADER, "Content-Type", "application/json; charset=UTF-8"
ELSE
putitem/id/case v_HEADER, "Content-Type", "application/xml; charset=UTF-8"
ENDIF
ENDIF
v_HEADER_IN = v_HEADER
v_CONTENT_OUT = v_CONTENT_IN
IF(0)
IF(v_SEC_LVL_U)
call LP_MELD("HTTP/XML %%v_METHOD%%% '%%v_URL_PART2%%%")
ELSE
call LP_MELD("HTTP/XML %%v_METHOD%%% URL=***")
ENDIF
ENDIF
REPEAT
$AAK_HND_UHTTP$->"READ_CONTENT"($99)
UNTIL($status!=1)
$AAK_HND_UHTTP$->"SEND"("%%$AAK_URL_BASE$%%v_URL_PART2%%%",v_METHOD, "", "",v_HEADER, v_CONTENT_OUT, v_STS_RSP)
v_STS_SND = $status
WHILE(v_STS_SND == 1 || (v_STS_SND>=200 && v_STS_SND<=299 ) )
$AAK_HND_UHTTP$->"READ_CONTENT"($99)
IF($status<0) BREAK
v_STS_SND = $status
IF(v_STS_SND!=1 && (v_STS_SND<200 || v_STS_SND>299) ) BREAK
v_CONTENT_OUT = $concat(v_CONTENT_OUT,$99)
ENDWHILE
IF(0)
IF(v_SEC_LVL_U)
call LP_MELD("HTTP/XML %%v_METHOD%%% '%%v_URL_PART2%%%Ä : STS=%%v_STS_SND%%%/%%v_STS_RSP%%%")
ELSE
call LP_MELD("HTTP/XML %%v_METHOD%%% URL=*** : STS=%%v_STS_SND%%%/%%v_STS_RSP%%%")
ENDIF
ENDIF
IF(v_STS_SND<0)
IF(v_SEC_LVL_U)
call LP_ERR("UHTTP error %%v_STS_SND%%% : %%v_METHOD%%% '%%v_URL_PART2%%%'")
ELSE
call LP_ERR("UHTTP error %%v_STS_SND%%% : %%v_METHOD%%% URL=***")
ENDIF
RETURN(v_STS_SND)
ENDIF
IF(v_STS_SND==404)
SELECTCASE $uppercase(v_METHOD)
CASE "DELETE"
RETURN(<UIOSERR_OCC_NOT_FOUND>)
ENDSELECTCASE
WHILE($scan(" %%"",v_CONTENT_OUT[1:1])>0) v_CONTENT_OUT = v_CONTENT_OUT[2]
IF($uppercase(v_CONTENT_OUT[1:16])=="RECORD NOT FOUND")
RETURN(<UIOSERR_OCC_NOT_FOUND>)
ENDIF
ELSEIF(v_STS_SND==403) ; 28.11.2018,IST
RETURN(-9999)
ENDIF
IF(v_STS_SND>=400 || v_STS_RSP>=400)
call LP_DBG_REST_ERR1(v_METHOD,v_URL_PART2,v_STS_SND,v_HEADER_IN,v_CONTENT_IN,v_STS_RSP,v_HEADER,v_CONTENT_OUT,v_SEC_LVL)
RETURN($status)
ENDIF
IF(0) ; DBG
call LP_DBG_REST_ERR1(v_METHOD,v_URL_PART2,v_STS_SND,v_HEADER_IN,v_CONTENT_IN,v_STS_RSP,v_HEADER,v_CONTENT_OUT,v_SEC_LVL)
ENDIF
RETURN(v_STS_RSP)
------------------------------
Ingo Stiller
Aareon Deutschland GmbH
------------------------------
Original Message:
Sent: 09-03-2024 01:31
From: Roger Wallin
Subject: Uniface REST API
Hi Ingo,
I suppose that you are right, it would be more efficient not to "kill" the instance. Actually I was a bit surprised myself as I saw the Exit.
However what about "all further calls will fail", I suppose using "activate" will just start a new instance of the component.
Isn't it just about how you want the handle the instance of the component.
------------------------------
Roger Wallin
Abilita Oy
Original Message:
Sent: 09-02-2024 12:17
From: Ingo Stiller
Subject: Uniface REST API
Hi Roger
I just saw that you used "EXIT" in an operation. that's not a good idea
if(P_HTTPSTAT<0) exit(P_HTTPSTAT)
This exit kills your instance of the component, all further calls will fail.
Use RETURN(P_HTTPSTAT) instead :-)
Ingo
------------------------------
Ingo Stiller
Aareon Deutschland GmbH
Original Message:
Sent: 08-30-2024 02:04
From: Roger Wallin
Subject: Uniface REST API
We get the answer in a changed vContent (json in)
operation GETBYSOSSECNO params string P_URI : IN string P_SIGNUM : IN string P_MUNICIPALITY : IN string P_TOKEN : IN struct P_STRUCTASW : OUT numeric P_HTTPSTAT : OUT endparams variables string vJson string vContent, vHeaders, vResponse string strStatBeg string vUri handle vUHTTP struct vStruct endvariables call MakeJsonSignum(P_SIGNUM, P_MUNICIPALITY, vJson) ;Define nested struct and convert to Json newinstance "UHTTP", vUHTTP vUHTTP->SET_FLAGS(10) vURI = P_URI ;Create list of headers putitem/id vHeaders, "Content-Type", "application/json" putitem/id vHeaders, "Authorization", "Bearer %%P_TOKEN%%%" vContent=vJson ; Call the UHTTP.SEND operation P_HTTPSTAT = 0 P_HTTPSTAT = vUHTTP->SEND(vURI, "POST", "", "", vHeaders, vContent, vResponse) if(P_HTTPSTAT<0) exit(P_HTTPSTAT) else strStatBeg = "%%P_HTTPSTAT%%%" strStatBeg = strStatBeg[1,1] if(P_HTTPSTAT == 404 | P_HTTPSTAT == 200) jsonToStruct vStruct, vContent P_STRUCTASW = vStruct->result deleteinstance vUHTTP elseif(strStatBeg="1" | strStatBeg="3" | strStatBeg="4" | strStatBeg="5") ;Tex 503 "HTTP/1.1 503 Service Unavailable" exit(P_HTTPSTAT) else jsonToStruct vStruct, vContent P_STRUCTASW = vStruct->result deleteinstance vUHTTP endif endifend; operation GETBYSOSSECNO
------------------------------
Roger Wallin
Abilita Oy
Original Message:
Sent: 08-29-2024 02:39
From: Stéphane PFEFER
Subject: Uniface REST API
Hello,
We need to implement a REST API that will call a REST WebService of our ERP (JD Edwards).
Can anyone share a simple REST API Call created with Uniface, so I don't need to perform too many tries and errors before I get it working correctly.
Thanks,
Stephane
------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------