You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Oliver Wulff <ow...@talend.com> on 2013/09/23 21:29:30 UTC

Config Admin service for WAR deployment

Hi there



Is it possible to use the Config Admin service to configure properties a web application which uses spring and has been deployed using the WAR deployer?



Thanks

Oli



Re: Config Admin service for WAR deployment

Posted by Marcos Mendez <ma...@jitisoft.com>.
You can also use spring-dm. I've been using it until we move to K3.

e.g.

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans.xsd
                         http://www.springframework.org/schema/osgi
                         http://www.springframework.org/schema/osgi/spring-osgi.xsd
                         http://www.springframework.org/schema/osgi-compendium
	                     http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
	                     http://www.springframework.org/schema/context
	                     http://www.springframework.org/schema/context/spring-context.xsd
	                     http://www.springframework.org/schema/mvc
                         http://www.springframework.org/schema/mvc/spring-mvc.xsd">


  <osgix:cm-properties id="cmProps" persistent-id="MyWARConfig">
        <!-- default values, overriden by cfg -->
        <prop key="a">12345</prop>
        <prop key="b">67890</prop>
    </osgix:cm-properties>

    <context:property-placeholder properties-ref="cmProps" />

    <bean id="myBean" init-method="init"
          class="org.myBeanImpl">
        <property name="myProperty1" value="${a}"/>
        <property name="myProperty2" value="${b}"/>
    </bean>

....

you can put this in your spring servlet xml.

you can even get a ref to the config admin service...

 <osgi:reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>

On Sep 23, 2013, at 4:53 PM, Achim Nierbeck wrote:

> With Pax-Web 3.0 it's possible to use Pax-CDI which lets you inject std. OSGi services into Servlets. 
> 
> Regards, Achim 
> 
> 
> 2013/9/23 Matthew Bishop <Ma...@elasticpath.com>
> The short answer is yes, but via gemini blueprint. You can create a bean
> that refers to the service you are trying to configure and add in a
> managed-properties directive to fire a PID change to a method like this:
> 
> <bean id="yourManagedService" class="com.company.YourManagedService.class">
>   <compendium:managed-properties persistent-id="yourPID"
> update-method="updateProperties"/>
>         </bean>
> 
> 
> 
> 
> Compendium's
> schemaLocation="http://www.eclipse.org/gemini/blueprint/schema/blueprint-co
> mpendium
>                         http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium/gemi
> ni-blueprint-compendium.xsd">
> 
> 
> 
> 
> On 2013-09-23 12:49 PM, "Jean-Baptiste Onofré" <jb...@nanthrax.net> wrote:
> 
> >Hi Oli,
> >
> >not sure to follow you. You can always use Spring in your WAR, with a
> >property placeholder which relay to ConfigAdmin.
> >
> >Is it what you are looking for ? I can send you an example if you need.
> >
> >Regards
> >JB
> >
> >On 09/23/2013 09:29 PM, Oliver Wulff wrote:
> >> Hi there
> >>
> >> Is it possible to use the Config Admin service to configure properties a
> >> web application which uses spring and has been deployed using the WAR
> >> deployer?
> >>
> >> Thanks
> >>
> >> Oli
> >>
> >
> >--
> >Jean-Baptiste Onofré
> >jbonofre@apache.org
> >http://blog.nanthrax.net
> >Talend - http://www.talend.com
> >
> 
> 
> 
> 
> Matthew Bishop, Senior Architect
> Mobile: +1-604-218-8102
> Email: Matthew.Bishop@elasticpath.com
> 
> Elastic Path Software Inc.
> Web: www.elasticpath.com
> Blog: www.getelastic.com
> Community: grep.elasticpath.com
> Careers: www.elasticpath.com/jobs
> 
> Confidentiality Notice: This message is intended only for the use of the designated addressee(s), and may contain information that is privileged, confidential and exempt from disclosure. Any unauthorized viewing, disclosure, copying, distribution or use of information contained in this e-mail is prohibited and may be unlawful. If you received this e-mail in error, please reply to the sender immediately to inform us you are not the intended recipient and delete the email from your computer system. Thank you.
> 
> 
> 
> 
> 
> -- 
> 
> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & Project Lead
> OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project Lead
> blog <http://notizblog.nierbeck.de/>


