Running a method on the server

Hi everybody,

I would like to create a method which will allow the user to convert a file into a pdf file. The only solution I’ve found to make an exact copy, is to use a pdf printer. But the users don’t have the same pdf printer or simply don’t have any.
So I would like to make the conversion onto the server with a printer installer on the server. But I don’t know how to run a method on the server while the client is running.

Cheers.

I had a similar need and I reported on the use of the headless client in conjunction with the servoyguy robot plugin.
Have a look at this article (http://www.servoymagazine.com/home/2008/10/article-client.html#more) to see where I created a general purpose headless client running on the server and an approach to add your own methods.
Tom

I kind of understand your method of doing it. But I need more precisions:

If,for example, I want to call the function ConvertFile2Pdf(fileName, pdfFileName) and run it on the server.
servoyguy_robot creates the headless client itself. And then you use this headless client to call your method and get back the result?!

In my case the client code would be like that?

if ( plugins.servoyguy_robot.checkAccessPassword('pwd') ) {    
        var headless_client = plugins.servoyguy_robot.getNewHeadlessClient('ConvertFile2Pdf_Solution', null, null, 'ESS_headlessClient')  
  
        if(headless_client) {  
            newFile = headless_client.runGlobalMethod('ConvertFile2Pdf', 'in','out');   
            headless_client.runGlobalMethod('PITC_appExit', '');   
        }  

...

And then you use this headless client to call your method and get back the result?!

Where do you want the result returned?

IT2Be:
Where do you want the result returned?

I would like that the client gets back the result (the pdf file).

In fact I would like that the client browse a documents database and be able to download them or send them via email in pdf format. And I need this conversion to be done by the server.

That is what I thought but I wanted to check.

What you could do, is have the client check that the file is created.
Either manually or via the scheduler. You can do that with our Tools Plug-in that has a .fileExists function for the server.

Internally we have a Plug-in that does something similar but with and for a different setup.

When you want complete freedom this plug-in goes a little bit further than the robot plug-in.

It fires up a servlet (that you can use for all kinds of work obviously) and takes a Get and Post request with a form name (optional), method name and argument (optional).
The servlet then initiates a call to a headless client.

When the process is finished an event is fired to all clients running.

The clients ‘listen’ to this event and can, obviously, recognize that it was ‘their call’ and do something with it.

When you want to see a little more of this, it will be part of my presentation at the VUG next Thursday.

Interesting. But as I already worked on the 1st solution I would like to complete it.
And, by the way, I have a problem. Here is my code:

function convert2pdf()
{
	/* Code to convert a document in pdf  (tested and working) */
}

function testRobot()
{
	if ( plugins.servoyguy_robot.checkAccessPassword('*******') ) {
		//Startup a new headless client on the server, and return a JSHeadlessClient object.
		//Optionally pass in ServerHost and ServerPort to get a connection to a different Application Server

		var headless_client = plugins.servoyguy_robot.getNewHeadlessClient('doc2pdf_test', null, null, 'ESS_headlessClient')

		if(headless_client) {
			headless_client.runGlobalMethod('convert2pdf', '');
			headless_client.runGlobalMethod('exitApp', '');
		}
		else {
			application.output('Error connecting.')
		}
	}
}

function exitApp()
{
	application.exit();  
}

So it’s quite basic for the moment: the solution if called “doc2pdf_test”. There is a form including a button. When this button is cliked it calls testRobot() which should launch the convertion on the server.
But my program is “stopped” (no more progression but no crash) at the line “if ( plugins.servoyguy_robot.checkAccessPassword(‘*******’) ) {”

The servoyguy_robot.checkAccessPassword is recorded in servoy server as required.
All these functions are Global ones.

To be honest I’m not really sure if what I’m doing is the correct procedure :?

Anything in the log?

IT2Be:
Anything in the log?

No nothing in any log :(

I know I should not ask this but are you sure you have the password set and that it is correct?

I am not familiar with the robot plugin but is there a password for the solution or is it for the plugin itself (or both)?

IT2Be:
I know I should not ask this but are you sure you have the password set and that it is correct?

I am not familiar with the robot plugin but is there a password for the solution or is it for the plugin itself (or both)?

Yes I checked the password in both the server administration page and my code: they are the same. In addition I have restarted the serverto be sure to apply the changes
In fact the password is simply used by Robot plugin to control the access of client to the server.

I might know why it’s not working. I’ve read in this thread (from June 2008) that at this period the Robot plugin wasn’t working with Servoy 4 (that I’m using). Does it still not working with Servoy 4?

By the way, on the same thread I have seen that people used more arguments for servoyguy_robot.checkAccessPassword
So, I’ve tried:

servoyguy_robot.checkAccessPassword('*********','http://localhost:8080',1099) )
//I'm running the server on my machine

But no improvement :cry:

Does it still not working with Servoy 4?

I honestly don’t know.
It is a project of ServoyGuy not ours so it might be best that you ask this on his site.

IT2Be:
I honestly don’t know.
It is a project of ServoyGuy not ours so it might be best that you ask this on his site.

No bother. I’ve just sent Scott an email about it.
Thx for your help :wink:

Sorry, I was away for a while.
The second argument of the call to the run global method is a single string with the parameters separated by comma.
So for example in your situation perhaps you could try:

newFile = headless_client.runGlobalMethod('ConvertFile2Pdf', 'in,out');

Worth a try - I made same wrong assumption too. :oops:
Tom

Thomas Parry:
Sorry, I was away for a while.
The second argument of the call to the run global method is a single string with the parameters separated by comma.
So for example in your situation perhaps you could try:

newFile = headless_client.runGlobalMethod('ConvertFile2Pdf', 'in,out');

Worth a try - I made same wrong assumption too. :oops:
Tom

Thanks, it will certainly help me in the future as I’ll probably have several parameters to send!

By the way, do you have any idea about what could cause a problem with the “servoyguy_robot.checkAccessPassword” line ?

Thx again :)

I have not used it for Servoy 4, only 3.5.7.
Perhaps Scott may have it tested for Servoy 4. Has anyone tested it for Servoy 4?

I’ve tried to avoid this test with “checkAccessPassword” in order to see if the rest was working but I have the same problem at this line:```
var headless_client = plugins.servoyguy_robot.getNewHeadlessClient(‘doc2pdf_test’, null, null, ‘ESS_headlessClient’)


So there is definitely a problem with this plugin <img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes" />

As I can’t make this robot plugin work, I’m looking at the Headless Client technology to generate my pdf on the server.
I have analysed the solution example provided with Servoy Developer. But I’m a bit confused.

The form version (Java Smart Client) isn’t running anything on the server (except the SQL queries), does it? And the Web version (JSP page) is obviously doing everything on the server.
Does it mean that the only way to run a method on the server using the Headless Client is to use a web version of your form?

For example, having a button “Get PDF”(in the smart client version) which generates (on the server) a PDF containing the information displayed on the current page, and send it to the client. Can I make this kind of function using the Smart Client or do I have to make the user use the web version because of this special functionnality?

I hope it’s clear?! :roll:

Foobrother:
The form version (Java Smart Client) isn’t running anything on the server (except the SQL queries), does it? And the Web version (JSP page) is obviously doing everything on the server.

Correct

Foobrother:
Does it mean that the only way to run a method on the server using the Headless Client is to use a web version of your form?

When you are going to create a web version of your form you could just as well use a web client. Headless Client is what I used to use to post a http request to and receive a confirmation of some sort from.
I say, used to, because I really don’t like to use JSP and for that reason I created the servlet plugin (as stated earlier).

Foobrother:
For example, having a button “Get PDF”(in the smart client version) which generates (on the server) a PDF containing the information displayed on the current page, and send it to the client. Can I make this kind of function using the Smart Client or do I have to make the user use the web version because of this special functionnality?

I guess this is answered above.