Execute a Servoy method from a stand alone Java Program

Hi all,

I know we can execute servoy methods using Servoy Headless Client (SHC) using JSP.

Is it possible to execute a servoy method from a stand alone Java program using SHC API?

If possible can anyone show me a sample code on how to execute a servoy method from a stand alone Java Program.

Any help would be appreciated.

Regards
jdcunha

Can’t show you sample code right now but it should be pretty easy to do this, just tell your java application to load a URL pointing to the correct jsp page.
If you need to get back a result just be sure to print the result to the web page and parse it back in your java app.

The headless client classes cannot be used outside Servoy’s application server.

You can, as Nicola suggests, connect from your Java application to the jsp’s that run inside the Servoy Application Server and utilize the Headless Client.

Paul

When you don’t want to do jsp, we have a plug-in that fires up a servlet on the server.
When a request comes in a headless client is fired and runs the method.
It can also return a result.

Another feature is that you can have it broadcast the request to all running clients based on the request.

And that is it… It does not do anything more than that.

It has been an internal plug-in so far but when you want we can make it a commercial plug-in.

When you want that please contact us via http://www.it2be.com/index.php/contact

Hi all,

Thanks for the prompt replies.

I need to email a pdf report every day at 12:00pm. In Servoy client we have a Scheduler plug-in that can add a cronjob to execute a global method that will do it. But it only runs on the client and not on the Servoy Server. One way would be to have a client running on machine 24/7.

But is there a way for me to implement this on the Servoy Server as a service or a process that wakes up at 12:00pm on the server and execute the servoy method that emails a pdf report every day at 12:00pm.

I like the way where I can write a java program to connect with the SHC jsp page and then parse the result. But I just want to explore if there are any other options that I am missing.

Regards
James Dcunha
The Support Group

To run processes serverside to do something at 12 at night: use a servoy module and run it as batchprocessor on the server. That what batchprocessors are for :)

Hi All,

Would like to thank everyone for helping me out.

I created a test batch processing script which basically sets a test cron job to store a file on the desktop every minute. It works on the client but not when executed as a batch process.

I have posted it under Servoy Deployment>Servoy Server
viewtopic.php?f=5&t=11867

Please let me know if I have missed something.

Regards
James

I created a test batch processing script which basically sets a test cron job to store a file on the desktop every minute. It works on the client but not when executed as a batch process.

What desktop? That of the client?
Make sure there are no dialogs called etc since you are working headless.
Is your path relative? If not, check the user for your application server. It could be the administrator.
Anything in your server log file?

Hi Marcel
I have written a simple test scheduler script to store file on a windows servoy server machine every minute. When I execute the methods on the servoy client on the servoy server machine it works fine.

When I execute as a Batch Process using Servoy Server admin interface. I get the following error on the server log

I tried to extract the file.jar in order to check the error for com.servoy.extensions.plugins.file.FileProvider.js_writeTXTFile(FileProvider.java:647). But there was no java files provided along with the class files

java.awt.HeadlessException
     at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source)
     at java.awt.Window.<init>(Unknown Source)
     at java.awt.Frame.<init>(Unknown Source)
     at java.awt.Frame.<init>(Unknown Source)
     at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(Unknown Source)
     at javax.swing.SwingUtilities.getSharedOwnerFrame(Unknown Source)
     at javax.swing.JOptionPane.getRootFrame(Unknown Source)
     at javax.swing.JOptionPane.getWindowForComponent(Unknown Source)
     at javax.swing.JFileChooser.createDialog(Unknown Source)
     at javax.swing.JFileChooser.showDialog(Unknown Source)
     at javax.swing.JFileChooser.showSaveDialog(Unknown Source)
     at com.servoy.j2db.util.FileChooserUtils.getAWriteFile(FileChooserUtils.java:18)
     at com.servoy.extensions.plugins.file.FileProvider.js_writeTXTFile(FileProvider.java:647)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
     at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:347)
     at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:73)
     at org.mozilla.javascript.gen.c7._c0(cron_method:9)
     at org.mozilla.javascript.gen.c7.call(cron_method)
     at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
     at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3122)
     at org.mozilla.javascript.gen.c7.call(cron_method)
     at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:45)
     at com.servoy.j2db.plugins.ClientPluginAccessProvider$MethodExecutor.run(ClientPluginAccessProvider.java:18)
     at com.servoy.j2db.server.headlessclient.SessionClient.invokeLater(SessionClient.java:292)
     at com.servoy.j2db.plugins.ClientPluginAccessProvider$1.run(ClientPluginAccessProvider.java:5)
     at com.servoy.j2db.util.TaskExecuter.run(TaskExecuter.java:9)
     at java.lang.Thread.run(Unknown Source)

This is the function that is executed on startup:

function test()
{
       //My startup script on open of the solution
	var batch_command = arguments[0];
	if(batch_command == "test")
		{
		 globals.create_cron_jobs();
		}
}

function create_cron_jobs()
{
	plugins.scheduler.addCronJob('1min','0 0/1 * * * ?',globals.cron_method);
}

function cron_method()
{
        // Method that creates the file on the PC machine
	var fileName = 'test.txt';
	var filePath = plugins.file.getDesktopFolder();
	filePath +="/" + fileName;
	plugins.file.writeTXTFile(filePath,'test');
}

On the Servoy admin Batch Processor interface I have the following parameters sets
Solution: test_solution
args: test
User: Admin
Startup Msg: -Empty-
Status: Is running

when i check the logs it actually runs the cron_method() every 1 minute and throws the error on the server log file.

Any help would be appreciated?

Regards
James Dcunha

Which version of Servoy are you using?
It is either this:

Make sure there are no dialogs called etc since you are working headless

or it is an (old) issue with the file plugin.

Hi Marcel,

Here is the following information:
Server Information
Servoy version 4.1.0 -build 651, repository version 35

JDK Information
java.vm.name=Java HotSpot™ Client VM
java.vm.version=11.0-b16
java.vm.info=mixed mode
java.vm.vendor=Sun Microsystems Inc.

Operating System Information
os.name=Windows XP
os.version=5.1
os.arch=x86

Let me know if you need any additional information. Thanks a lot for your help

Regards
James Dcunha