Foren

Home » Liferay Portal » English » Liferay Legacy

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Stefan Rauch
Problem accessing company specific properties using PropsUtil
21. September 2006 23:24
Antwort

Stefan Rauch

Rang: New Member

Nachrichten: 5

Eintrittsdatum: 2. August 2006

Neue Beiträge

Hi,

we have build a working environment to host multiple portal instances. Right now everything works quite fine except accessing the portal-companyid.properties.

Environment is liferay 4.1.1 on Jboss using CAS on separate Tomcat.

We define some extra properties in portal-ext.properties and some more in portal-abc.mydomain.fun.properties and portal-xyz.mydomain.fun.properties

Building works fine and we get one liferay.ear containing portal-web-abc.war and portal-web-xyz.war.

Also accessing each portal-instance works fine.

But when accessing http://abc.mydomain.fun and trying to read some of the extra properties defined in portal-abc.mydomain.fun.properties by using PropsUtil.get("myprop") we do not get the expected result.
If "myprop" is defined in portal-ext.properties or portal.properties we get the value defined there (portal-ext.properties overriding portal.properties), but not the one defined in portal-abc.mydomain.fun.properties.
If "myprop" is defined only in portal-abc.mydomain.fun.properties we get null.

I understand that using CompanyPropsUtil would bypass this problem, but that doesn't seem to be a good option to me as I would have to know the companyId at compile-time. This is definitely not wanted, as the piece of code using "myprop" is used for all of our portal instances.

Whilst searching around I found the folllowing peace of code from com.germinus.easyconf.ConfigurationLoader (included in easyconfig.jar):

public ComponentProperties readPropertiesConfiguration(String companyId, String componentName) {
AggregatedProperties properties = new AggregatedProperties(companyId, componentName);
// if (companyId != null) {
// properties.addGlobalFileName(Conventions.GLOBAL_CONFIGURATION_FILE + Conventions.SLASH + companyId
// + Conventions.PROPERTIES_EXTENSION);
// }
properties.addGlobalFileName(Conventions.GLOBAL_CONFIGURATION_FILE +
Conventions.PROPERTIES_EXTENSION);
// if (companyId != null) {
// properties.addBaseFileName(componentName + Conventions.SLASH + companyId +
// Conventions.PROPERTIES_EXTENSION);
// }
properties.addBaseFileName(componentName + Conventions.PROPERTIES_EXTENSION);

log.info("Properties for " + componentName + " loaded from " + properties.loadedSources());
return new ComponentProperties(properties);
}


I believe the out commented piece of code would solve our problem, but am really not sure about this.

Is this rather a bug, a feature or did I overlook something?

I would be glad, if anyone could help us.

Cheers

Stefan.
Jorge Ferrer
RE: Problem accessing company specific properties using PropsUtil
12. Oktober 2006 10:26
Antwort

Jorge Ferrer

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 2762

Eintrittsdatum: 31. August 2006

Neue Beiträge

Hi Stefan,

As you say, you must use CompanyPropsUtil if you want Liferay to read the configuration that is dependent on a given companyId. You don't have to hardcode the companyId in the call to this class, as it can be retrieved from the request, the session or even the servlet context.

Related to the EasyConf code you point to, it is old code that should remain commented out. Starting with EasyConf 0.9 (the one used in Liferay 4) the name of the file specific for one company is configured in the base properties file. In the case of Liferay, check the first lines of portal.properties and you'll see:

1include-and-override=portal-${easyconf:companyId}.properties


So this is the lines that says that for company 'portalA' the file 'portal-portalA.properties' will be read and will override the default values.

Let me know if calling CompanyPropsUtil has solved your problem.
Stefan Rauch
RE: Problem accessing company specific properties using PropsUtil
12. Oktober 2006 11:05
Antwort

Stefan Rauch

Rang: New Member

Nachrichten: 5

Eintrittsdatum: 2. August 2006

Neue Beiträge

Hi Jorge,

probably you're right that I want need to hardcode the company id, but wouldn't it still be better that PropsUtil would return the value of a property belonging to the current portal instance?

And if not I do think that there should be a convenience method like PropsUtil.get(String key, boolean useCompanyProperty) to preserve people from duplicating the piece of code to determine the current company id. Actually I believ the default behaviour of PropsUtil.get(String key) should be to return the specific value of the current portal instance (company id)

What do you think?

Stefan.
Jorge Ferrer
RE: Problem accessing company specific properties using PropsUtil
13. Oktober 2006 01:12
Antwort

Jorge Ferrer

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 2762

Eintrittsdatum: 31. August 2006

Neue Beiträge

Hi Stefan,

I agree that it would be a good idea if PropsUtil automatically added the current companyId, but currently it has no way to access its value, because it does not have access to the request, session nor servletContext.

Do you have an idea to implement that in a way that wouldn't require many changes to the source code?
Stefan Rauch
RE: Problem accessing company specific properties using PropsUtil
13. Oktober 2006 01:33
Antwort

Stefan Rauch

Rang: New Member

Nachrichten: 5

Eintrittsdatum: 2. August 2006

Neue Beiträge

;-))

That's why I would have to hardcode the company id in the example givven above. I hoped to find a solution here...;-)
Brian Chan
RE: Problem accessing company specific properties using PropsUtil
13. Oktober 2006 11:54
Antwort

Brian Chan

LIFERAY STAFF

Rang: Liferay Master

Nachrichten: 751

Eintrittsdatum: 4. August 2004

Neue Beiträge

CompanyPropsUtil actually wraps PropsUtil...

Perhaps we can set it in... the thread context?
Jorge Ferrer
RE: Problem accessing company specific properties using PropsUtil
14. Oktober 2006 06:33
Antwort

Jorge Ferrer

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 2762

Eintrittsdatum: 31. August 2006

Neue Beiträge

Brian Chan:
Perhaps we can set it in... the thread context?


Yes, I think that setting the company_id in a ThreadLocal variable would be a great idea. If we do it that way there is no longer a need to store it in the request or session anymore.