Re: Config Admin service for WAR deployment

Posted by Achim Nierbeck <bc...@googlemail.com>.
With Pax-Web 3.0 it's possible to use Pax-CDI which lets you inject std.
OSGi services into Servlets.

Regards, Achim


2013/9/23 Matthew Bishop <Ma...@elasticpath.com>

> The short answer is yes, but via gemini blueprint. You can create a bean
> that refers to the service you are trying to configure and add in a
> managed-properties directive to fire a PID change to a method like this:
>
> <bean id="yourManagedService" class="com.company.YourManagedService.class">
>   <compendium:managed-properties persistent-id="yourPID"
> update-method="updateProperties"/>
>         </bean>
>
>
>
>
> Compendium's
> schemaLocation="
> http://www.eclipse.org/gemini/blueprint/schema/blueprint-co
> mpendium
>
> http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium/gemi
> ni-blueprint-compendium.xsd">
>
>
>
>
> On 2013-09-23 12:49 PM, "Jean-Baptiste Onofré" <jb...@nanthrax.net> wrote:
>
> >Hi Oli,
> >
> >not sure to follow you. You can always use Spring in your WAR, with a
> >property placeholder which relay to ConfigAdmin.
> >
> >Is it what you are looking for ? I can send you an example if you need.
> >
> >Regards
> >JB
> >
> >On 09/23/2013 09:29 PM, Oliver Wulff wrote:
> >> Hi there
> >>
> >> Is it possible to use the Config Admin service to configure properties a
> >> web application which uses spring and has been deployed using the WAR
> >> deployer?
> >>
> >> Thanks
> >>
> >> Oli
> >>
> >
> >--
> >Jean-Baptiste Onofré
> >jbonofre@apache.org
> >http://blog.nanthrax.net
> >Talend - http://www.talend.com
> >
>
>
>
>
> Matthew Bishop, Senior Architect
> Mobile: +1-604-218-8102
> Email: Matthew.Bishop@elasticpath.com
>
> Elastic Path Software Inc.
> Web: www.elasticpath.com
> Blog: www.getelastic.com
> Community: grep.elasticpath.com
> Careers: www.elasticpath.com/jobs
>
> Confidentiality Notice: This message is intended only for the use of the
> designated addressee(s), and may contain information that is privileged,
> confidential and exempt from disclosure. Any unauthorized viewing,
> disclosure, copying, distribution or use of information contained in this
> e-mail is prohibited and may be unlawful. If you received this e-mail in
> error, please reply to the sender immediately to inform us you are not the
> intended recipient and delete the email from your computer system. Thank
> you.
>
>
>


-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
OPS4J Pax for Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
Commiter & Project Lead
blog <http://notizblog.nierbeck.de/>

RE: Config Admin service for WAR deployment

Posted by Oliver Wulff <ow...@talend.com>.
This is exactly what I was looking for. Thanks guys.

Oli

________________________________________
From: Jean-Baptiste Onofré [jb@nanthrax.net]
Sent: 23 September 2013 22:02
To: user@karaf.apache.org
Subject: Re: Config Admin service for WAR deployment

Hi Matthew,

The "problem" with Blueprint is that your WAR can be deployed only in a
Blueprint container (like Karaf).

If you use Spring, and Spring osgix, you can leverage a
PropertyPlaceholder with ConfigAdmin:

<beans xmlns:context="http://www.springframework.org/schema/context"
             xmlns:osgi="http://www.springframework.org/schema/osgi"

xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://www.springframework.org/schema/beans"
             xsi:schemalocation="
                 http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                 http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
                 http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
                 http://www.springframework.org/schema/osgi-compendium
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">

     <osgix:cm-properties id="props" persistent-id="my.props">
         <prop key="property.name">default value</prop>
     </osgix:cm-properties>

     <context:property-placeholder properties-ref="props">
</context:property-placeholder>

     <bean id="myBean" lass="com.company.MyClass">
         <property name="property" value="${property.name}"></property>
     </bean>
