Topic
  • 3 replies
  • Latest Post - ‏2013-08-29T07:26:02Z by RichEllis
JRoyal
JRoyal
1 Post

Pinned topic OSGi and Liberty JMS

‏2013-07-18T18:26:14Z |

Hi all,

I imagine this might be a simple question to answer but all of my searching has come up short so far so I thought I would come here and ask for some help. At the moment I am trying to connect a client osgi bundle to the embedded liberty messaging service. The server is set up and configured correctly I believe, because I have no problems connecting to it when I run normal servlets that aren't part of an OSGi bundle. I get an error that looks like the following if I attempt to take that same client code and put it inside of a bundle.

 java.lang.ClassCastException: com.ibm.ws.jca.service.ConnectionFactoryService incompatible with javax.jms.TopicConnectionFactory

at com.ibm.PubSubExample.Publisher.doGet(Publisher.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1240)
at [internal classes]

 

From what I can tell from my searching, connecting to the TopicConnectionFactory and all that from inside of a OSGi bundle is done using blueprints. Unfortunately i'm not sure how to do that or if that is even correct. If anyone knows or is willing to point me in the right direction I would greatly appreciate it!

Edit: I forgot to mention that I am using the 8.5.5 Liberty Profile. If you need anymore information please let me know.

Thanks!

James

  • bkail
    bkail
    23 Posts

    Re: OSGi and Liberty JMS

    ‏2013-07-19T16:09:11Z  

    Are you using JNDI with an "osgi:service/jndiname"?  If yes, this appears to be in some way related to PM91526.  In that case, as a workaround, can you use BundleContext to obtain the TopicConnectionFactory service rather than indirecting through JNDI?  If no, I recommend opening a PMR with IBM.

    If you're not using JNDI, can you share a snippet that shows what the code is doing when it gets the ClassCastException?

  • IT_Girdhar
    IT_Girdhar
    2 Posts

    Re: OSGi and Liberty JMS

    ‏2013-08-27T06:31:42Z  
    • bkail
    • ‏2013-07-19T16:09:11Z

    Are you using JNDI with an "osgi:service/jndiname"?  If yes, this appears to be in some way related to PM91526.  In that case, as a workaround, can you use BundleContext to obtain the TopicConnectionFactory service rather than indirecting through JNDI?  If no, I recommend opening a PMR with IBM.

    If you're not using JNDI, can you share a snippet that shows what the code is doing when it gets the ClassCastException?

    Hi,

    I've come across the same issue.  Please find below the code snippet . I am able to fetch JNDI properties from Liberty server's server.xml  (ConnectionFactory and Queue) , It results in nullpointerException when it executes  statement Connection conn = cf.createConnection().

    I've also not specified anything in blueprint.xml for JMS. I tried the same from web App , It works fine but it does not in OSGI.  Please suggest any pointer to resove this issue.

     

     

    Code Snippet :

    BundleContext bundleContext = BundleReference.class.cast(mqMessagingClient.class.getClassLoader()).getBundle().getBundleContext();
            
            ServiceReference [] serviceReferences=null;
            
          try {
                BundleContext bundleContext = BundleReference.class.cast(JMSClient.class.getClassLoader()).getBundle().getBundleContext();
                ConnectionFactory cf = (ConnectionFactory) bundleContext.
                        getService(bundleContext.getServiceReferences("javax.jms.ConnectionFactory",
                                "(osgi.jndi.service.name=jms/libertyQCF)")[0]);
                System.out.println("Created connection factory" + cf.toString());
                
                Destination dest = (Destination) bundleContext.
                        getService(bundleContext.getServiceReferences("javax.jms.Destination",
                                "(osgi.jndi.service.name=jms/libertyQue)")[0]);
                
                System.out.println("Desination: " + dest.toString());
                
                 Connection conn = cf.createConnection();
                
            }
            catch(JMSException e){
                System.out.println("Something went wrong,JMSException caught .." + e.getMessage());
                
            }
            catch(Exception e){
                System.out.println("Something went wrong,Exception caught.." + e.getMessage());
            }
              
             
             try {
                connectionFactory.createConnection();
            } catch (JMSException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }  

  • RichEllis
    RichEllis
    4 Posts

    Re: OSGi and Liberty JMS

    ‏2013-08-29T07:26:02Z  

    Hi,

    I've come across the same issue.  Please find below the code snippet . I am able to fetch JNDI properties from Liberty server's server.xml  (ConnectionFactory and Queue) , It results in nullpointerException when it executes  statement Connection conn = cf.createConnection().

    I've also not specified anything in blueprint.xml for JMS. I tried the same from web App , It works fine but it does not in OSGI.  Please suggest any pointer to resove this issue.

     

     

    Code Snippet :

    BundleContext bundleContext = BundleReference.class.cast(mqMessagingClient.class.getClassLoader()).getBundle().getBundleContext();
            
            ServiceReference [] serviceReferences=null;
            
          try {
                BundleContext bundleContext = BundleReference.class.cast(JMSClient.class.getClassLoader()).getBundle().getBundleContext();
                ConnectionFactory cf = (ConnectionFactory) bundleContext.
                        getService(bundleContext.getServiceReferences("javax.jms.ConnectionFactory",
                                "(osgi.jndi.service.name=jms/libertyQCF)")[0]);
                System.out.println("Created connection factory" + cf.toString());
                
                Destination dest = (Destination) bundleContext.
                        getService(bundleContext.getServiceReferences("javax.jms.Destination",
                                "(osgi.jndi.service.name=jms/libertyQue)")[0]);
                
                System.out.println("Desination: " + dest.toString());
                
                 Connection conn = cf.createConnection();
                
            }
            catch(JMSException e){
                System.out.println("Something went wrong,JMSException caught .." + e.getMessage());
                
            }
            catch(Exception e){
                System.out.println("Something went wrong,Exception caught.." + e.getMessage());
            }
              
             
             try {
                connectionFactory.createConnection();
            } catch (JMSException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }  

    What is the stack trace of the NullPointerException?