Hi,
I submitted PR-851, merger in Feb 2018 to handle the background task host problem.
To use these, simply create a context using ERXWOContext sessionLessContext = ERXWOContext.newContext(); sessionLessContext.generateCompleteURLs(); String url = sessionLessContext.urlWithRequestHandlerKey(...)
or create a component with ERXApplication.instantiatePage(String pageName) or ERMailUtils.instantiatePage() as both will use ERXWOContext.newContext();
Properties to enable this: ## If your WOHost is not your public host name, specify the public host to use for complete URL ## generated without a server request like background tasks that send emails. ## Set to true to switch default request used in background tasks to https # er.extensions.ERXApplication.publicHostIsSecure=false Regards,
Samuel
Two important questions should be considered:
- Do you generate the URL inside of a request-response cycle or possibly also inside of a background task?
- If during a request, WOContext.directActionURLForActionNamed works fine, as written by René and Ramsey. This works because the WOContext takes the URL used in the HTTP WORequest.
- Else:
- Is the host, which the app is running on, the one directly accessed by users via HTTP?
- If yes, you might be able to use ERXConfigurationManager.defaultManager().hostName() as suggested by Jesse (it uses InetAddress.getLocalHost().getHostName() internally)
- Else:
- Just define a configuration property containing the base URL (can certainly be specified per environment) as written by Paul.
Best regards, Stefan
The subject line already says all
Thanks
Markus Ruggiero
4051 Basel / Switzerland mobile +41 79 508 4701
|