Hi,

Thanks for the response. 
My Observations: In the setter function (setServiceBn(MyService serviceBn)) 
, if i check, the "MyService" is not null. That means it is injecting 
during activating the feature. But after that in function execute(), it is 
getting null. Any suggestion to this?

On Sunday, 28 August 2016 12:03:56 UTC+5:30, Achim Nierbeck wrote:
>
> hi, 
>
> even though this is the wrong list to ask, you should ask at the karaf 
> mailinglist for karaf specific question. 
> It might be because you have your blueprint contextes initialized lazy. on 
> both sides. Producing and consuming. 
> Might be that. Maybe remove that and give it another try. 
>
> cheers, Achim 
>
>
> 2016-08-27 22:21 GMT+02:00 <[email protected] <javascript:>>:
>
>> Hi All,
>>
>> Please see my setup and code. 
>>
>> Version: apache-karaf-3.0.5
>>
>> *Part 1*: Service class
>>
>> Service:
>> ------------
>> package org.jrb.test;
>>
>> public interface MyService {
>>
>>     public String echo(String message);
>>
>> }
>>
>> package org.jrb.test;
>>
>> public class MyServiceImpl implements MyService {
>>
>>     public String echo(String message) {
>>         return "Echo processed: " + message;
>>     }
>>
>> }
>>
>> Blueprit:
>> ------------
>> <?xml version="1.0" encoding="UTF-8"?>
>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; 
>> default-activation="lazy">
>>
>>     <bean id="serviceBean" class="org.jrb.test.MyServiceImpl"/>
>>
>>     <service id="MyService" ref="serviceBean" 
>> interface="org.jrb.test.MyService"/>
>>
>> </blueprint>
>>
>> i can see my service in list: 
>> ------------------------------------------
>> onos> service:list | grep serviceBean
>>  *osgi.service.blueprint.compname = serviceBean*
>>
>>
>> *Part 2*: consumer class for testing
>>
>> Blueprint
>> -------------
>> <?xml version="1.0" encoding="UTF-8"?>
>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; 
>> default-activation="lazy">
>>
>> <reference id="MyService" interface="org.jrb.test.MyService"/>
>> <bean id="b" class="org.ct.command.AddCommand" activation="eager" >
>> <property name="serviceBn" ref="MyService" />
>> </bean>
>>     <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0";>
>>         <command>
>>             <action class="org.ct.command.AddCommand"/>
>>         </command>
>>     </command-bundle>
>>     
>> </blueprint>
>>
>> In Java:
>> ------------
>> package org.ct.command;
>>
>> import org.apache.felix.gogo.commands.Action;
>> import org.apache.felix.gogo.commands.Argument;
>> import org.apache.felix.gogo.commands.Command;
>> import org.apache.felix.service.command.CommandSession;
>>
>> import org.jrb.test.MyService;
>>
>> @Command(scope = "onos", name = "service-add", description = "Adds a 
>> Client")
>> public class AddCommand implements Action {
>>
>> public AddCommand()
>> {
>> }
>>
>> private MyService serviceBn;
>>         
>>         public void setServiceBn(MyService serviceBn)
>>         {
>>         this.serviceBn = serviceBn;
>>         }
>>     
>>     public MyService getServiceBn() {
>> return service;
>> }
>>
>>    @Override
>>     public Object execute(CommandSession session) throws Exception {
>>          System.out.println("Executing command add");
>>
>>          if(serviceBn != null)
>>         System.out.println("serviceBn is not null");
>>          else
>>         System.out.println("serviceBn is null !!");
>>          if(serviceBn != null)
>>         System.out.println(serviceBn.echo("testing....."));
>>
>>     }
>> }
>>
>> In the above code, if i run the command "service-add",  my serviceBn is 
>> always NULL. The reference is not injecting the bean. 
>>
>> Is there anything missing in my code? please help. 
>>
>>
>> Regards,
>> Jayanth
>>
>>
>> -- 
>> -- 
>> ------------------
>> OPS4J - http://www.ops4j.org - [email protected] <javascript:>
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "OPS4J" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
>
> Apache Member
> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & 
> Project Lead
> blog <http://notizblog.nierbeck.de/>
> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>
>
> Software Architect / Project Manager / Scrum Master 
>
>

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to