2

I'd like to know how you can know the current hostname from a Root Object in Surf.

I'm writting a webscript which serve a JNLP, so I have no page context, and ${url.context} only returns /share.

I'm looking how I can have the hostname http://foobar.com or if this is possible at all from server side.

I've been through: http://wiki.alfresco.com/wiki/Surf_Platform_-_Freemarker_Template_and_JavaScript_API# without success

plus-
  • 45,453
  • 15
  • 60
  • 73

2 Answers2

4

On the repository side, the URLs for Alfresco and Share are known. You can get all the individual parts from SysAdminParams and you can use UrlUtils to have the different parts joined together for you to give a full URL.

As far as I can tell though, these details are only ever held on the Alfresco Repository tier, and are never passed over to Share. All the absolute URLs in Share seem to be generated in the Repo and sent over

One option then is for you to change your webscript to be a repo webscript rather than a share one. That'll give you access to the appropriate beans. Share will proxy Repo webscripts for you, so you can still access it directly in Share as the logged in user. You'll want a URL a bit like /share/proxy/alfresco/my/web/script to access them.

Otherwise, create a new repo webscript that exposes the useful bits of the SysAdminParams and Share URLs, and have your share webscript fetch it (likely with caching). There are lots of examples of that too to work with.

Gagravarr
  • 47,320
  • 10
  • 111
  • 156
1

Have you tried ${url.serverPath}

Or else you can use the default alfresco-global.properties like

share.context=share
share.host=foobar.com
share.port=80
share.protocol=http

These properties can be injected anywhere you want, take look here: Accessing values from Alfresco's alfresco-global.properties file

The only thing you'll need to be aware of, is that these properties are repository related. So you can write a repo webscript which will give all the props to Share.

And since you're using Share, one can easily use client-side JavaScript to determine the host ;).

Community
  • 1
  • 1
Tahir Malik
  • 6,623
  • 15
  • 22
  • As I've explained, I'm serving some JNLP file so there is no client-side js involved. The serverPath is not defined in Share, I believe it's repository only – plus- Nov 21 '12 at 12:48
  • Ok, so you neede a Repository Webscript which will either read the properties or use url.serverPath. And send this e.g. as JSON to the Share repo. Use remote.call your repo webscript to retrieve the value – Tahir Malik Nov 21 '12 at 12:55