11 Replies Latest reply on Jan 24, 2008 12:09 PM by ccustine

    Client API

    vikas_sm

      Hi All,

       

      I am using service mix3.2.1 and our team is working for support contract with iona for the same.

       

      As part of our requirement, we need to invoke the services (jms endpoints or any other services) from POJO, residing under the same jvm where service mix (service assembly)is running.

      This can be achieved by using client-api. http://docs.huihoo.com/apache/servicemix/client-api.html

       

      There are two approaches for creating ServiceMixClient

      1) Spring configurations

      2) Using Client Factory

       

      I tried second approach but i am getting javax.naming.NameNotFoundException: env not bound exception.

      I found that the required JNDI name is missing.

       

      I decided to go with spring approach but I am wondering how can i get hold of jbi container.

       

      Enviroment

      Jboss4.2.2

      ServiceMix3.2.1 deployed as Sar.

       

      can any one throw some light on this?

       

      Thanks in Advance

      Vikas

        • 1. Re: Client API
          ccustine

          The easiest way to get a client is to use ServiceMixClientFacade as shown at the bottom of the Client API page.  Depending on the component type you are working with, you can usually create a setter on your POJO to get a ComponentContext like this:

           

          ComponentContext context;
          
          public void setContext(ComponentContext context) {
              this.context = context;
          }
          

           

          Then create a client from your POJO methods like this:

           

          ServiceMixClient client = new ServiceMixClientFacade(context);
          

           

          I know that the above scenario works with cxf and jsr-181 service engines, but if this doesn't work out in your situation let us know what component you are using and we can offer more suggestions.

           

          Chris

           

          Edited by: ccustine on Jan 17, 2008 4:00 PM - Fixed code formatting

          • 2. Re: Client API
            vikas_sm

            Thanks Chris,

             

            Can you please explain me how to get hold of ComponentContex in my POJO.

             

            I think, you are suggesting to achieve it using spring(dependency injection) but i am not sure how to get reference of ComponenetContext.

             

            Thanks/Vikas

            • 3. Re: Client API
              ccustine

              Which service engine are you using?  For instance, with CXF and jsr-181, these two in particular have a helper that will set the ComponentContext on your POJO if you have the setter method that I show above and that will not require spring at all.

               

              Let me know a little about your config and I can give more specifics for your situation.

               

              Chris

              • 4. Re: Client API
                vikas_sm

                I am using jms service . I want to invoke jms-endpoint from POJO.

                 

                Do you mean that for JSR181, by having just settter , things will work for me.

                 

                I might need JSR181 in future but currently I am working on jms invocation and get this done at earliest.

                 

                Appreciate your help on this.

                 

                Thanks/Vikas

                • 5. Re: Client API
                  ccustine

                  Hi Vikas,

                  Sorry to keep asking for more info, but could you post a detailed description of the flow you are trying to accomplish?  For instance I am wondering if you have much processing going on in the POJO, and if you are bridging different JMS providers.  Maybe with a little more detail we can dive deeper into the use case and find the right solution.

                   

                  Thanks,

                  Chris

                  • 6. Re: Client API
                    vikas_sm

                    Hi Chris,

                     

                    I will try to explain the business problem we are trying to solve here

                     

                    Currently the business application say A interacts with Business Application B using messaging.

                     

                    We are trying to use ESB over here. The application 'A' will send message to Jms-end point on esb and esb will do processing (validation, logging or audit trails) and send the message to queue of application B.

                     

                    Now we need the same workflow for say application A1 . Application 'A1' and ESB are running under same jboss server instance, hence we want to avoid the messaging overhead here and instead would to like to directly invoke the jms end point configured for B using client-api.

                     

                    Going ahead we might invoke some service (logging or some validation servive) instead of directly invoking jms-end point.

                     

                    I hope, this helps you to get the clear picture on our requirement.

                    Let me know your input or approach to solve the above business problem.

                     

                    Thanks/Vikas

                    • 7. Re: Client API
                      cjd11

                      To clarify, we dont need to call a jms endpoint - we need to invoke a service. How we do that, we are open to your suggestions (bean service?). Basically, we want to be able to invoke a method - say send (XMLStructure foo) - and then have that method run within the service mix process space and enable us to pass the xml as a jms message on to an MQ queue. So we would have a jms provider endpoint, and another service that would provide access to the service mix bus.

                       

                      Hope that clarifies some more.

                      • 8. Re: Client API
                        cjd11

                        So at a higher level, here's what we are trying to do:

                        An application (deployed as an ear) is running in JBoss AS 4.2.2. We have our Service Mix ESB deployed as shared libraries. Our test services are deployed as a service assembly, picked up by the JBoss deployer.

                         

                        We need to be able to invoke a service on the bus - preferably using method invocation (local client proxy type stuff) rather than going via jms. The recommendation that we are currently following is using the ClientFactory MBean to try and create a ServiceMixClient (DefaultServiceMixClient) to invoke a service. This seems like a solid appraoch, but we are getting a ClassCastException, possibly caused by the j2EE deployment model. We are working to ensure our deployment is clean (and classes are only included where necessary) in all this, and we do expect JBoss classloading to provide - shall we say - challenges. Once we have a cleaner deployment, if we are still getting hte issues we will post more information about the applicaiton (client) deployment model, any information we have about the classloaders being used and of course the issue itself. In the meantime, if this does nto seem like the right approach, please let us know.

                        • 9. Re: Client API
                          ccustine

                          I assume you are using JNDI to get the ClientFactory, is that correct?  So are you getting a ClassCastException when casting the ClientFactory from the JNDI lookup or are you getting that when invoking createClient() on the ClientFactory?

                           

                          This is the best way for you to get your client instance for sure.  Give me an update on your current issues if you are still having trouble.  There are some issues with JBoss JNDI lookups, but I don't think they should be affecting you in this case, so I am curious if you are getting far enough to get a valid ClientFactory from JNDI.

                           

                          Thanks,

                          Chris

                          • 10. Re: Client API
                            cjd11

                            We are getting an error when the JBoss Deployer loads into JBoss:

                            2008-01-22 17:04:18,899 DEBUG setRepository, repository=org.jboss.mx.loading.HeirarchicalLoaderRepository3@e8e8f9, cl=org.jboss.mx.loading.HeirarchicalLoaderRepository3$CacheClassLoader@b1be82{ url=null ,addedOrder=0}

                            2008-01-22 17:04:18,899 WARN  Cound not start ClientFactory: javax.naming.NameNotFoundException: env not bound

                            2008-01-22 17:04:18,899 DEBUG setRepository, repository=org.jboss.mx.loading.HeirarchicalLoaderRepository3@e8e8f9, cl=org.jboss.mx.loading.HeirarchicalLoaderRepository3$CacheClassLoader@1697d14{ url=null ,addedOrder=0}

                            2008-01-22 17:04:18,899 INFO  ServiceMix JBI Container (ServiceMix) started

                            2008-01-22 17:04:18,899 DEBUG starting service org.servicemix:service=JBIService

                            2008-01-22 17:04:18,899 DEBUG Ignoring start request for service: org.servicemix:service=JBIService

                            2008-01-22 17:04:18,899 DEBUG Started org.servicemix:service=JBIService

                            2008-01-22 17:04:18,899 DEBUG Starting dependent components for: org.servicemix:service=JBIService dependent components: [ObjectName: org.servicemix:service=Deployer

                              State: CREATED

                              I Depend On:

                                org.servicemix:service=JBIService

                            ]

                            2008-01-22 17:04:18,899 DEBUG starting service org.servicemix:service=Deployer

                            2008-01-22 17:04:18,899 DEBUG Starting org.servicemix:service=Deployer

                            2008-01-22 17:04:18,915 DEBUG Adding deployer: org.servicemix.jboss.deployment.JBIDeployer@92de02

                            2008-01-22 17:04:18,915 DEBUG org.servicemix:service=Deployer does not support EnhancedSuffixes

                            2

                             

                            We did see the ClientFactory MBean deployed in Jboss, so we did try and acces sthat - that gave us the ClassCastException; looking at the JNDI issue, the env namespace is bound in our Jboss server. It is trying to bind the ClientFactory using the name:

                            java:comp/env/jbi/ClientFactory

                            We are validating that it is creating the right InitialContext() and seeing the JNDI tree.

                             

                            Our general deployment model is as follows:

                            JBoss deployer for the JBI container

                            SM Shared libraries (we had to prune for Jboss to prevent class contentions on things like Xerces)

                            Service Mix Service Assembly with some su's deployed

                            Application war (simple jsp right now) that will try nad acces shte Client Factory and create a client

                             

                            We will update this post with any more information we gather through our debugging exercise.

                            • 11. Re: Client API
                              ccustine

                              I have reproduced your environment and it looks like there are indeed a couple of issues with JBoss, JNDI and the JBoss deployer that are going to affect you.  I have an open issue on the Apache project for the problems binding the ClientFactory in JNDI ( SM-1206 ).  In addition, it looks like the JBoss deployer itself needs some updating to work with 3.2+ but you must have worked around that to get as far as you have.  The deployer fixes are easy and quick to resolve, but the ClientFactory JNDI binding problem is going to require a little more research and effort.

                               

                              In the mean time, there are a couple of options:

                              1).  Use JMS and send directly to the exposed JMS endpoint

                              2).  You could look at the RemoteServiceMixClient for a short term solution that will just route the requests over JMS and will have much of the same invocation semantics to make it easy to use the in-VM client when the issues above are fixed.

                               

                              Those are the easy solutions that come to mind.  #2 above embeds a JBI container in your client and connects to your main instance, so if you try that route, be careful not to create the client over and over.  For this reason, #1 may be preferred.

                               

                              Monitor SM-1206 and when we get that fixed you should be in business with the ClientFactory from JNDI.

                               

                              Chris