Skip to content

checkAuthorization is causing multiple connections  #1

@xwanner

Description

@xwanner

My problem is that when doing a lot of requests, opensileClientToolsR is creating a new connection for each request.

For instance

opensilexClientToolsR::connectToOpenSILEX(PHIS_user,PHIS_password,PHIS_api_url)
DataApi$new()
print(get("TOKEN_VALUE",opensilexWSClientR:::configWS))
DataApi$new()
print(get("TOKEN_VALUE",opensilexWSClientR:::configWS))

So i tried to use the ClientApi object to pass to each Api Call, so that we keep the open connection :

opensilexClientToolsR::connectToOpenSILEX(PHIS_user,PHIS_password,PHIS_api_url)
apiclient <- ApiClient$new()
DataApi$new(apiclient)
print(get("TOKEN_VALUE",opensilexWSClientR:::configWS))
DataApi$new(apiclient)
print(get("TOKEN_VALUE",opensilexWSClientR:::configWS))

But it still generates a new token !

The problem seems to come from https://github.com/OpenSILEX/opensilexClientToolsR/blob/master/R/ApiClient.r#L80

It does not check if a connection exists and it try to create a new one as soon as IDENTIFIER, PASSWORD and BASE_PATH are valid.

I think that this should be modified to

checkAuthorization <-function(){
    if(!get("USER_VALID",opensilexWSClientR:::configWS)) {
      stop("You must first connect to an OpenSILEX Instance using connectToOpenSILEXWS() function")
    }

    if(!get("TOKEN_VALID",opensilexWSClientR:::configWS)
     && !is.null(get("IDENTIFIER",opensilexWSClientR:::configWS))
     && !is.null(get("PASSWORD",opensilexWSClientR:::configWS)) 
     && !is.null(get("BASE_PATH",opensilexWSClientR:::configWS))){
      connectToOpenSILEXWS(get("IDENTIFIER",opensilexWSClientR:::configWS),get("PASSWORD",opensilexWSClientR:::configWS),get("BASE_PATH",opensilexWSClientR:::configWS))
    }
}

A workaround is to disconnect after each call to Api function but it's cumbersome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions