Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-13435

Incorrect domain name in external URL generated from a scheduler job

    XMLWordPrintable

Details

    • Unknown
    • N/A
    • N/A

    Description

      I am trying to generate an external URL from a groovy code (Job Script) using the following code:
      def url = xwiki.getXWiki().getExternalURL("Space.Page", "view", "param1=xxx&param2=yyy", xcontext);
      The problem is that sometimes in the generated URL, the domain name of the wiki that executed the code is 'localhost'
      As you can see in the example bellow:
      The generated url is :
      http://localhost:8080/xwiki/bin/view/Space/Page?param1=xxx&param2=yyy

      instead of

      http://myDomainName/xwiki/bin/view/Space/Page?param1=xxx&param2=yyy

      Unscheduling and scheduling again the job fix the problem.

      -------------------------------------------------------------------------------------------------------------------------------------------------
      below, a discussion started on IRC about this problem

      Vvmassol (IRC)
      maybe check your main wiki descriptor
      see what domain you've put there

      Ccjd (IRC)
      Is it Apache/AJP/Tomcat or Jetty ?

      Mmouhb
      Jetty

      Ccjd (IRC)
      I seem to recall there being a place to set the hostname of the server in the xwiki.cfg

      CClemensR (IRC)
      Job script is a background job, it has to get the information from the config, as it has no current request to guess the domain name

      Ccjd (IRC)
      but also as Vincent said, the wiki descriptor (which I take it to mean XWiki.XWikiServerXwiki) might be involved

      Vvmassol (IRC)
      it's xwiki.home ClemensR
      if defined, it's used to generate the external url
      (on the main wiki)
      if not defined, then the descriptor is used

      EEnygma` (IRC)
      vmassol: the problem M-mouhb1 is having is when sending an email. When the mail sending job generates the external URL, probably the context is not properly initialized and the context URL (the one used by the XWikiServletURLFactory#getHost when initializing the factory)

      Vvmassol (IRC)
      indeed
      we use a stub context
      and it's likely it's localhost used then

      EEnygma` (IRC)
      now indeed, the xwiki.home parameter from xwiki.cfg is taking precedence to the context URL and to the XWikiServer defined alias
      so that would be a solution
      Thu 17:28
      Options
      the order of initializing the server now seems to be: proxy host > xwiki.home > contextURL; Once initialized, on each call if the context wiki is the same as the requested document's wiki, the initialized server is returned. If not, only then the XWikiServer descriptor is checked for the main wiki or for a subwiki to see what is defined there.
      so we either change the lookup order to prioritize the wiki descriptor or we work on the context initialization and say initialize it with the external URL of the main wiki's homepage
      I see that the mail sender uses the current context and it passes it to the mail prepare thread so maybe it`s actually the scheduler's fault that the scheduler context is not setting the correct URL

      Attachments

        Issue Links

          Activity

            People

              tmortagne Thomas Mortagne
              mouhb Mohamed Boussaa
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: