Page 1 of 1

6.0.7 - Headless Client Plug-in getClient Broken?

PostPosted: Wed Sep 19, 2012 9:05 pm
by bobcusick1332964082
Maybe someone can help me out here - I'm banging my head against a wall on this one.

I'm starting up a headless client on the server via code and executing a global method. So far, so good.

However, I then want to be able to use that spawned client for other users to do the same thing.

So, I'm using:

Code: Select all
headlessClient = plugins.headlessclient.getClient(headlessID)


I have the UUID of the client (as I captured it after I created it) - but still the call to getClient gives me a null or invalid result.

I've tried a number of approaches - including this one:

Code: Select all
var headlessClient = null;
var cnt = application.getClientCountForInfo("PDFBOT");

if(cnt == 0) {
   //not running - create it
   // Creates a headless client that will open the given solution.
   headlessClient = plugins.headlessclient.createClient("myBotSolution", "userName", "password", null);

} else {
   //running - get the ID
   var botID = null;
   var clients = plugins.maintenance.getConnectedClients();
   for (var i = 0; i < clients.length; i++) {
      if(utils.stringPatternCount(clients[i].getUserName(),"PDFBOT") > 0) {
         //found the BOT
         var botID = clients[i].getClientID();
         break
      }
   }

/*** THIS CORRECTLY RETURNS THE HEADLESS CLIENT ID OF:  "FBDAD129-4DF2-4CC4-8508-747EFC23EFC8" ***/

   if(botID) {
      // Gets an existing headless client for the given client uuid.
      headlessClient = plugins.headlessclient.getClient(botID);  // <----- HERE IS WHERE IT'S NOT WORKING
   } else {
      application.output("Your PDF generation request FAILED because we couldn't find a running bot." );
      return;
   }
}

if (headlessClient != null && headlessClient.isValid()) {
   var x = new Object();
   x.value = myRecordID;
   headlessClient.queueMethod(null, "runCronMethod", [x], globals.PDFBotCallback);

} else {
   application.output("Error - Your PDF generation request FAILED to queue");
}


Is there anything obvious I'm missing here?

Any help would be appreciated!

Bob

Re: 6.0.7 - Headless Client Plug-in getClient Broken?

PostPosted: Tue Oct 16, 2012 3:44 pm
by Hans Nieuwenhuis
Hi Bob,

did you find out what the issue was ?
I have the same problem.

Regards,

Re: 6.0.7 - Headless Client Plug-in getClient Broken?

PostPosted: Wed Oct 17, 2012 12:41 pm
by rgansevles
The headless client plugin has manages its own client ids, these are not the same as the internal client id which is displayed on the admin page.
You can get a handle to the client using the getClientID() method

Code: Select all
   var client = plugins.headlessclient.createClient(solutionName,username,password,solutionOpenMethodArgs);
   var clientHandle = client.getClientID();
   
   ...
   
   client = plugins.headlessclient.getClient(clientHandle);


Rob

Re: 6.0.7 - Headless Client Plug-in getClient Broken?

PostPosted: Sun Nov 18, 2012 10:28 am
by antonio
rgansevles wrote:The headless client plugin has manages its own client ids, these are not the same as the internal client id which is displayed on the admin page.
You can get a handle to the client using the getClientID() method


Thanks Rob, I thought I was going nuts. Could you add an entry in the docs to explain?

For a client created with plugins.headlessclient.createClient() is there any way to get the corresponding client ID that's displayed on the admin page?

Re: 6.0.7 - Headless Client Plug-in getClient Broken?

PostPosted: Mon Nov 19, 2012 11:30 am
by rgansevles
Tony,

We have to keep the internal client id hidden for security reasons, so unfortunately you cannot that client id.

Maybe application.addClientInfo() can help you here, you can set some info on the admin page that is specific to your client instance.

Rob

Re: 6.0.7 - Headless Client Plug-in getClient Broken?

PostPosted: Mon Nov 19, 2012 11:40 am
by antonio
Thanks Rob, good suggestion.
A note in the docs would be helpful, to the effect "the client ID reported by hc.getClientID() is unrelated to the client ID displayed...."

Re: 6.0.7 - Headless Client Plug-in getClient Broken?

PostPosted: Mon Nov 19, 2012 12:47 pm
by rgansevles
Will do.

Rob