You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Benoît Thiébault <th...@artenum.com> on 2009/07/16 10:53:09 UTC

[iPOJO] NullPointerException on injected service

Hi list !

I'm new to OSGI and iPOJO and I'm trying to create my first  
application using these tools with Maven. The purpose of this  
application is to test a messaging system accross components  
(basically an observer pattern).

The application is composed of 4 bundles :

1) The CoreServices bundle defines service interfaces in two  
packages : one for the execution service and one for the messaging  
service. The execution package defines just one ExecutionService  
interface, while the messaging service defines the MessagingService  
and the Message interfaces (plus an Enum Class).

There is no metada.xml file defined for this bundle and the pom.xml  
file declares the two packages in the <Export-Package> tag

2) The ExecutionService bundle implements the ExecutionService  
interface. The metada.xml file declares the component that <provides / 
 > the services and creates an instance. The pom file declares the  
compilation dependency with the first bundle and declares the impl  
package as <Private-Package>

3) The MessagingService bundle implements the MessagingService and the  
Message interfaces. The MessageImpl class uses an executionService  
field. The metadata.xml file is provided below. The pom.xml file  
declares the compilation dependency with the first bundle and declares  
the impl package as <Private-Package>

<iPOJO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd 
"
	xmlns="org.apache.felix.ipojo">
     <component classname="myapp.messaging.impl.MessagingServiceImpl"
		name="MessagingServiceImpl" public="false">
	<provides />
     </component>
     <component classname="myapp.messaging.impl.MessageImpl"
		name="MessageImpl">
	<requires field="executionService"/>
     </component>
     <instance component="MessagingServiceImpl"/>
</iPOJO>

4) The Test bundle implements two classes : a GUI that allows the user  
to send messages and a Logger that subscribes the message and prints  
"Hello World" when received.

I manage to build and launch the application without any problem. The  
arch command confirms that all my instances are valid. However, when I  
click the "send message" button, I have a null pointer exception on  
the executionService field in the MessageImpl class.

What did I do wrong ? Do I need to split the CoreServices bundle into  
two bundles (one declaring the execution service and the other one the  
messaging service ?)

I also tryed to launch all bundles except the ExecutionService bundle,  
and even though the MessagingService bundle requires it, arch tells me  
its instance is valid and the application is correctly launched.

Thanks for your help,

Benoît


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: [iPOJO] NullPointerException on injected service

Posted by Benoît Thiébault <th...@artenum.com>.
OK, I'll try that
Thanks a lot

Benoît

Le 16 juil. 09 à 16:59, Clement Escoffier a écrit :