</beans>

It can in a Spring webapp application context.

Regards
JB

On 09/23/2013 09:54 PM, Matthew Bishop wrote:
> The short answer is yes, but via gemini blueprint. You can create a bean
> that refers to the service you are trying to configure and add in a
> managed-properties directive to fire a PID change to a method like this:
>
> <bean id="yourManagedService" class="com.company.YourManagedService.class">
>    <compendium:managed-properties persistent-id="yourPID"
> update-method="updateProperties"/>
>          </bean>
>
>
>
>
> Compendium's
> schemaLocation="http://www.eclipse.org/gemini/blueprint/schema/blueprint-co
> mpendium
>                          http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium/gemi
> ni-blueprint-compendium.xsd">
>
>
>
>
> On 2013-09-23 12:49 PM, "Jean-Baptiste Onofré" <jb...@nanthrax.net> wrote:
>
>> Hi Oli,
>>
>> not sure to follow you. You can always use Spring in your WAR, with a
>> property placeholder which relay to ConfigAdmin.
>>
>> Is it what you are looking for ? I can send you an example if you need.
>>
>> Regards
>> JB
>>
>> On 09/23/2013 09:29 PM, Oliver Wulff wrote:
>>> Hi there
>>>
>>> Is it possible to use the Config Admin service to configure properties a
>>> web application which uses spring and has been deployed using the WAR
>>> deployer?
>>>
>>> Thanks
>>>
>>> Oli
>>>
>>
>> --
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>>
>
>
>
>
> Matthew Bishop, Senior Architect
> Mobile: +1-604-218-8102
> Email: Matthew.Bishop@elasticpath.com
>
> Elastic Path Software Inc.
> Web: www.elasticpath.com
> Blog: www.getelastic.com
> Community: grep.elasticpath.com
> Careers: www.elasticpath.com/jobs
>
> Confidentiality Notice: This message is intended only for the use of the designated addressee(s), and may contain information that is privileged, confidential and exempt from disclosure. Any unauthorized viewing, disclosure, copying, distribution or use of information contained in this e-mail is prohibited and may be unlawful. If you received this e-mail in error, please reply to the sender immediately to inform us you are not the intended recipient and delete the email from your computer system. Thank you.
>
>

--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Config Admin service for WAR deployment

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Matthew,

The "problem" with Blueprint is that your WAR can be deployed only in a 
Blueprint container (like Karaf).

If you use Spring, and Spring osgix, you can leverage a 
PropertyPlaceholder with ConfigAdmin:

<beans xmlns:context="http://www.springframework.org/schema/context"
             xmlns:osgi="http://www.springframework.org/schema/osgi"
 
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://www.springframework.org/schema/beans"
             xsi:schemalocation="
                 http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                 http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd
                 http://www.springframework.org/schema/osgi 
http://www.springframework.org/schema/osgi/spring-osgi.xsd
                 http://www.springframework.org/schema/osgi-compendium 
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">

     <osgix:cm-properties id="props" persistent-id="my.props">
         <prop key="property.name">default value</prop>
     </osgix:cm-properties>

     <context:property-placeholder properties-ref="props">	 
</context:property-placeholder>

     <bean id="myBean" lass="com.company.MyClass">
         <property name="property" value="${property.name}"></property>
     </bean>
</beans>

It can in a Spring webapp application context.

Regards
JB

