plugins.file.writeFile

Hi Alan,

I looked up one of my older projects, even logged into their application and did a download.
Works wonderful from a public server + remote client

The code that makes it work:

function downloadFile(event)
{
	var _rec = foundset.getSelectedRecord();
	var _file = _rec.file_path_relative;
	
	var _jsFile = plugins.file.convertToRemoteJSFile(_file);
	
	plugins.file.writeFile(_rec.file_name, _jsFile.getBytes(), _rec.file_extension);
}

Where the ‘file_path_relative’ column has stored something like this:

/2B6B8076-48DD-4B84-99C0-A43585E711CC/myInvoice.xml

This is the relative path to the default upload path of the server
I think this is the area where your issue could be: trying to download an absolute path which doesn’t make sense if your on a remote client (browser in this case)

Hope this helps.

ROCLASI:
Hi Alan,

So what is the topology of your network ?
Does the server have a real IP ? Is it behind a VPN? Is it behind a proxy (web) server?

I will clarify the topology. It’s on their LAN yet also has a public IP so I’m sure there’s a stack of network between it and the outside world.

Marc

It works fine on a Azure-hosted test server with the same directory structure - I think something in the network setup is causing something in the Servoy stack to go wrong.

Is it feasible to create a Servoy web service that returns a binary object, then leverage that to download the PDF?

This is some sort of Tomcat/network issue as far as I can see and I’m not getting any help from Servoy.

what is exactly your setup?
I think you have a tomcat and in front of that you have another firewall/proxy server?

And that proxy server talks to tomcat by tomcats internal ip?

Problem is that when you serve files to the browser we need to make it a full absolute url

what we do then is get the request url of tomcat (so the incoming url) and prepend that in front of the relative url (that points to that pdf)

But if you have a proxy/firewall server in front of this that talks to the tomcat server through its local ip then tomcat gives us that and we prepend the local ip

The thing is that the proxy/firewall should rewrite this. There should be rewrite rules somewhere where it sees certain ip adresses in the responses it should rewrite it to the public one.

the biggest problem here that it is not really a http header or a real redirect :(

Because this url is in the content, its in an ajax request that looks like this (you can see this in the chrome network inspector)

<?xml version="1.0" encoding="UTF-8"?><ajax-response><evaluate><![CDATA[Servoy.HTMLEdit.removeInvalidEditors();]]></evaluate><evaluate><![CDATA[storeValueAndCursorBeforeUpdate();]]></evaluate><evaluate><![CDATA[setValidationFailed(null);]]></evaluate><evaluate><![CDATA[restoreValueAndCursorAfterUpdate();]]></evaluate><evaluate><![CDATA[setStatusText('Ready');]]></evaluate><evaluate><![CDATA[showurl('http://localhost:8080/servoy-webclient/resources/servoy/resources',0,false,true,false);]]></evaluate><evaluate><![CDATA[clearDoubleClickId('id5')]]></evaluate></ajax-response>

there you see that “showurl” that has in my example localhost:8080

So currently you have to have some rewrite rull that rewrites that too the public ip…

We could if needed do this rewrite maybe in servoy, where you then say in a property on the admin page what the public ip should be.
Or maybe this is also set in the headers somehow where we could potentally extract it (not sure if that is always the case)

Johan

Sorry only just saw your reply.

The topology is possibly slightly unusual in that it is a Windows Server 2008 server that is hosting Servoy. It has a publicly visible IP address which end users hit, however it also is on the client’s LAN with a private IP. So WriteFile() seems to be favouring the private IP when building the URL for the browser, and there is no mechanism for overriding this within the Servoy stack.

Providing an Servoy admin page setting to provide the public IP would be great, do I have to file that as a request?

Make a case for this yes.

Okay, it turns out that the server is behind a product called Sophos UTM Web Server Protection. This has a per-server ‘pass host header’ setting which was disabled but when enabled appears to have solved thr problem, and WriteFile() acts as expected in this scenario.

When it’s not permissions, it’s always a bloody firewall or something. :P