You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Tom Barber <to...@meteorite.bi> on 2015/07/30 18:07:20 UTC

Accessing the correct classpath(Was:PAX CDI not bootstrapping)

Okay chaps,

After a day of bashing my head against a brick wall and finding out CDI
won't work with Websockets in Karaf at the mo, I started thinking about
coming at it from the other way and looking up the bean from the
ServerEndpoint class.

So I had a google and came across the JNDI naming stuff, which looks pretty
much what I'm going to have to do, and ran it past jbonofre before he flew
and he semi validated the idea.

So I added


Context context = new InitialContext();
FileManagerClientImpl myBean = (FileManagerClientImpl)
context.lookup("fmclient");

To my ServerEndpoint class and it tries to load my service via JNDI but it
can't cast itself to itself... urgh.

java.lang.ClassCastException:
com.mytool.filemanager.websocket.FileManagerClientImpl cannot be cast to
com.mytool.filemanager.websocket.FileManagerClientImpl


As the ServerEndpoint isn't managed by blueprint or anything anyone got any
good ideas as to how to get the valid object?

Code here:
https://github.com/buggtb/broken-cdi-example/blob/master/src/main/java/com/mytool/filemanager/websocket/FileManagerEndpoint.java#L49

Thanks

Tom



On Thu, Jul 30, 2015 at 4:05 PM, Tom Barber <to...@meteorite.bi> wrote:

> That said, I do find plenty of posts where they say it does work:
>
> For example:
> http://stackoverflow.com/questions/30332043/inject-an-application-scoped-managed-bean-in-a-websocket
>
>
> On Thu, Jul 30, 2015 at 3:24 PM, Tom Barber <to...@meteorite.bi>
> wrote:
>
>> Thanks Jens
>>
>> When I figured it wasn't CDI at complete fault I went googling and came
>> across a bunch of similar stuff, which is nuts. If you want to run
>> websockets and have some system beans, how on earth do you communicate with
>> them?! :)
>>
>> Tom
>>
>> On Thu, Jul 30, 2015 at 3:00 PM, Jens J Parappallil <
>> jens.parappallil@ibsplc.com> wrote:
>>
>>> Hi Tom,
>>>
>>>
>>>
>>> You may find this interesting
>>>
>>>
>>>
>>> https://dzone.com/articles/integrating-cdi-and-websockets
>>>
>>>
>>>
>>> Regards
>>>
>>> Jens
>>>
>>>
>>>
>>> *From:* Tom Barber [mailto:tom.barber@meteorite.bi]
>>> *Sent:* Thursday, July 30, 2015 4:52 PM
>>> *To:* user@karaf.apache.org
>>> *Subject:* Re: PAX CDI not bootstrapping
>>>
>>>
>>>
>>> You'll cringe when you see this but I've been hacking around a bit to
>>> see whats broken:
>>>
>>>
>>>
>>>
>>> https://github.com/buggtb/broken-cdi-example/blob/master/src/main/java/com/mytool/filemanager/websocket/FileManagerEndpoint.java
>>>
>>>
>>>
>>> So I made my endpoint multipurpose and it now doubles up as a Servlet.
>>>
>>>
>>>
>>> Anyway, the get works and responds correctly with my injected CDI
>>> object, the Web socket endpoint still bombs with an NPE. I'm gonna guess
>>> its some weird Web Socket classloading issue, but I have absolutely no clue.
>>>
>>>
>>>
>>> tom
>>>
>>>
>>>
>>> On Thu, Jul 30, 2015 at 12:03 PM, Tom Barber <to...@meteorite.bi>
>>> wrote:
>>>
>>> Thanks Andreas,
>>>
>>>
>>>
>>> That was a hangover from when I tried it without an interface.
>>>
>>>
>>>
>>> I've checked it and its still not firing.
>>>
>>>
>>>
>>> Tom
>>>
>>>
>>>
>>> On Thu, Jul 30, 2015 at 11:54 AM, Andreas Kuhtz <an...@gmail.com>
>>> wrote:
>>>
>>> Hi,
>>>
>>> Might be a problem of injecting the impl instead of the interface in
>>> FileManagerEndpoint:
>>>
>>> @OsgiService
>>> private FileManagerClientImpl fileManagerClient;
>>>
>>> .. the same in the setter. Try change to FileManagerClient and see if
>>> this helps.
>>>
>>> Regards,
>>>
>>> Andreas
>>>
>>>
>>>
>>> 2015-07-30 12:48 GMT+02:00 Tom Barber <to...@meteorite.bi>:
>>>
>>> Okay gang,
>>>
>>>
>>>
>>> I've tried 0.13.0-SNAPSHOT and I still can't for the life of me figure
>>> out why I don't get my dependency injected.
>>>
>>>
>>>
>>> Here is a stripped out version:
>>> https://github.com/buggtb/broken-cdi-example I'm sure its something
>>> obvious but I can't figure it out.
>>>
>>>
>>>
>>> Thanks
>>>
>>>
>>>
>>> Tom
>>>
>>>
>>>
>>> On Wed, Jul 29, 2015 at 11:47 PM, Tom Barber <to...@meteorite.bi>
>>> wrote:
>>>
>>> Knowing my coding prowess, i wouldn't say nicely, but i'll give it a
>>> shot and ask questions another day!
>>>
>>>
>>>
>>> Thanks Achim!
>>>
>>>
>>>
>>>
>>>
>>> On Wed, Jul 29, 2015 at 11:42 PM, Achim Nierbeck <
>>> bcanhome@googlemail.com> wrote:
>>>
>>> If you switch to use pax-cdi 0.13.0-SNAPSHOT it'll work nicely with
>>> Pax-Web 4.x and Karaf 4.
>>>
>>> I just pushed the changes and deployed the snapshot to the ops4j
>>> snapshot repo.
>>>
>>>
>>>
>>> regards, Achim
>>>
>>>
>>>
>>> 2015-07-30 0:02 GMT+02:00 Tom Barber <to...@meteorite.bi>:
>>>
>>> Boo, actually I resolved that weirdness, that was due to me overriding
>>> the default classpath, but when it starts I don't get any beans injected
>>> which gives me a sad face.......
>>>
>>>
>>>
>>> Tom
>>>
>>>
>>>
>>> On Wed, Jul 29, 2015 at 10:38 PM, Achim Nierbeck <
>>> bcanhome@googlemail.com> wrote:
>>>
>>> Hi Tom,
>>>
>>>
>>>
>>> I'm not sure what happened to your setup,
>>>
>>> but actually that shouldn't be of an issue.
>>>
>>> I just tested it and stumbled over another thing.
>>>
>>> The latest pax-cdi bundles aren't compatible with Jetty 9.1 and Servlet
>>> 3.1
>>>
>>>
>>>
>>> I'm gonna look at it.
>>>
>>>
>>>
>>> regards, Achim
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> 2015-07-29 18:04 GMT+02:00 Tom Barber <to...@meteorite.bi>:
>>>
>>> Hello chaps
>>>
>>>
>>>
>>> Running Karaf 4 and PAX CDI I'm running into an issue wiring it all up.
>>> I have
>>>
>>>
>>>
>>> Require-Capability: org.ops4j.pax.cdi.extension; filter:="(&(extension=p
>>>
>>>  ax-cdi-extension)(version>=0.12)(!(version>=0.13)))",osgi.extender; fil
>>>
>>>  ter:="(osgi.extender=pax.cdi)"
>>>
>>>
>>>
>>> In my Manifest but when it starts it complains of stuff like:
>>>
>>>
>>>
>>> Caused by: java.lang.ClassNotFoundException:
>>> WEB-INFes.com.mytool.filemanager.websocket.FileManagerObj not found by
>>> com.mytool.filemanager-client
>>>
>>>
>>>
>>> Which is weird, mostly because where does WEB-IFes come from?
>>>
>>>
>>>
>>> Anyway I can't work it out, where those errors come from and whilst my
>>> bundle does come up my beans aren't injected, does anyone have a good idea?
>>>
>>>
>>>
>>> Thanks
>>>
>>>
>>>
>>> Tom
>>>
>>>
>>>
>>>
>>>
>>> --
>>>
>>>
>>> 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
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>>
>>>
>>> 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
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> DISCLAIMER: "The information in this e-mail and any attachment is
>>> intended only for the person to whom it is addressed and may contain
>>> confidential and/or privileged material. If you have received this e-mail
>>> in error, kindly contact the sender and destroy all copies of the original
>>> communication. IBS makes no warranty, express or implied, nor guarantees
>>> the accuracy, adequacy or completeness of the information contained in this
>>> email or any attachment and is not liable for any errors, defects,
>>> omissions, viruses or for resultant loss or damage, if any, direct or
>>> indirect."
>>>
>>
>>
>

Re: Accessing the correct classpath(Was:PAX CDI not bootstrapping)

Posted by Tom Barber <to...@meteorite.bi>.
Cancel that, in my first test I must have been running the wrong jar and
not casting to the interface... doh....

good news, it all seems to work(after 2 days of head scratching)

Thanks guys, your interfaces rock even if the spec doesn't!

Tom

On Thu, Jul 30, 2015 at 5:07 PM, Tom Barber <to...@meteorite.bi> wrote:

