Foros de discusión

MessageListener class

thumbnail
Ahmed Hasan, modificado hace 11 años.

MessageListener class

Expert Mensajes: 306 Fecha de incorporación: 13/04/07 Mensajes recientes
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>
Praveen Kumar, modificado hace 11 años.

RE: MessageListener class

New Member Mensajes: 14 Fecha de incorporación: 23/03/13 Mensajes recientes
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
Ahmed Hasan, modificado hace 11 años.

RE: MessageListener class

Expert Mensajes: 306 Fecha de incorporación: 13/04/07 Mensajes recientes
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
Gnaniyar Zubair, modificado hace 11 años.

RE: MessageListener class

Liferay Master Mensajes: 722 Fecha de incorporación: 19/12/07 Mensajes recientes
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
Ahmed Hasan, modificado hace 11 años.

RE: MessageListener class

Expert Mensajes: 306 Fecha de incorporación: 13/04/07 Mensajes recientes
Oh, cool zubair bhai, will try this. Then how are things @ elm?
thumbnail
Gnaniyar Zubair, modificado hace 11 años.

RE: MessageListener class

Liferay Master Mensajes: 722 Fecha de incorporación: 19/12/07 Mensajes recientes
Expecting your presence for technical supports. emoticon
thumbnail
Domingo Piña, modificado hace 10 años.

RE: MessageListener class

Junior Member Mensajes: 28 Fecha de incorporación: 3/04/09 Mensajes recientes
ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

Returns null inside a MessageListener (with Liferay 6.0 EE).
thumbnail
Jitendra Rajput, modificado hace 10 años.

RE: MessageListener class

Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
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
Domingo Piña, modificado hace 10 años.

RE: MessageListener class

Junior Member Mensajes: 28 Fecha de incorporación: 3/04/09 Mensajes recientes
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
Ahmed Hasan, modificado hace 9 años.

RE: MessageListener class

Expert Mensajes: 306 Fecha de incorporación: 13/04/07 Mensajes recientes
Thanks a lot.

Ahamed Hasan
Author, Liferay Cookbook