From within a groovy service I'd like to determine the server-name of the TM server running the groovy service. The best way so far I've come up with is to pull it from the database using
select context_path from portal where portal_oid = 1
where portal_oid = 1 is TM, I could also use portal.name = 'Transaction Manager'
Are there better alternatives?
Hey Matthew, by 'server name' I'm assuming you want the domain or host name.
Are you in a Dynamic Data Service or standard Groovy Service? If you are in a Dynamic Data service and have access to the HttpRequest you can use PortalUtils.getPortalContext(request) function as follows to get the domain of the form space:
String portalContext = PortalUtils.getPortalContext(request)
String domain = new URL(portalContext).getHost()
If you are in a standard Groovy service you can use the PortalDao class to retrieve a portal by name and get the context path as follows:
def context = new PortalDao().getPortalByName("Maguire").getContextPath()
def domain = new URL(context).getHost()
In Transact 5, you can use the new Fluent API to achieve the same result as follows:
Space mySpace = new SpaceQuery().setName("Maguire").firstValue()
String domain = new URL(mySpace.contextPath).getHost()
You should never access the database directly using SQL.
Did this work for you Matthew?
Thanks Ben, this does what I want - the TM 4 version. Haven't tried the 5.