On 09/23/2013 09:54 PM, Matthew Bishop wrote:
> The short answer is yes, but via gemini blueprint. You can create a bean
> that refers to the service you are trying to configure and add in a
> managed-properties directive to fire a PID change to a method like this:
>
> <bean id="yourManagedService" class="com.company.YourManagedService.class">
>    <compendium:managed-properties persistent-id="yourPID"
> update-method="updateProperties"/>
>          </bean>
>
>
>
>
> Compendium's
> schemaLocation="http://www.eclipse.org/gemini/blueprint/schema/blueprint-co
> mpendium
>                          http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium/gemi
> ni-blueprint-compendium.xsd">
>
>
>
>
> On 2013-09-23 12:49 PM, "Jean-Baptiste Onofré" <jb...@nanthrax.net> wrote:
>
>> Hi Oli,
>>
>> not sure to follow you. You can always use Spring in your WAR, with a
>> property placeholder which relay to ConfigAdmin.
>>
>> Is it what you are looking for ? I can send you an example if you need.
>>
>> Regards
>> JB
>>
>> On 09/23/2013 09:29 PM, Oliver Wulff wrote:
>>> Hi there
>>>
>>> Is it possible to use the Config Admin service to configure properties a
>>> web application which uses spring and has been deployed using the WAR
>>> deployer?
>>>
>>> Thanks
>>>
>>> Oli
>>>
>>
>> --
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>>
>
>
>
>
> Matthew Bishop, Senior Architect
> Mobile: +1-604-218-8102
> Email: Matthew.Bishop@elasticpath.com
>
> Elastic Path Software Inc.
> Web: www.elasticpath.com
> Blog: www.getelastic.com
> Community: grep.elasticpath.com
> Careers: www.elasticpath.com/jobs
>
> Confidentiality Notice: This message is intended only for the use of the designated addressee(s), and may contain information that is privileged, confidential and exempt from disclosure. Any unauthorized viewing, disclosure, copying, distribution or use of information contained in this e-mail is prohibited and may be unlawful. If you received this e-mail in error, please reply to the sender immediately to inform us you are not the intended recipient and delete the email from your computer system. Thank you.
>
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Config Admin service for WAR deployment

Posted by Matthew Bishop <Ma...@elasticpath.com>.
The short answer is yes, but via gemini blueprint. You can create a bean
that refers to the service you are trying to configure and add in a
managed-properties directive to fire a PID change to a method like this:

<bean id="yourManagedService" class="com.company.YourManagedService.class">
  <compendium:managed-properties persistent-id="yourPID"
update-method="updateProperties"/>
        </bean>




Compendium's
schemaLocation="http://www.eclipse.org/gemini/blueprint/schema/blueprint-co
mpendium
                        http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium/gemi
ni-blueprint-compendium.xsd">




On 2013-09-23 12:49 PM, "Jean-Baptiste Onofré" <jb...@nanthrax.net> wrote:

>Hi Oli,
>
>not sure to follow you. You can always use Spring in your WAR, with a
>property placeholder which relay to ConfigAdmin.
>
>Is it what you are looking for ? I can send you an example if you need.
>
>Regards
>JB
>
>On 09/23/2013 09:29 PM, Oliver Wulff wrote:
>> Hi there
>>
>> Is it possible to use the Config Admin service to configure properties a
>> web application which uses spring and has been deployed using the WAR
>> deployer?
>>
>> Thanks
>>
>> Oli
>>
>
>--
>Jean-Baptiste Onofré
>jbonofre@apache.org
>http://blog.nanthrax.net
>Talend - http://www.talend.com
>




Matthew Bishop, Senior Architect
Mobile: +1-604-218-8102
Email: Matthew.Bishop@elasticpath.com

Elastic Path Software Inc.
Web: www.elasticpath.com
Blog: www.getelastic.com
Community: grep.elasticpath.com
Careers: www.elasticpath.com/jobs

Confidentiality Notice: This message is intended only for the use of the designated addressee(s), and may contain information that is privileged, confidential and exempt from disclosure. Any unauthorized viewing, disclosure, copying, distribution or use of information contained in this e-mail is prohibited and may be unlawful. If you received this e-mail in error, please reply to the sender immediately to inform us you are not the intended recipient and delete the email from your computer system. Thank you.



Re: Config Admin service for WAR deployment

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Oli,

not sure to follow you. You can always use Spring in your WAR, with a 
property placeholder which relay to ConfigAdmin.

Is it what you are looking for ? I can send you an example if you need.

Regards
JB

On 09/23/2013 09:29 PM, Oliver Wulff wrote:
> Hi there
>
> Is it possible to use the Config Admin service to configure properties a
> web application which uses spring and has been deployed using the WAR
> deployer?
>
> Thanks
>
> Oli
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com