> Okay chaps,
>
> After a day of bashing my head against a brick wall and finding out CDI
> won't work with Websockets in Karaf at the mo, I started thinking about
> coming at it from the other way and looking up the bean from the
> ServerEndpoint class.
>
> So I had a google and came across the JNDI naming stuff, which looks
> pretty much what I'm going to have to do, and ran it past jbonofre before
> he flew and he semi validated the idea.
>
> So I added
>
>
> Context context = new InitialContext();
> FileManagerClientImpl myBean = (FileManagerClientImpl)
> context.lookup("fmclient");
>
> To my ServerEndpoint class and it tries to load my service via JNDI but it
> can't cast itself to itself... urgh.
>
> java.lang.ClassCastException:
> com.mytool.filemanager.websocket.FileManagerClientImpl cannot be cast to
> com.mytool.filemanager.websocket.FileManagerClientImpl
>
>
> As the ServerEndpoint isn't managed by blueprint or anything anyone got
> any good ideas as to how to get the valid object?
>
> Code here:
> https://github.com/buggtb/broken-cdi-example/blob/master/src/main/java/com/mytool/filemanager/websocket/FileManagerEndpoint.java#L49
>
> Thanks
>
> Tom
>
>
>
> On Thu, Jul 30, 2015 at 4:05 PM, Tom Barber <to...@meteorite.bi>
> wrote:
>
>> That said, I do find plenty of posts where they say it does work:
>>
>> For example:
>> http://stackoverflow.com/questions/30332043/inject-an-application-scoped-managed-bean-in-a-websocket
>>
>>
>> On Thu, Jul 30, 2015 at 3:24 PM, Tom Barber <to...@meteorite.bi>
>> wrote:
>>
>>> Thanks Jens
>>>
>>> When I figured it wasn't CDI at complete fault I went googling and came
>>> across a bunch of similar stuff, which is nuts. If you want to run
>>> websockets and have some system beans, how on earth do you communicate with
>>> them?! :)
>>>
>>> Tom
>>>
>>> On Thu, Jul 30, 2015 at 3:00 PM, Jens J Parappallil <
>>> jens.parappallil@ibsplc.com> wrote:
>>>
>>>> Hi Tom,
>>>>
>>>>
>>>>
>>>> You may find this interesting
>>>>
>>>>
>>>>
>>>> https://dzone.com/articles/integrating-cdi-and-websockets
>>>>
>>>>
>>>>
>>>> Regards
>>>>
>>>> Jens
>>>>
>>>>
>>>>
>>>> *From:* Tom Barber [mailto:tom.barber@meteorite.bi]
>>>> *Sent:* Thursday, July 30, 2015 4:52 PM
>>>> *To:* user@karaf.apache.org
>>>> *Subject:* Re: PAX CDI not bootstrapping
>>>>
>>>>
>>>>
>>>> You'll cringe when you see this but I've been hacking around a bit to
>>>> see whats broken:
>>>>
>>>>
>>>>
>>>>
>>>> https://github.com/buggtb/broken-cdi-example/blob/master/src/main/java/com/mytool/filemanager/websocket/FileManagerEndpoint.java
>>>>
>>>>
>>>>
>>>> So I made my endpoint multipurpose and it now doubles up as a Servlet.
>>>>
>>>>
>>>>
>>>> Anyway, the get works and responds correctly with my injected CDI
>>>> object, the Web socket endpoint still bombs with an NPE. I'm gonna guess
>>>> its some weird Web Socket classloading issue, but I have absolutely no clue.
>>>>
>>>>
>>>>
>>>> tom
>>>>
>>>>
>>>>
>>>> On Thu, Jul 30, 2015 at 12:03 PM, Tom Barber <to...@meteorite.bi>
>>>> wrote:
>>>>
>>>> Thanks Andreas,
>>>>
>>>>
>>>>
>>>> That was a hangover from when I tried it without an interface.
>>>>
>>>>
>>>>
>>>> I've checked it and its still not firing.
>>>>
>>>>
>>>>
>>>> Tom
>>>>
>>>>
>>>>
>>>> On Thu, Jul 30, 2015 at 11:54 AM, Andreas Kuhtz <
>>>> andreas.kuhtz@gmail.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> Might be a problem of injecting the impl instead of the interface in
>>>> FileManagerEndpoint:
>>>>
>>>> @OsgiService
>>>> private FileManagerClientImpl fileManagerClient;
>>>>
>>>> .. the same in the setter. Try change to FileManagerClient and see if
>>>> this helps.
>>>>
>>>> Regards,
>>>>
>>>> Andreas
>>>>
>>>>
>>>>
>>>> 2015-07-30 12:48 GMT+02:00 Tom Barber <to...@meteorite.bi>:
>>>>
>>>> Okay gang,
>>>>
>>>>
>>>>
>>>> I've tried 0.13.0-SNAPSHOT and I still can't for the life of me figure
>>>> out why I don't get my dependency injected.
>>>>
>>>>
>>>>
>>>> Here is a stripped out version:
>>>> https://github.com/buggtb/broken-cdi-example I'm sure its something
>>>> obvious but I can't figure it out.
>>>>
>>>>
>>>>
>>>> Thanks
>>>>
>>>>
>>>>
>>>> Tom
>>>>
>>>>
>>>>
>>>> On Wed, Jul 29, 2015 at 11:47 PM, Tom Barber <to...@meteorite.bi>
>>>> wrote:
>>>>
>>>> Knowing my coding prowess, i wouldn't say nicely, but i'll give it a
>>>> shot and ask questions another day!
>>>>
>>>>
>>>>
>>>> Thanks Achim!
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Jul 29, 2015 at 11:42 PM, Achim Nierbeck <
>>>> bcanhome@googlemail.com> wrote:
>>>>
>>>> If you switch to use pax-cdi 0.13.0-SNAPSHOT it'll work nicely with
>>>> Pax-Web 4.x and Karaf 4.
>>>>
>>>> I just pushed the changes and deployed the snapshot to the ops4j
>>>> snapshot repo.
>>>>
>>>>
>>>>
>>>> regards, Achim
>>>>
>>>>
>>>>
>>>> 2015-07-30 0:02 GMT+02:00 Tom Barber <to...@meteorite.bi>:
>>>>
>>>> Boo, actually I resolved that weirdness, that was due to me overriding
>>>> the default classpath, but when it starts I don't get any beans injected
>>>> which gives me a sad face.......
>>>>
>>>>
>>>>
>>>> Tom
>>>>
>>>>
>>>>
>>>> On Wed, Jul 29, 2015 at 10:38 PM, Achim Nierbeck <
>>>> bcanhome@googlemail.com> wrote:
>>>>
>>>> Hi Tom,
>>>>
>>>>
>>>>
>>>> I'm not sure what happened to your setup,
>>>>
>>>> but actually that shouldn't be of an issue.
>>>>
>>>> I just tested it and stumbled over another thing.
>>>>
>>>> The latest pax-cdi bundles aren't compatible with Jetty 9.1 and Servlet
>>>> 3.1
>>>>
>>>>
>>>>
>>>> I'm gonna look at it.
>>>>
>>>>
>>>>
>>>> regards, Achim
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> 2015-07-29 18:04 GMT+02:00 Tom Barber <to...@meteorite.bi>:
>>>>
>>>> Hello chaps
>>>>
>>>>
>>>>
>>>> Running Karaf 4 and PAX CDI I'm running into an issue wiring it all up.
>>>> I have
>>>>
>>>>
>>>>
>>>> Require-Capability: org.ops4j.pax.cdi.extension; filter:="(&(extension=p
>>>>
>>>>  ax-cdi-extension)(version>=0.12)(!(version>=0.13)))",osgi.extender; fil
>>>>
>>>>  ter:="(osgi.extender=pax.cdi)"
>>>>
>>>>
>>>>
>>>> In my Manifest but when it starts it complains of stuff like:
>>>>
>>>>
>>>>
>>>> Caused by: java.lang.ClassNotFoundException:
>>>> WEB-INFes.com.mytool.filemanager.websocket.FileManagerObj not found by
>>>> com.mytool.filemanager-client
>>>>
>>>>
>>>>
>>>> Which is weird, mostly because where does WEB-IFes come from?
>>>>
>>>>
>>>>
>>>> Anyway I can't work it out, where those errors come from and whilst my
>>>> bundle does come up my beans aren't injected, does anyone have a good idea?
>>>>
>>>>
>>>>
>>>> Thanks
>>>>
>>>>
>>>>
>>>> Tom
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>>
>>>> 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
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>>
>>>> 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
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> DISCLAIMER: "The information in this e-mail and any attachment is
>>>> intended only for the person to whom it is addressed and may contain
>>>> confidential and/or privileged material. If you have received this e-mail
>>>> in error, kindly contact the sender and destroy all copies of the original
>>>> communication. IBS makes no warranty, express or implied, nor guarantees
>>>> the accuracy, adequacy or completeness of the information contained in this
>>>> email or any attachment and is not liable for any errors, defects,
>>>> omissions, viruses or for resultant loss or damage, if any, direct or
>>>> indirect."
>>>>
>>>
>>>
>>
>