留言板

Getting portal url from within hook [RESOLVED]

M J,修改在13 年前。

Getting portal url from within hook [RESOLVED]

New Member 帖子: 8 加入日期: 10-7-7 最近的帖子
Hi

I'm writing a ModelListener on the JournalArticle and need to get the
Portal URL (http://host:port) from within this hook.

Is there a way to do this without an additional property file?

Every hint is welcome!
v c vijayan,修改在13 年前。

RE: Getting portal url from within hook

thumbnail
Sandeep Nair,修改在13 年前。

RE: Getting portal url from within hook (答复)

Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Hi,

Try using this

String portalURL = PortalUtil.getPortalURL(
company.getVirtualHost(), PortalUtil.getPortalPort(), false);

Company u can get from companyid which may be there in your journal article

Regards,
Sandeep
M J,修改在13 年前。

RE: Getting portal url from within hook

New Member 帖子: 8 加入日期: 10-7-7 最近的帖子
Works like a charm!

Thank you very much for your help.
thumbnail
Jitendra Rajput,修改在12 年前。

RE: Getting portal url from within hook [RESOLVED]

Liferay Master 帖子: 875 加入日期: 11-1-7 最近的帖子
Whats the third argument mean in this method
 PortalUtil.getPortalURL(
company.getVirtualHost(), PortalUtil.getPortalPort(), false);
thumbnail
Sandeep Nair,修改在12 年前。

RE: Getting portal url from within hook [RESOLVED]

Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Secure or non secure. If secure(flag is true) it will give url with https
thumbnail
Jitendra Rajput,修改在12 年前。

RE: Getting portal url from within hook [RESOLVED]

Liferay Master 帖子: 875 加入日期: 11-1-7 最近的帖子
can we determine this dynamically ?

I know there is one method in themeDisplay.isSecure() .
I mean can we check dynamically whether server is SSL enabled or not ? without using any request object . As i want to determine from my scheduler and i dnt have access to any of request object.
thumbnail
Sandeep Nair,修改在12 年前。

RE: Getting portal url from within hook [RESOLVED]

Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Are you setting the follwoing in your portal-ext.properties

web.server.protocol=https

If yes then you can just check the property. Otherwise you dont have any other way

Regards,
Sandeep
thumbnail
Jitendra Rajput,修改在12 年前。

RE: Getting portal url from within hook [RESOLVED]

Liferay Master 帖子: 875 加入日期: 11-1-7 最近的帖子
You mean to say ,, this is manual job ..if my server is https enabled then i need to set this property as https otherwise http.
thumbnail
Sandeep Nair,修改在12 年前。

RE: Getting portal url from within hook [RESOLVED]

Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Well, since you have no other option as you are using scheduler and protocol is associated with request. User A can hit http or https and scheduler cant magically dream about the request being made by each client. By setting the property you are saying that this is the preferred protocol and it becomes easy for you as you are generating the url and not the end user.

Regards,
Sandeep
thumbnail
Bijan Vakili,修改在9 年前。

RE: Getting portal url from within hook

Expert 帖子: 375 加入日期: 09-3-10 最近的帖子
Sandeep Nair:
Hi,

Try using this

String portalURL = PortalUtil.getPortalURL(
company.getVirtualHost(), PortalUtil.getPortalPort(), false);

Company u can get from companyid which may be there in your journal article

Regards,
Sandeep



Thank you; in 6.2, this has changed bit:

String portalURL = PortalUtil.getPortalURL(
company.getVirtualHostname(), PortalUtil.getPortalPort(), false);

Note: company.getVirtualHost() --> company.getVirtualHostname()