How to retrieve the hostname from an Alfresco Share webscript

若如初见. 提交于 2019-12-11 04:03:14

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/13491604/how-to-retrieve-the-hostname-from-an-alfresco-share-webscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!