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?


    CommentAdd your comment...

    1 answer


      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:


      import com.avoka.fc.core.util.PortalUtils
      import java.net.URL
      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:


      import com.avoka.fc.core.dao.PortalDao
      import java.net.URL
      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.

      1. Ben Warner

        Did this work for you Matthew?

      2. Matthew White

        Thanks Ben, this does what I want - the TM 4 version. Haven't tried the 5.

      CommentAdd your comment...