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.
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.
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.
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
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 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.