OsgiServiceProvider vs Service, OsgiService vs Reference

2016-09-03 Thread Ranx0r0x
One thing that isn't clear to me from the documentation is how the 
annotations vary.

I know that if I use the Service/Reference annotations they work in the CDI 
test runner just fine.  The OsgiServiceProvider and OsgiService annotations 
do not.  I haven't put them in karaf/felix as deployments yet.  But the 
Service/Reference should work I'd think since the are felix annotations.

Is it that the Service/Reference annotations are not portable across 
container types - that is Equinox, Knopplerfish, in addition to Felix while 
the Osgi...Service annotations should be?  Or is it that the Osgi types are 
differentiated by using proxies while the Service/Reference annotations are 
strictly DS?

Other than the testing concern why would I choose one over the other?

Brad

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pax CDI and Camel...testing...

2016-09-03 Thread Ranx0r0x
While I find this less than ideal, until I get to know how CDI in general 
and Pax CDI specifically work, I've modified my DatastoreImpl class to have 
a @Produces annotation with a "factory" method for lack of a better name.

While this facilitates testing locally and lets me inject the interface via 
a standard @Inject annotation, I'm not sure if this will have ramifications 
when I install it in Karaf.  If this works for both testing and deployment 
I'm cool with it.

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pax CDI and Camel...testing...

2016-09-03 Thread Brad Johnson
While not ideal, if I just remove the @OsgiService from the unit test it 
injects because it is within the same bundle.  I'll likely have to use a 
different testing mechanism to get the provider/service injection to work. 
I've also added this to make sure the service is exported the way I want 
from the bundle.  This more like what I'd do in blueprint and if I have it 
right the Pax CDI is using the same proxy mechanism as blueprint.

@OsgiServiceProvider(classes = {DataStore.class})

