Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 312393

Summary: Use BundleContext.getProperty() instead of System.getProperty() when running in OSGi
Product: [Modeling] EMF Reporter: Michal Tkacz <Michal.Tkacz>
Component: cdo.net4jAssignee: Eike Stepper <stepper>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: enhancement    
Priority: P3    
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Patch that makes Net4j use BundleContext.getProperty() when used in OSGi stepper: iplog+

Description Michal Tkacz CLA 2010-05-11 06:16:28 EDT
Build Identifier: 

Currently CDO (and more specifically Net4j) uses System.getProperty() to get configuration properties like net4j.config. This works fine in most setups. In particular, when CDO is used inside OSGi, config.ini can be used to set these properties. However when OSGi is deployed inside servlet container via servletbridge, this doesn't work anymore. The reason is that in this particular setup properties specified in config.ini are not stored in global system properties and are instead stored in a private copy of FrameworkProperties, available through BundleContext.getProperty() method (something I have learned from bug 209013). 

If CDO/Net4j used BundleContext.getProperty() instead of System.getProperty() it would have no negative impact on existing installations as FrameworkProperties are typically backed up by system properties anyway (unless osgi.framework.useSystemProperties is set to false). With current implementation, the only solution is to set properties globally for the whole servlet container (e.g. inside Tomcat start scripts). This is not an optimal solution when the servlet container hosts more web applications and prevents it from hosting multiple CDO servers (altough that might not be a frequent scenario).

Reproducible: Always
Comment 1 Michal Tkacz CLA 2010-05-11 06:31:13 EDT
Created attachment 167890 [details]
Patch that makes Net4j use BundleContext.getProperty() when used in OSGi

Here's a proposal of a patch for org.eclipse.net4j.util. The patch was made against HEAD but can also be applied to R2_0_maintenance after excluding unmatched changes.

The main part are the changes to AbstractPlatform and OSGiPlatform. But to support properties like org.eclipse.net4j.util.io.tmpdir (which I consider less important) I had to make the two getProperty methods public and push them to OMPlatform interface as well.

There might be other places using System.getProperty() outside org.eclipse.net4j.util which honestly I haven't checked.
Comment 2 Eike Stepper CLA 2010-05-18 06:29:16 EDT
Good catch, Michal. Thank you ;-)

Committed to HEAD
Comment 3 Eike Stepper CLA 2010-05-18 06:30:52 EDT
Michal, please confirm that:

1) The number of lines that you changed is smaller than 250.
2) You are the only author of these changed lines.
3) You apply the EPL to these changed lines.
Comment 4 Michal Tkacz CLA 2010-05-18 07:53:09 EDT
(In reply to comment #3)
> Michal, please confirm that:
> 
> 1) The number of lines that you changed is smaller than 250.
> 2) You are the only author of these changed lines.
> 3) You apply the EPL to these changed lines.

I confirm all three points.
Comment 5 Eike Stepper CLA 2010-05-18 07:54:22 EDT
Comment on attachment 167890 [details]
Patch that makes Net4j use BundleContext.getProperty() when used in OSGi

Thank you!
Comment 6 Eike Stepper CLA 2010-06-29 04:40:56 EDT
Available in 3.0 GA:
http://download.eclipse.org/modeling/emf/cdo/updates/3.0-releases/