> Hi,
>
>
> On 16.07.2009, at 15:12, Benoît Thiébault wrote:
>
>>
>> Le 16 juil. 09 à 14:47, Clement Escoffier a écrit :
>>
>>> Hi,
>>>
>>> There is no instances of MessageImpl declared there. How are they  
>>> created ? If you call "new" on the class, it will not be managed  
>>> by iPOJO.
>>
>> yes, the messages are created by the message service on demand by  
>> client applications :
>>
>> public void createMessage(String messageName) {
>> 	// If the message does not exist, create it
>> 	if (messageMap.get(messageName) == null) {
>> 	    messageMap.put(messageName, new MessageImpl(messageName));
>> 	} else {
>> 	    System.out.println("[Create] Message " + messageName + "  
>> already exists");
>> 	}
>>   }
>>
>> I understand now that this can't be managed by iPOJO... How can I  
>> do this ? By using the Message factory ? Do you have any  
>> documentation to point for that ?
>
> So, the client application can use a temporal service dependency  
> (that's support proxy) injecting your service and gives it to the  
> MessageImpl (as a constructor argument for example). To achieve  
> that, add the following metadata to the client's metadata file  :
>
> <temporal:requires proxy="true" field="service"/>
>
> Then, the previous code, would become (assuming that the service  
> field is declared) :
>> public void createMessage(String messageName) {
>> 	// If the message does not exist, create it
>> 	if (messageMap.get(messageName) == null) {
>> 	    messageMap.put(messageName, new MessageImpl(service,  
>> messageName)); // Give the service there.
>> 	} else {
>> 	    System.out.println("[Create] Message " + messageName + "  
>> already exists");
>> 	}
>>   }
>
>
> Regards,
>
> Clement
>
>
>>
>>> Can you send the architecture of the MessagingServiceImpl instance  
>>> and of the MessageImpl instance ? (arch -instance instance_name).
>>
>> Here it is :
>>
>> instance name="MessagingServiceImpl-0"  
>> component.type="MessagingServiceImpl" state="valid" bundle="7"
>> 	object name="myapp.messaging.impl.MessagingServiceImpl@1dcc042f"
>> 	handler name="org.apache.felix.ipojo:provides" state="valid"
>> 		provides service.id="33" state="registered"  
>> specifications="[myapp.messaging.MessagingService]"
>> 			property name="factory.name" value="MessagingServiceImpl"
>> 			property name="instance.name" value="MessagingServiceImpl-0"
>> 	handler name="org.apache.felix.ipojo:architecture" state="valid"
>>
>>>
>>> Regards,
>>>
>>> Clement
>>
>> Thank you
>>
>> Benoît Thiébault
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Benoît Thiébault

   Société Artenum
   24 rue Louis Blanc, 75010 Paris
   tel: +33 (0)1 46 94 67 54

   Artenum - Science & Groupware - http://www.artenum.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: [iPOJO] NullPointerException on injected service

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,


On 16.07.2009, at 15:12, Benoît Thiébault wrote:

>
> Le 16 juil. 09 à 14:47, Clement Escoffier a écrit :
>
>> Hi,
>>
>> There is no instances of MessageImpl declared there. How are they  
>> created ? If you call "new" on the class, it will not be managed by  
>> iPOJO.
>
> yes, the messages are created by the message service on demand by  
> client applications :
>
> public void createMessage(String messageName) {
> 	// If the message does not exist, create it
> 	if (messageMap.get(messageName) == null) {
> 	    messageMap.put(messageName, new MessageImpl(messageName));
> 	} else {
> 	    System.out.println("[Create] Message " + messageName + "  
> already exists");
> 	}
>    }
>
> I understand now that this can't be managed by iPOJO... How can I do  
> this ? By using the Message factory ? Do you have any documentation  
> to point for that ?

So, the client application can use a temporal service dependency  
(that's support proxy) injecting your service and gives it to the  
MessageImpl (as a constructor argument for example). To achieve that,  
add the following metadata to the client's metadata file  :

<temporal:requires proxy="true" field="service"/>

Then, the previous code, would become (assuming that the service field  
is declared) :
> public void createMessage(String messageName) {
> 	// If the message does not exist, create it
> 	if (messageMap.get(messageName) == null) {
> 	    messageMap.put(messageName, new MessageImpl(service,  
> messageName)); // Give the service there.
> 	} else {
> 	    System.out.println("[Create] Message " + messageName + "  
> already exists");
> 	}
>    }


Regards,

Clement


>
>> Can you send the architecture of the MessagingServiceImpl instance  
>> and of the MessageImpl instance ? (arch -instance instance_name).
>
> Here it is :
>
> instance name="MessagingServiceImpl-0"  
> component.type="MessagingServiceImpl" state="valid" bundle="7"
> 	object name="myapp.messaging.impl.MessagingServiceImpl@1dcc042f"
> 	handler name="org.apache.felix.ipojo:provides" state="valid"
> 		provides service.id="33" state="registered"  
> specifications="[myapp.messaging.MessagingService]"
> 			property name="factory.name" value="MessagingServiceImpl"
> 			property name="instance.name" value="MessagingServiceImpl-0"
> 	handler name="org.apache.felix.ipojo:architecture" state="valid"
>
>>
>> Regards,
>>
>> Clement
>
> Thank you
>
> Benoît Thiébault
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: [iPOJO] NullPointerException on injected service

Posted by Benoît Thiébault <th...@artenum.com>.
Le 16 juil. 09 à 14:47, Clement Escoffier a écrit :

> Hi,
>
> There is no instances of MessageImpl declared there. How are they  
> created ? If you call "new" on the class, it will not be managed by  
> iPOJO.

yes, the messages are created by the message service on demand by  
client applications :

public void createMessage(String messageName) {
	// If the message does not exist, create it
	if (messageMap.get(messageName) == null) {
	    messageMap.put(messageName, new MessageImpl(messageName));
	} else {
	    System.out.println("[Create] Message " + messageName + " already  
exists");
	}
     }

I understand now that this can't be managed by iPOJO... How can I do  
this ? By using the Message factory ? Do you have any documentation to  
point for that ?

> Can you send the architecture of the MessagingServiceImpl instance  
> and of the MessageImpl instance ? (arch -instance instance_name).

Here it is :

instance name="MessagingServiceImpl-0"  
component.type="MessagingServiceImpl" state="valid" bundle="7"
	object name="myapp.messaging.impl.MessagingServiceImpl@1dcc042f"
	handler name="org.apache.felix.ipojo:provides" state="valid"
		provides service.id="33" state="registered"  
specifications="[myapp.messaging.MessagingService]"
			property name="factory.name" value="MessagingServiceImpl"
			property name="instance.name" value="MessagingServiceImpl-0"
	handler name="org.apache.felix.ipojo:architecture" state="valid"

>
> Regards,
>
> Clement

Thank you

Benoît Thiébault



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: [iPOJO] NullPointerException on injected service

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,


On 16.07.2009, at 10:53, Benoît Thiébault wrote:

> Hi list !
>
> I'm new to OSGI and iPOJO and I'm trying to create my first  
> application using these tools with Maven. The purpose of this  
> application is to test a messaging system accross components  
> (basically an observer pattern).
>
> The application is composed of 4 bundles :
>
> 1) The CoreServices bundle defines service interfaces in two  
> packages : one for the execution service and one for the messaging  
> service. The execution package defines just one ExecutionService  
> interface, while the messaging service defines the MessagingService  
> and the Message interfaces (plus an Enum Class).
>
> There is no metada.xml file defined for this bundle and the pom.xml  
> file declares the two packages in the <Export-Package> tag
>
> 2) The ExecutionService bundle implements the ExecutionService  
> interface. The metada.xml file declares the component that  
> <provides /> the services and creates an instance. The pom file  
> declares the compilation dependency with the first bundle and  
> declares the impl package as <Private-Package>
>
> 3) The MessagingService bundle implements the MessagingService and  
> the Message interfaces. The MessageImpl class uses an  
> executionService field. The metadata.xml file is provided below. The  
> pom.xml file declares the compilation dependency with the first  
> bundle and declares the impl package as <Private-Package>
>
> <iPOJO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd 
> "
> 	xmlns="org.apache.felix.ipojo">
>    <component classname="myapp.messaging.impl.MessagingServiceImpl"
> 		name="MessagingServiceImpl" public="false">
> 	<provides />
>    </component>
>    <component classname="myapp.messaging.impl.MessageImpl"
> 		name="MessageImpl">
> 	<requires field="executionService"/>
>    </component>
>    <instance component="MessagingServiceImpl"/>
> </iPOJO>
>

There is no instances of MessageImpl declared there. How are they  
created ? If you call "new" on the class, it will not be managed by  
iPOJO.


> 4) The Test bundle implements two classes : a GUI that allows the  
> user to send messages and a Logger that subscribes the message and  
> prints "Hello World" when received.
>
> I manage to build and launch the application without any problem.  
> The arch command confirms that all my instances are valid. However,  
> when I click the "send message" button, I have a null pointer  
> exception on the executionService field in the MessageImpl class.
>
> What did I do wrong ? Do I need to split the CoreServices bundle  
> into two bundles (one declaring the execution service and the other  
> one the messaging service ?)
>
> I also tryed to launch all bundles except the ExecutionService  
> bundle, and even though the MessagingService bundle requires it,  
> arch tells me its instance is valid and the application is correctly  
> launched.

Can you send the architecture of the MessagingServiceImpl instance and  
of the MessageImpl instance ? (arch -instance instance_name).

Regards,

Clement

>
> Thanks for your help,
>
> Benoît
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org