On Saturday, September 3, 2016 at 10:50:03 AM UTC-5, Brad Johnson wrote:
>
> I've been using the 2.17 update of Camel that more closely integrates CDI 
> 1.2 and specifically Pax CDI.  I'm quite impressed with and look forward to 
> using it in the years ahead.  I've used blueprint for quite awhile and 
> while it works well enough the CDI simply makes development much easier and 
> testing is a snap.
>
> One problem I've run into is with the CDI testing framework.  Within 
> bundle tests or even bundles listed as dependencies work just fine.  But 
> when I try to use the @OsgiServiceProvider and @OsgiService I run into some 
> problems.  It may simply be that the regular CDI runner with Weld isn't 
> appropriate for testing service export and import.
>
> From what I can tell I'm either missing a library dependency or the CDI 
> test even within bundle will not respect the pick up or use the annotations.
>
> The @Inject in this unit test shows a squiggly yellow underline indicating 
> it can't find anything to inject.
>
> @RunWith(CamelCdiRunner.class)
> public class DevelopmentDataStoreTest {
>
> @Inject
> @OsgiService
> private DataStore datastore;
>
> In the same bundle I have am Impl of the DataStore interface that looks 
> like this:
>
> @Singleton
> @OsgiServiceProvider
> public class DevelopmentDataStoreImpl implements DataStore {
>
> I've tried a number of different permutations such as adding a 
> dynamic=true to the OsgiService annotation.
>
> The stack trace on the test seems to indicate that it understand what it 
> is I want to do but I don't have something right about it (italics are 
> mine).
>
> ELD-001408: Unsatisfied dependencies for type DataStore with qualifiers 
> @OsgiService
>   at injection point [BackedAnnotatedField] @Inject @OsgiService private 
> org.enjekt.panda.developmentdatstore.DevelopmentDataStoreTest.datastore
>   at 
> org.enjekt.panda.developmentdatstore.DevelopmentDataStoreTest.datastore(DevelopmentDataStoreTest.java:0)
> WELD-001475: *The following beans match by type, but none have matching 
> qualifiers:*
> *  - Managed Bean [class 
> org.enjekt.panda.developmentdatastore.DevelopmentDataStoreImpl] with 
> qualifiers [@OsgiServiceProvider @Any]*
>
> Italics are mine. So something is off about my annotations. Should the 
> OsgiServiceProvider be scoped differently?  For in bundle testing like this 
> I could use @Named("dataStore") and inject it that way.
>
>
> My imports look like the following:
> 
> javax.enterprise
> cdi-api
> ${cdi.version}
> 
> 
> org.ops4j.pax.cdi
> pax-cdi-api
> 1.0.0.RC1
> 
> 
> org.apache.camel
> camel-cdi
> ${camel.version}
> 2.17.3
> 
>
> 
> 
> org.apache.camel
> camel-test-cdi
> ${camel.version}
> test
> 
>
> Any help is appreciated.
>

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Karaf Blueprit Service is not injecting the objects.

2016-09-03 Thread Brad Johnson
That sounds like the case the Blueprint is creating a proxy to the 
interface but when it is invoked there isn't a concreted object exposed for 
it to execute against.  If you actually look at the class type of the 
MyService injected into your class it will likely be a Proxy class and a 
true instance of the object.

On Thursday, September 1, 2016 at 4:12:13 AM UTC-5, jayant...@gmail.com 
wrote:
>
> 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 :
>>
>>> 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:
>>> 
>>> 
>>> http://www.osgi.org/xmlns/blueprint/v1.0.0; 
>>> default-activation="lazy">
>>>
>>> 
>>>
>>> >> interface="org.jrb.test.MyService"/>
>>>
>>> 
>>>
>>> i can see my service in list: 
>>> --
>>> onos> service:list | grep serviceBean
>>>  *osgi.service.blueprint.compname = serviceBean*
>>>
>>>
>>> *Part 2*: consumer class for testing
>>>
>>> Blueprint
>>> -
>>> 
>>> http://www.osgi.org/xmlns/blueprint/v1.0.0; 
>>> default-activation="lazy">
>>>
>>> 
>>> 
>>> 
>>> 
>>> http://karaf.apache.org/xmlns/shell/v1.1.0;>
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>
>>> 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 - op...@googlegroups.com
>>>
>>> --- 
>>> 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 ops4j+un...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>>
>> Apache Member
>> Apache Karaf  Committer & PMC
>> OPS4J Pax Web  Committer 
>> & Project Lead
>> blog 
>> Co-Author of Apache Karaf Cookbook 
>>
>> Software Architect / Project Manager / Scrum Master 
>>
>>

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Pax CDI and Camel...testing...

2016-09-03 Thread Brad Johnson
I've been using the 2.17 update of Camel that more closely integrates CDI 
1.2 and specifically Pax CDI.  I'm quite impressed with and look forward to 
using it in the years ahead.  I've used blueprint for quite awhile and 
while it works well enough the CDI simply makes development much easier and 
testing is a snap.

One problem I've run into is with the CDI testing framework.  Within bundle 
tests or even bundles listed as dependencies work just fine.  But when I 
try to use the @OsgiServiceProvider and @OsgiService I run into some 
problems.  It may simply be that the regular CDI runner with Weld isn't 
appropriate for testing service export and import.

>From what I can tell I'm either missing a library dependency or the CDI 
test even within bundle will not respect the pick up or use the annotations.

The @Inject in this unit test shows a squiggly yellow underline indicating 
it can't find anything to inject.

@RunWith(CamelCdiRunner.class)
public class DevelopmentDataStoreTest {

@Inject
@OsgiService
private DataStore datastore;

In the same bundle I have am Impl of the DataStore interface that looks 
like this:

@Singleton
@OsgiServiceProvider
public class DevelopmentDataStoreImpl implements DataStore {

I've tried a number of different permutations such as adding a dynamic=true 
to the OsgiService annotation.

The stack trace on the test seems to indicate that it understand what it is 
I want to do but I don't have something right about it (italics are mine).

ELD-001408: Unsatisfied dependencies for type DataStore with qualifiers 
@OsgiService
  at injection point [BackedAnnotatedField] @Inject @OsgiService private 
org.enjekt.panda.developmentdatstore.DevelopmentDataStoreTest.datastore
  at 
org.enjekt.panda.developmentdatstore.DevelopmentDataStoreTest.datastore(DevelopmentDataStoreTest.java:0)
WELD-001475: *The following beans match by type, but none have matching 
qualifiers:*
*  - Managed Bean [class 
org.enjekt.panda.developmentdatastore.DevelopmentDataStoreImpl] with 
qualifiers [@OsgiServiceProvider @Any]*

Italics are mine. So something is off about my annotations. Should the 
OsgiServiceProvider be scoped differently?  For in bundle testing like this 
I could use @Named("dataStore") and inject it that way.


My imports look like the following:

javax.enterprise
cdi-api
${cdi.version}


org.ops4j.pax.cdi
pax-cdi-api
1.0.0.RC1


org.apache.camel
camel-cdi
${camel.version}
2.17.3




org.apache.camel
camel-test-cdi
${camel.version}
test


Any help is appreciated.

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: PAX-CDI+PAX-WEB: org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: Unable to resolve any beans for Type

2016-09-03 Thread iJava
Please, any hint. The problem still not solved...

On Friday, 2 September 2016 15:27:05 UTC+3, iJava wrote:
>
> Hi all,
>
> I have a very very bad problem with pax-cdi and pax-web. My configuration: 
> jetty 9.3.11.v20160721, weld 2.2.12.Final, pax-cdi 0.13.0-SNAPSHOT, 
> pax-swissbox 1.8.0 , pax-web 6.0.0-SNAPSHOT.
>
> The problem is that the SAME war bundle sometimes works fine, sometimes I 
> get the exception:
>
> org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: 
> Unable to resolve any beans for Type: class com.example.SomeClass; 
> Qualifiers: [@javax.enterprise.inject.Any()]
> at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:101)
>
> When I set logging level to debug - I see in weld log file that class 
> com.example.SomeClass is found with qualifiers Any and Default.
>
> However, when logging level is set to debug and everything works much 
> slower I don't get this exception. However, when I set
> logging level to warn and everything works fast I SOMETIMES get this 
> exception. So it may be about timing???
>
> Please, any help and hints
>
>

-- 
-- 
--
OPS4J - http://www.ops4j.org - ops4j@googlegroups.com

--- 
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 ops4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problems using @PostConstruct on primefaces bean in Pax web 4.2.7

2016-09-03 Thread Steinar Bang
Platform: Intel i7, Windows 7 professional,
  eclipse Neon 4.6.0
  m2e 1.7.0.20160603-1933 (ie. the version bundled with eclipse Neon)
  Java SDK 1.8.0_91
  Pax web 4.2.7
  Pax exam 4.9.1
  Apache myfaces 2.2.6
  primefaces 5.1

I was trying to change the controller bean of my application to do its
setup in a @PostConstruct, instead of (as now) in the constructor:
  
https://github.com/steinarb/ukelonn/blob/using-primefaces/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnController.java
(Note: The bean currently only contains hardcoded data for testing)

So I created a public void init() method, and tried annotating it with
a @PostConstruct annotation, ie. like so:
@PostConstruct
public void init() {
transactionTypes = new ArrayList();
transactionTypes.add(new TransactionType(1, "Støvsuging 1. etasje", 
45.0, true, false));
transactionTypes.add(new TransactionType(2, "Støvsuging kjeller", 45.0, 
true, false));
transactionTypes.add(new TransactionType(3, "Gå med resirk", 35.0, 
true, false));
transactionTypes.add(new TransactionType(4, "Inn på konto", null, 
false, true));

transactions = new ArrayList();
transactions.add(new Transaction(transactionTypes.get(0), new Date(), 
45.0));
transactions.add(new Transaction(transactionTypes.get(1), new Date(), 
45.0));
transactions.add(new Transaction(transactionTypes.get(2), new Date(), 
35.0));
transactions.add(new Transaction(transactionTypes.get(3), new Date(), 
-125.0));
}


However that gave me problems in eclipse:
 1. Typing Ctrl-SPC in eclipse didn't offer to expand @PostConstruct
 2. Typing @PostConstruct made @PostConstruct be underlined in red, and
typing Ctrl-1 on top of the highlighted text, didn't give me import
of javax.annotations as an alternative
 3. Manually adding "using javax.annotation.PostConstruct" made both the
"using" line and the @PostConstruct be highlighted with yellow
underlining (i.e. as a warning).
The warning was:
 Access restriction: The type 'PostConstruct' is not API (restriction on 
required library 'C:\Program Files\Java\jre1.8.0_91\lib\rt.jar')


Trying to test the bundle in a pax exam test, that uses equinox as the
OSGi runtime, I get the following error message:
org.osgi.framework.BundleException:
Could not resolve module: no.priv.bang.ukelonn [61]
  Bundle was not resolved because of a uses contraint violation.
  org.osgi.service.resolver.ResolutionException: Uses constraint violation. 
Unable to resolve resource no.priv.bang.ukelonn [osgi.identity; 
osgi.identity="no.priv.bang.ukelonn"; type="osgi.bundle"; 
version:Version="1.0.0.SNAPSHOT"] because it is exposed to package 
'javax.annotation' from resources org.apache.servicemix.specs.jsr250-1.0 
[osgi.identity; osgi.identity="org.apache.servicemix.specs.jsr250-1.0"; 
type="osgi.bundle"; version:Version="2.0.0"] and org.eclipse.osgi 
[osgi.identity; osgi.identity="org.eclipse.osgi"; type="osgi.bundle"; 
version:Version="3.11.0.v20160603-1336"; singleton:="true"] via two dependency 
chains.

Chain 1:
  no.priv.bang.ukelonn [osgi.identity; osgi.identity="no.priv.bang.ukelonn"; 
type="osgi.bundle"; version:Version="1.0.0.SNAPSHOT"]
import: (osgi.wiring.package=javax.annotation)
 |
export: osgi.wiring.package: javax.annotation
  org.apache.servicemix.specs.jsr250-1.0 [osgi.identity; 
osgi.identity="org.apache.servicemix.specs.jsr250-1.0"; type="osgi.bundle"; 
version:Version="2.0.0"]

Chain 2:
  no.priv.bang.ukelonn [osgi.identity; osgi.identity="no.priv.bang.ukelonn"; 
type="osgi.bundle"; version:Version="1.0.0.SNAPSHOT"]
require: (osgi.wiring.bundle=org.primefaces)
 |
provide: osgi.wiring.bundle; bundle-version:Version="5.1.0"; 
osgi.wiring.bundle="org.primefaces"
  org.primefaces [osgi.identity; osgi.identity="org.primefaces"; 
type="osgi.bundle"; version:Version="5.1.0"]
import: (osgi.wiring.package=javax.annotation)
 |
export: osgi.wiring.package: javax.annotation
  org.eclipse.osgi [osgi.identity; osgi.identity="org.eclipse.osgi"; 
type="osgi.bundle"; version:Version="3.11.0.v20160603-1336"; singleton:="true"]
at 
no.priv.bang.ukelonn.tests.UkelonnServiceIntegrationTest.setup(UkelonnServiceIntegrationTest.java:143)


Note: When I start the gogoshell with
 cd ukelonn.gogoshell
 mvn clean install pax:provision
I get no bundle resolution error. However, the gogoshell uses felix as
the OSGi runtime, so that may be a different environment in this
context...?

Does anyone know what to do with this?  Is it fixable, both for the pax
exam test and for eclipse?  Does it have something to do with me using
Java 8?

I have googled and found some interesting matches
 [1] http://njbartlett.name/2011/09/02/uses-constraints.html
 [2] http://spring.io/blog/2008/10/20/understanding-the-osgi-uses-directive/

Article [1] is a bit old (2011), but it still is the most