Headless Client use

Hi All,

I try to use Headless Client but without success.

I have a solution “Sola”
I have a form “FormA” which contains a method “methA” and a callback method
.

I have tried different syntax:

function onActionLaunchClient()
{
         client = plugins.headlessclient.createClient('Sola','login','pwd',null);
         // I tried this
	client.queueMethod(null,"forms.FormA.methA",["something"],callback);
       // I tried this
        client.queueMethod(null,"FormA.methA",["something"],callback);
       // I tried a global method
        client.queueMethod(null,"globalMethod",["something"],callback);
}
function methA(param) 
{
	// do something
}

function callback(event) {
	 // do some stuff
   if (JSClient.CALLBACK_EVENT == event.getType())
   {
      // handle normal execute of remote method 
	   application.output("work");
   }
   else if (JSClientC.ALLBACK_EXCEPTION_EVENT == event.getType())
   {
      // handle exception execute of remote method 
	   application.output("notwork");
   }
   client.shutdown()
}

In all the case I get CALLBACK_EXCEPTION_EVENT in my callback method :(

If someone can explain me what am I doing wrong.

Thank you in advance for your support

If you look at the sample code for the queueMethod function, you see this:

// this calls a 'remoteMethod' on the server as a global method, because the context (first argument is set to null), you can use a formname to call a form method
	jsclient.queueMethod(null, "remoteMethod", [x], callback);

So, translated to your example, the following should work:

         client = plugins.headlessclient.createClient('Sola','login','pwd',null);
         // I tried this
   client.queueMethod('FormA',"methA",["something"],callback);
        // I tried a global method
        client.queueMethod(null,"globalMethod",["something"],callback)

So, the latter method queued, the global method should’ve worked already in your example. Are you sure you got the name correct?
In the sample code you can also see that the details of the exception that occurred is stored in teh data property of the event:

else if (event.getType() == JSClient.CALLBACK_EXCEPTION_EVENT)
	{
		application.output("exception callback, name: " + event.data);
	}

You can check this to get more info on what exactly happened.

Paul

Thank you Paul for the reply.

With the formName in the context param, I’m getting now a CALLBACK_EVENT, but my method is not called!!

I have the following error in my servoy_log.txt

2010-08-26 09:51:03,868 ERROR [authenticator] com.servoy.j2db.util.Debug - A Plugin with the internal name file has already been loaded
2010-08-26 09:51:03,915 ERROR [authenticator] com.servoy.j2db.util.Debug - A Plugin with the internal name file has already been loaded
2010-08-26 09:51:34,603 ERROR [authenticator] com.servoy.j2db.util.Debug - A Plugin with the internal name file has already been loaded
2010-08-26 09:51:34,634 ERROR [authenticator] com.servoy.j2db.util.Debug - A Plugin with the internal name file has already been loaded
2010-08-26 09:51:52,775 ERROR [AWT-EventQueue-0] com.servoy.j2db.util.Debug - A Plugin with the internal name file has already been loaded

My solution has a mustAuthenticate flag on, so I have a login and authenticator modules.

Any suggestion are more than welcome

Hi Othmane,

I don’t thing these errors are related to the headless_client plugin: it indicates that you seem to have 2 file.jar in your class path (check in /beans and /plugins maybe?)

Hope this helps,

Thank you Patrick,

You’re right, I forgot to keep off an old version of file.jar from my plugins folder.

Now I have no error in my log file, but my method is not called by the headless_client!!!

I noted then even if I provide a methodName that doesn’t exist or formname that dosn’t exist too
it doesn’t generate an exception!!

I really don’t undersatand why my method is not called and what is strange, is that i dont have any error.

Any suggestion guys to debug that?

I made a sample solution that not require Authentication.
In this case my method is called!!!

should I authenticate the headless_client somewhere?
I guess that createClient do that?

Thank you for any suggestion

When you create the client, you have to supply credentials, you do so in your code already:

client = plugins.headlessclient.createClient('Sola','login','pwd',null);

I assumed you were passing in correct credentials?

Paul

yes of course,I provide the right credentials.

I tried to trace where the headless_client passes using application.output with LOGINLEVEL.EROOR
I see that it goes up the onload of form login.
I tried to re-authenticate it with security.authenticate (‘module_authenticator’ methLogin, [params]).
I saw that it is authenticated Successfully But What Happened after, this is my big question!

Thank you for your help

what happens if you just use security.login() instead of security.authenticate()

Hi Johan,

I tried security.login() directly in my module Login instead of doing it in the authenticator! module but without success.

Thank you for your support

Hi all,

I’ve made a simple solution that illustrates my problem of launching a headlessClient through a solution that requires an authentication.

The solution includes three modules:

main solution: testHeadlessClient
Solution login: SGM_LOGIN
solution authenticator: SGM_AUTHENTICATOR

To test the behaviour

  1. launch the solution
  2. click on the login button to log
  3. click on the button “Launch headless client” who creates a client and associates to it the method “CallMe” which is simply an output of the string “headless method executed” with a LOGGINLEVEL.ERROR.

When I disable authentication (mustAuthenticate = false and loginSolutionName = default), everything works perfectly and my method “CallMe” is called by the headlessClient.

When I enable authentication (mustAuthenticate = true and loginSolutionName = SGM_LOGIN), the headless client is created and the onload method of my login form is called but unfortunately, the method “CallMe” is not called by the headlessClient!:frowning:

I really do not know what else to test and I really need to use the headless client to associate to it a long process that we have to do in a solution we are developping in version 5.2.
We have another solutions developped with version 5.1.4 witch use batchProcessor which is in effect a headlessClient, So I’m wondering if they will still work if we passes to the 5.2 version :|
I hope that I was clear enough and If someone can explain to me what I’m doing wrong, that would be very appreciated.

Thank you for your support

testHeadlessClient.servoy (21 KB)

please file (viewtopic.php?f=8&t=6062) a case with this information.

Ok, I’ve opened a case and its id is 317807.

Thank you for your support

Othmane,

Can you try the same solution in a real server-smartclient setup, so not in developer?

Rob

Hi Rob,

I tried the solution in a real server-smartclient as you suggested and it works :!:
I hope there’s an explanation for why it does longer works on developer

I opened a case about that, what should I do?

Thank you for your support

This will be fixed in Servoy 5.2.2

The problem was caused by a threading difference in smart client and web client/smart client in developer

Rob

Ok nice, Thank you for the information

Hi Rob,

I tried the submitted sample solution in 5.2.1+ from latest SVN source (so containing your fix - rev 1031) and found that although it is now running fine in Smart client, this is still not working in web client.

In Web client, I ran into that Exception:

Exception in thread "pool-5-thread-1" org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-5-thread-1
	at org.apache.wicket.Application.get(Application.java:179)
	at com.servoy.j2db.server.headlessclient.SessionClient.unsetThreadLocals(SessionClient.java:645)
	at com.servoy.j2db.server.headlessclient.SessionClient$3.afterExecute(SessionClient.java:1252)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Which is obviously in a Runnable, but I’m not sure where it is called from.

Also after a try in web client (and the above exception occuring), relaunching Smart client and trying again fail to call the queued method (although the login works) anymore.

Any idea?

Patrick,

The exception is a different issue, not caused by my fix.
This is fixed in next release as well.

Thanks,

Rob