Discussion:
[FreeMarker-user] freemarker.template.Configuration (v.2.3.22) cannot be injected because of final method decleration in OSGI environment
halil
2015-05-20 14:30:43 UTC
Permalink
Hi All,

I could not create a reference of freemarker.template.Configuration on OSGI
blueprint file. I referenced it as below. Blueprint throwed exception which
states that Configuration class has final method declerations. It seems
that OSGI (org.apache.felix.framework-4.4.1) does not support injection of
classes having final method declerations...

<reference id="freemarkerCfgRef"
interface="freemarker.template.Configuration" ext:proxy-method='classes' />

When I did below steps, I succeed.

1. create an interface of Configuration class
2. put it a new package named freemarker.template.api.
3. Configuration class now implements
freemarker.template.api.FreeMarkerConfigurationInt
3. reference it as below

<reference id="freemarkerCfgRef"
interface="freemarker.template.api.FreeMarkerConfigurationInt" />

Now, it works perfectly...

I read some mails of developers stating that freemarker works on OSGI but I
could not succeed until I have done it as above...


I would like to inform you,


best,


-halil.
Daniel Dekany
2015-05-20 22:59:25 UTC
Permalink
Note that "works on OSGi" doesn't imply at all that it can be (easily)
proxyed (for Buleprint or whatever). It just means that you can drop
the jar into an OSGi container, and then can link to it from the other
bundles.

OTOH surely if somebody for some reason wants to proxy Configuration,
final methods make it hard (requires byte code manipulation). I will
consider making them non-final in 2.3.23.
Post by halil
Hi All,
I could not create a reference of freemarker.template.Configuration
on OSGI blueprint file. I referenced it as below. Blueprint throwed
exception which states that Configuration class has final method
declerations. It seems that OSGI (org.apache.felix.framework-4.4.1)
does not support injection of classes having final method declerations...
<reference id="freemarkerCfgRef"
interface="freemarker.template.Configuration" ext:proxy-method='classes' />
When I did below steps, I succeed.
1. create an interface of Configuration class
2. put it a new package named freemarker.template.api.
3. Configuration class now implements
freemarker.template.api.FreeMarkerConfigurationInt
3. reference it as below
<reference id="freemarkerCfgRef"
interface="freemarker.template.api.FreeMarkerConfigurationInt" />
Now, it works perfectly...
I read some mails of developers stating that freemarker works on
OSGI but I could not succeed until I have done it as above...
I would like to inform you,
best,
-halil.
--
Thanks,
Daniel Dekany
Daniel Dekany
2015-06-07 13:43:50 UTC
Permalink
On second though, having some final methods is not a problem. The
problem is simply that Freemarker doesn't define a service interface,
which then Configuration would implement (and then only the methods
that are also in the service interface must be non-final). If I add a
such interface (is freemarker.template.FreemarkerService a good
name?), will you or somebody else test if now it indeed works with
Felix / Blueprint, and if the interface contains the methods that are
expected from a "Freemarker service" (I guess the setting setters
won't be there for example)?

We also have some other strange problem reported for Felix:
https://sourceforge.net/p/freemarker/bugs/428/

Someone feels like picking this up, and test that (A) the Freemarker
bundle (that's just freemarker.jar - it's already an OSGi bundle) can
be used under Felix without problems from a different bundle via its
package exports, and (B) that it can be used as a Blueprint service
out-of-the-box? Ideally, testing means testing in the form of a JUnit
tests.
--
Thanks,
Daniel Dekany
Post by Daniel Dekany
Note that "works on OSGi" doesn't imply at all that it can be (easily)
proxyed (for Buleprint or whatever). It just means that you can drop
the jar into an OSGi container, and then can link to it from the other
bundles.
OTOH surely if somebody for some reason wants to proxy Configuration,
final methods make it hard (requires byte code manipulation). I will
consider making them non-final in 2.3.23.
Post by halil
Hi All,
I could not create a reference of freemarker.template.Configuration
on OSGI blueprint file. I referenced it as below. Blueprint throwed
exception which states that Configuration class has final method
declerations. It seems that OSGI (org.apache.felix.framework-4.4.1)
does not support injection of classes having final method declerations...
<reference id="freemarkerCfgRef"
interface="freemarker.template.Configuration" ext:proxy-method='classes' />
When I did below steps, I succeed.
1. create an interface of Configuration class
2. put it a new package named freemarker.template.api.
3. Configuration class now implements
freemarker.template.api.FreeMarkerConfigurationInt
3. reference it as below
<reference id="freemarkerCfgRef"
interface="freemarker.template.api.FreeMarkerConfigurationInt" />
Now, it works perfectly...
I read some mails of developers stating that freemarker works on
OSGI but I could not succeed until I have done it as above...
I would like to inform you,
best,
-halil.
------------------------------------------------------------------------------
Loading...