web service and file plugin

Hi!

If have a restful web service (solution A) that uses the file plugin to create/manipulate files/folders. And I have another solution(solutionB) that calls solutionA. Doing such will the function createnewfile create the file on the client or server?

thanks!

I have a rest web service solution. When I run in developer mode.

	var directory_for_backup = "dbbackupXXX"
	var d = plugins.file.convertToJSFile(plugins.file.getDefaultUploadLocation()+"\\backup\\"+directory_for_backup);
	application.output("1..."+ new Date(), LOGGINGLEVEL.WARNING)
	if (!plugins.file.createFolder(d))
		application.output("Folder could not be created.");
	
	var f = plugins.file.createFile(d+"\\xyz.sql");

	// Create the file on disk.
	if (!f.createNewFile())
		application.output("The file could not be created.");

	plugins.it2be_tools.register("12345");

	application.output(plugins.it2be_tools.zip(d.getAbsolutePath(), true));
	 plugins.file.getRemoteFolderContents("//backup//")

The getRemoteFolderContents() returns null. If I try to change it to “/” it still return null.

What does plugins.file.getDefaultUploadLocation() returns then?
And you shouldn’t use //, one / is enough.

ptalbot:
What does plugins.file.getDefaultUploadLocation() returns then?
And you shouldn’t use //, one / is enough.

C:\Development\team servers\Servoy_6_Rogel\application_server\server\webapps\ROOT\uploads

Anything significant in the servoy_log.txt file?

ptalbot:
Anything significant in the servoy_log.txt file?

I am not sure what happened but it is now working. I did not make any code changes. As far as I can remember is I updated the servoy version to address the synchronizedb error. thanks!

follow-up question.
i ran the web service through developer

test using other machine
http://192.168.0.120:50020/examples/res … tpage.html

i was able to go into the code

 var list = plugins.file.getRemoteFolderContents('/', '.zip');	
	 if (list) {
	 	var monitor = plugins.file.streamFilesFromServer("C:/develop", list);
	 }

“C:/develop” is existing in the machine where I used to call the URL(http://192.168.0.120:50020/examples/res … tpage.html)

but i get an error. please help.

2011-09-27 07:02:34,532 ERROR [http-50020-1] com.servoy.extensions.plugins.rest_ws.RestWSPlugin - /servoy-service/rest_ws/backuprestore_ws/ws_backuprestore
org.mozilla.javascript.WrappedException: Wrapped java.lang.IllegalArgumentException: The first argument must represent an existing folder or an array of files to receive the server files. (C:\Development\team servers\Servoy_6_Rogel\workspaces\backuprestore_ws\forms\ws_backuprestore.js#378)
	at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1828)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:199)
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:367)
	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)

You are calling a web service right? And the call to plugins.file.streamFilesFromServer(“C:/develop”, list); is located in the ws_xxx method, I suppose?
This means that the call to the file plugin is evaluated on the server-side not on the client-side…
So, do you have a “C:/develop” on your server-side (your 192.168.0.120 server)?

Actually this doesn’t make too much sense because you are calling a method to streamFilesFromServer, when you are already on the server-side.

ptalbot:
You are calling a web service right? And the call to plugins.file.streamFilesFromServer(“C:/develop”, list); is located in the ws_xxx method, I suppose?

Yes

ptalbot:
So, do you have a “C:/develop” on your server-side (your 192.168.0.120 server)?

No

ptalbot:
Actually this doesn’t make too much sense because you are calling a method to streamFilesFromServer, when you are already on the server-side.

The big question is how will I be able to send the file to the client machine? :(
If returning the file directly is not possible then I think I will just return the location of the file and then the client will do the streamfilesfromserver? Does it make sense?

why are you trying to do that with a web service solution?

It seems to me that you just should use a Web/Headless client that where you send a deeplink to that calls plugins.file.writeFile() with the right arguments to that a user gets in the browser the file.

A browser shouldn’t really talk the a web service, that is more for machine<->machine communication

jcompagner:
why are you trying to do that with a web service solution?

It seems to me that you just should use a Web/Headless client that where you send a deeplink to that calls plugins.file.writeFile() with the right arguments to that a user gets in the browser the file.

A browser shouldn’t really talk the a web service, that is more for machine<->machine communication

I chose a web service solution so other systems can access the “service” to do the “backup” of their data. For as long as the process is performed on the server and the client machine will be able to get the copy of the file that is ok.

I have not done a web/headless client before. I will look into that. If i choose:
Headless – my solutionA will be a normal solution and that I will need to create a jsclient in solutionB to establish communication?
Web – my solutionA will be a normal solution and that I just need to add it as a module in solutionB and just call the method directly?

Is this the right way to do it?

first of all what are the other systems? are those also servoy solutions, smart clients running from that server?

Its for me not clear what you are trying to do.

jcompagner:
first of all what are the other systems? are those also servoy solutions, smart clients running from that server?

Its for me not clear what you are trying to do.

Here is the requirement.
Backup - This functionality will allow the user to backup organization data manually or automatically and save it to the local computer as a date / time stamped compressed ZIP file of SQL statements. The backup process will be done on the server
Restore - This functionality will allow the TSM user to replace organization data by selecting a file from a location. The restore process will be done on the server

GUI
Backup - select a local directory where the zip file will be stored
Restore - select a zip file from a local computer location

Hope this helps.

I have no answer for the thing i asked you, what is a client? is a user using a smart client? or a completely different none servoy application?

If the user uses a smart client then just create a headless client through the headless client plugin and let that make the backup on the server, give the file back to the client (as a return value or save it on a place on the server where the smart client can stream it from)

jcompagner:
I have no answer for the thing i asked you, what is a client? is a user using a smart client? or a completely different none servoy application?

smart client.

If the user uses a smart client then just create a headless client through the headless client plugin and let that make the backup on the server, give the file back to the client (as a return value or save it on a place on the server where the smart client can stream it from)

as of the moment, the process solution is in a web service and my service returns the filename to the client and the client streams it from the server.

what is the advantage of using headless client plugin against a http request/response(for the web service)? thanks!

that you don’t have to talk restfull from the smart client to the server,
But it is just like execute this method there with these arguments
and you could get the return value back just as a string or even a byte

jcompagner:
that you don’t have to talk restfull from the smart client to the server,
But it is just like execute this method there with these arguments
and you could get the return value back just as a string or even a byte

i see. the file I am pertaining to is a zip file. the problem I had with the restfull is I cannot find a way to return the zip file in the XML response body. can that be returned by the headless client? if it is more efficient.

returning a zip file to the client can be done in multiply ways
yes you could just “return bytes”
that should work

but what you also can do is save it on the server (you can use streamToServer for that even if you are already on the server)
and then return the filename where you saved it to (not the absolute filename but the filename seen from the servoy.FileServerService.defaultFolder adming property)
an then on the smart client you use streamFromServer again with that file name to stream it to the client

jcompagner:
returning a zip file to the client can be done in multiply ways
yes you could just “return bytes”
that should work

but what you also can do is save it on the server (you can use streamToServer for that even if you are already on the server)
and then return the filename where you saved it to (not the absolute filename but the filename seen from the servoy.FileServerService.defaultFolder adming property)
an then on the smart client you use streamFromServer again with that file name to stream it to the client

Thank you.