掲示板

MessageListener class

thumbnail
11年前 に Ahmed Hasan によって更新されました。

MessageListener class

Expert 投稿: 306 参加年月日: 07/04/13 最新の投稿
How can i get the Portal URL (e.g., http://localhost:8080) dynamically inside a MessageListener class. I've given the sample code here. Based on this value i have to dynamically create an createAccountURL and send to the invitees. This job is being invoked by a scheduler.

public class ReminderInvitationJob extends BaseMessageListener {

	protected void doReceive(Message message) throws Exception {

		long userId = 10195l;
		
		long companyId = CompanyLocalServiceUtil.getCompanyIdByUserId(userId);
		
		Group group = GroupLocalServiceUtil.fetchGroup(companyId, GroupConstants.GUEST);
		
		String portalURL = ""; // ???????
		System.out.println("createAccountURL ==> " + 
				InvitationUtil.getCreateAccountURL(group.getGroupId(), portalURL, userId));
		
		Iterator<string> itr = message.getValues().keySet().iterator();
		
		while (itr.hasNext()) {
			System.out.println(itr.next());
		}
	}
}</string>
11年前 に Praveen Kumar によって更新されました。

RE: MessageListener class

New Member 投稿: 14 参加年月日: 13/03/23 最新の投稿
you can create a friendly url and then pass the parameters in the URL (something like a new create_account_id) and then u can get this parameter in your custom create account portlet (or even create a hook to override account create portlet)

with the create_account_id you can fetch data from the DB and pre-populate the form in the page,

/Praveen
thumbnail
11年前 に Ahmed Hasan によって更新されました。

RE: MessageListener class

Expert 投稿: 306 参加年月日: 07/04/13 最新の投稿
The invitation reminders are sent by a scheduler job. All i need is to dynamically get the portal URL, eg. http://www.mpowerglobal.com or http://localhost:8080 based on target environment where this portlet is deployed.
thumbnail
11年前 に Gnaniyar Zubair によって更新されました。

RE: MessageListener class

Liferay Master 投稿: 722 参加年月日: 07/12/19 最新の投稿
I think we can get the service context object in MessageListener class and get the Portal URL like this:

ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
serviceContext.getPortalURL()


I am not sure whether above things will work in Message Listener class but i have tried like this in my model listener class.

HTH

- Gnaniyar Zubair
thumbnail
11年前 に Ahmed Hasan によって更新されました。

RE: MessageListener class

Expert 投稿: 306 参加年月日: 07/04/13 最新の投稿
Oh, cool zubair bhai, will try this. Then how are things @ elm?
thumbnail
11年前 に Gnaniyar Zubair によって更新されました。

RE: MessageListener class

Liferay Master 投稿: 722 参加年月日: 07/12/19 最新の投稿
Expecting your presence for technical supports. emoticon
thumbnail
10年前 に Domingo Piña によって更新されました。

RE: MessageListener class

Junior Member 投稿: 28 参加年月日: 09/04/03 最新の投稿
ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

Returns null inside a MessageListener (with Liferay 6.0 EE).
thumbnail
10年前 に Jitendra Rajput によって更新されました。

RE: MessageListener class

Liferay Master 投稿: 875 参加年月日: 11/01/07 最新の投稿
You can also get Portal URL if you have company details .

  Company company = CommonUtil.getCompanyByWebId("liferay.com");
        if (Validator.isNotNull(company))
        {
            String portalURL = PortalUtil.getPortalURL(company.getVirtualHostname(), PortalUtil.getPortalPort(false), false);
        }


Third argument for getPortalURL is to indicate server is secured or not. If you have enabled SSL then you can read from properties file and based on that you can pass true or false.

#
# Set the preferred protocol.
#
#web.server.protocol=https
thumbnail
10年前 に Domingo Piña によって更新されました。

RE: MessageListener class

Junior Member 投稿: 28 参加年月日: 09/04/03 最新の投稿
Thanks for the clue!
Finally, this is the code that works for LR 6.0 EE SP1:


Company company = CompanyLocalServiceUtil.getCompanyByWebId("liferay.com");
if ( company != null ) {
    int port = PortalUtil.getPortalPort();
    if ( port &lt; 0 ) {
        port = 80;
    }
    portalURL = PortalUtil.getPortalURL(company.getVirtualHost(), port, false);
}
thumbnail
9年前 に Ahmed Hasan によって更新されました。

RE: MessageListener class

Expert 投稿: 306 参加年月日: 07/04/13 最新の投稿
Thanks a lot.

Ahamed Hasan
Author, Liferay Cookbook