5 Replies Latest reply on Feb 27, 2010 11:38 AM by hartmann1980

    Get a Response from ESB

      Hi

       

      I'm trying to call a simple method that returns the server time (local time on the server system). But, it doesn't work

       

      Here is my jboss-esb.xml:

       

      <?xml version="1.0"?>
      <jbossesb parameterReloadSecs="5"
       xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd">
       <providers>
        <jms-provider connection-factory="ConnectionFactory" name="JBoss-MessageQueue">
         <jms-bus busid="gatewayChannel">
          <jms-message-filter dest-name="queue/jmsRequestQueue_Gw" dest-type="QUEUE"/>
         </jms-bus>
         <jms-bus busid="esbChannel">
          <jms-message-filter dest-name="queue/jmsRequestQueue_Esb" dest-type="QUEUE"/>
         </jms-bus>
        </jms-provider>
       </providers>
       <services>
        <service category="MyTimeService" description="Local time service" name="LocalTimeService">
         <listeners>
          <jms-listener busidref="gatewayChannel" is-gateway="true" name="jmsGwListener"/>
          <jms-listener busidref="esbChannel" name="jmsEsbListener"/>
         </listeners>
         <actions mep="RequestResponse">
          <action class="esb.demo.time.actions.MyJMSListenerAction" name="myAction" process="getLocalTime"/>
         </actions>
        </service>
       </services>
      </jbossesb>
      

       

      I created deployment.xml and jbm-queue-service.xml (I'm not sure if I need it really )! Both files are (more or less) "copy paste" from quickstarts!

       

      <jbossesb-deployment>
        <depends>jboss.esb.destination:service=Queue,name=jmsRequestQueue_Gw</depends>
        <depends>jboss.esb.destination:service=Queue,name=jmsRequestQueue_Esb</depends>
      </jbossesb-deployment>
      

       

      <?xml version="1.0" encoding="UTF-8"?>
      <server>
        <mbean code="org.jboss.jms.server.destination.QueueService"
          name="jboss.esb.destination:service=Queue,name=jmsRequestQueue_Gw"
          xmbean-dd="xmdesc/Queue-xmbean.xml">
           <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
           <depends>jboss.messaging:service=PostOffice</depends>
        </mbean>
        <mbean code="org.jboss.jms.server.destination.QueueService"
          name="jboss.esb.destination:service=Queue,name=jmsRequestQueue_Esb"
          xmbean-dd="xmdesc/Queue-xmbean.xml">
          <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
           <depends>jboss.messaging:service=PostOffice</depends>
        </mbean>
      </server>
      

       

      Here is my Action-Class:

       

      /* Created on 16.02.2010 */
      package esb.demo.time.actions;
      
      import java.util.Date;
      
      import org.jboss.soa.esb.actions.AbstractActionLifecycle;
      import org.jboss.soa.esb.helpers.ConfigTree;
      import org.jboss.soa.esb.message.Message;
      import org.jboss.soa.esb.message.format.MessageFactory;
      
      public class MyJMSListenerAction extends AbstractActionLifecycle
      {
      
          protected ConfigTree cnfg;
      
          public MyJMSListenerAction(ConfigTree config)
          {
              this.cnfg = cnfg;
          }
      
          public Message getLocalTime(Message message) throws Exception
          {
              // I'm here
              System.out.println("method 'getLocalTime' called!");
              
              Message response = MessageFactory.getInstance().getMessage();   
              response.getBody().add("date", new Date().toString());  
              
              // I'm not sure, if the next two lines are necessary
              response.getHeader().getCall().setTo(message.getHeader().getCall().getReplyTo());
              response.getHeader().getCall().setRelatesTo(message.getHeader().getCall().getMessageID());
              
              return response;
          }
      
      }
      

       

      And now my SendEsbMessage-Class:

       

      package esb.demo.time.actions.test;
      
      import org.jboss.soa.esb.message.Message;
      import org.jboss.soa.esb.message.format.*; 
      import org.jboss.soa.esb.client.ServiceInvoker;
      
      
      public class SendEsbMessage
      {
          public static void main(String args[]) throws Exception
          {
              System.setProperty("javax.xml.registry.ConnectionFactoryClass",
                      "org.apache.ws.scout.registry.ConnectionFactoryImpl");
      
              String msg = "DefaultText";
      
              ServiceInvoker invoker = new ServiceInvoker("MyTimeService", "LocalTimeService"); // critical line!
              
              Message requestMessage = MessageFactory.getInstance().getMessage(
                      MessageType.JBOSS_XML);
              requestMessage.getBody().add(msg);
      
              Message replyMessage = invoker.deliverSync(requestMessage, 20000);
      
              System.out.println("Reply: " + replyMessage.getBody().get());
          }
      
      }
      

       

      I created the "SendJMSMessage" class to see, if the method is called (from quicksarts):

       

      package esb.demo.time.actions.test;
      
      import java.util.Properties;
      
      import javax.jms.JMSException;
      import javax.jms.ObjectMessage;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class SendJMSMessage {
          QueueConnection conn;
          QueueSession session;
          Queue que;
          
          
          public void setupConnection() throws JMSException, NamingException
          {
              Properties properties1 = new Properties();
              properties1.put(Context.INITIAL_CONTEXT_FACTORY,
                      "org.jnp.interfaces.NamingContextFactory");
              properties1.put(Context.URL_PKG_PREFIXES,
                      "org.jboss.naming:org.jnp.interfaces");
              properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
              InitialContext iniCtx = new InitialContext(properties1);
      
              Object tmp = iniCtx.lookup("ConnectionFactory");
              QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
              conn = qcf.createQueueConnection();
              que = (Queue) iniCtx.lookup("queue/jmsRequestQueue_Gw");
              session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
              conn.start();
              System.out.println("Connection Started");
          }
          
          public void stop() throws JMSException 
          { 
              conn.stop();
              session.close();
              conn.close();
          }
          
          public void sendAMessage(String msg) throws JMSException {
              
              QueueSender send = session.createSender(que);        
              ObjectMessage tm = session.createObjectMessage(msg);
              
              send.send(tm);        
              send.close();
          }
             
          
          public static void main(String args[]) throws Exception
          {                   
              SendJMSMessage sm = new SendJMSMessage();
              sm.setupConnection();
              sm.sendAMessage("***"); 
              sm.stop();
              
          }
          
      }
      

       

      And, this works! With SendJMSMessage I see the message on the screen:

       

      method 'getLocalTime' called!

      If I try with "SendEsbMessage" it ends with following error message:

       

      Exception in thread "main" org.jboss.soa.esb.listeners.message.MessageDeliverException: Invocation exception. null
           at org.jboss.soa.esb.client.ServiceInvoker.loadServiceClusterInfo(ServiceInvoker.java:545)
           at org.jboss.soa.esb.client.ServiceInvoker.<init>(ServiceInvoker.java:174)
           at org.jboss.soa.esb.client.ServiceInvoker.<init>(ServiceInvoker.java:155)
           at org.jboss.soa.esb.client.ServiceInvoker.<init>(ServiceInvoker.java:197)
           at esb.demo.time.actions.test.SendEsbMessage.main(SendEsbMessage.java:17)
      Caused by: org.jboss.soa.esb.services.registry.RegistryException: Invocation exception. null
           at org.jboss.soa.esb.services.registry.RegistryFactory.createRegistry(RegistryFactory.java:121)
           at org.jboss.soa.esb.services.registry.RegistryFactory.getRegistry(RegistryFactory.java:86)
           at org.jboss.soa.esb.listeners.RegistryUtil.getEprs(RegistryUtil.java:220)
           at org.jboss.soa.esb.client.ServiceInvoker.loadServiceClusterInfo(ServiceInvoker.java:532)
           ... 4 more
      Caused by: java.lang.NullPointerException
           at java.lang.Class.forName0(Native Method)
           at java.lang.Class.forName(Unknown Source)
           at org.jboss.soa.esb.util.ClassUtil.forName(ClassUtil.java:65)
           at org.jboss.soa.esb.services.registry.RegistryFactory.createRegistry(RegistryFactory.java:110)
           ... 7 more
      

       

      What is wrong in my example? And, how can I get a response from my method (synchron call)? Have I really to work with ServiceInvoker to get the response or could I get response with "SendJMSMessage"?

       

      It would be very nice, if anybody could help.

       

      Thaks, Eva

        • 1. Re: Get a Response from ESB

          Any ideas?

           

          I tried to call my service from the quickstart 'helloworld' class SendEsbMessage. And, it works! But, if I try to call the helloworld-service from my class SendEsbMessage, it doesn't work!

           

          ServiceInvoker invoker = new ServiceInvoker("FirstServiceESB", "SimpleListener");
          

           

          I have the following error message:

           

          Exception in thread "main" org.jboss.soa.esb.listeners.message.MessageDeliverException: Invocation exception. null
               at org.jboss.soa.esb.client.ServiceInvoker.loadServiceClusterInfo(ServiceInvoker.java:545)
               at org.jboss.soa.esb.client.ServiceInvoker.<init>(ServiceInvoker.java:174)
               at org.jboss.soa.esb.client.ServiceInvoker.<init>(ServiceInvoker.java:155)
               at org.jboss.soa.esb.client.ServiceInvoker.<init>(ServiceInvoker.java:197)
               at esb.demo.time.actions.test.SendEsbMessage.main(SendEsbMessage.java:18)
          Caused by: org.jboss.soa.esb.services.registry.RegistryException: Invocation exception. null
               at org.jboss.soa.esb.services.registry.RegistryFactory.createRegistry(RegistryFactory.java:121)
               at org.jboss.soa.esb.services.registry.RegistryFactory.getRegistry(RegistryFactory.java:86)
               at org.jboss.soa.esb.listeners.RegistryUtil.getEprs(RegistryUtil.java:220)
               at org.jboss.soa.esb.client.ServiceInvoker.loadServiceClusterInfo(ServiceInvoker.java:532)
               ... 4 more
          Caused by: java.lang.NullPointerException
               at java.lang.Class.forName0(Native Method)
               at java.lang.Class.forName(Unknown Source)
               at org.jboss.soa.esb.util.ClassUtil.forName(ClassUtil.java:65)
               at org.jboss.soa.esb.services.registry.RegistryFactory.createRegistry(RegistryFactory.java:110)
               ... 7 more
          
          

           

          Do I need some additional files in the client root directory (jbossesb-prpperties.xml, jndi.properties etc.)? And, what does it mean

           

          Caused by: java.lang.NullPointerException
               at java.lang.Class.forName0(Native Method)
               at java.lang.Class.forName(Unknown Source)
               at org.jboss.soa.esb.util.ClassUtil.forName(ClassUtil.java:65)
               at org.jboss.soa.esb.services.registry.RegistryFactory.createRegistry(RegistryFactory.java:110)
               ... 7 more
          

           

          Is a class missing? Does anyone see, what is wrong here?

          • 2. Re: Get a Response from ESB
            scottdawson

            Eva - look at the section titled 'Configuration for a remote ServiceInvoker' in the Programmer's Guide

            It shows the jars and configuration files (including jbossesb-properties.xml) needed for a remote client using the ServiceInvoker.

             

            Regards,

            Scott

            • 3. Re: Get a Response from ESB

              Thanks, Scott

               

              I tried it:

               

              I have all required libraries in clientlib directory and the setclasspath.bat file for setting classpath. The file uuid.xml is in META-INF directory and jbossesb-properties.xml in root directory. To be sure, that I have all required libraries as specified in Programmers Guide (page 52), I compiled bouth classes (SendJMSMessage and SendESBMessage) from command line. After that I call SendJMSMessage and could see, that ist works! Wenn I try to call SendESBMessage, I have the same error (as described).

               

               


              • 4. Re: Get a Response from ESB

                I think, something is wrong with libraries and classpath neded for client with ServiceInvoker: the org.jboss.esb.client.EsbClient (Programmers Guide - page 53) doesn't work.

                 

                Here are my files and libraries:

                 

                C:\Temp>sinvoker
                          ¦
                          +-- lib
                          ¦
                          +-- META-INF\uuid.xml
                          ¦
                          +-- org\jboss\esb\client\EsbClient.class
                          ¦
                          +-- jbossesb-properties.xml
                          ¦
                          +-- jndi.properties
                          ¦
                          +-- juddi.properties
                          ¦
                          +-- log4j.propeties
                          ¦
                          +-- setclasspath.bat
                

                 

                In lib directory are 74 jar files: 23 jar-files listed on the page 52 (Programmers Guide) and 51 jar-files listed in readme.txt in jbossall-client.jar.

                 

                Here is an extract form readme.txt:

                 

                This jar file contains a classpath reference to various client jar files used by jboss client applications.
                Each of the jar files in the following list must available in the same directory as the jbossall-client.jar,  Otherwise they will not be found by the classloader.
                

                 

                If I understand correctly, I have to copy the 53 listed jar files in the same directory with other 23 jar files (hope, this is correct).

                 

                The setclasspath.bat is as follows:

                 

                set classpath=%CLASSPATH%;lib\commons-lang-2.3.jar;lib\commons-configuration-1.5.jar;lib\commons-logging-1.1.jar;lib\javassist-3.6.0.GA.jar;lib\jboss-aop-jdk50-1.5.6.GA.jar;lib\jboss-messaging-client.jar;lib\jboss-remoting.jar;lib\jbossesb-config-model-1.0.1.jar;lib\jbossesb-rosetta.jar;lib\jbossts-common.jar;lib\juddi-client-3.0.0.aop.jar;lib\juddi-core-3.0.0.aop.jar;lib\log4j-1.2.15.jar;lib\scout-1.2.aop.jar;lib\stax-1.2.0.jar;lib\stax-api-1.0.1.jar;lib\trove.jar;lib\uddi-ws-3.0.0.jar;lib\wstx-asl-3.2.0.jar;lib\xbean-2.2.0.jar;lib\xercesImpl-2.8.0.jar;lib\commons-codec-1.3.jar;lib\jbossall-client.jar;
                
                

                 

                 

                Set classpath and run EsbClient (JBoss AS is running and helloworld deployed):

                 

                Microsoft Windows XP [Version 5.1.2600]
                (C) Copyright 1985-2001 Microsoft Corp.
                
                C:\Temp\sinvoker>setclasspath.bat
                
                C:\Temp\sinvoker>set classpath=.;C:\Programme\Java\jre6\lib\ext\QTJava.zip;./lib/
                commons-lang-2.3.jar;./lib/commons-configuration-1.5.jar;./lib/commons-logging-1.1.jar;./lib/javassist-3.6.0.GA.jar;./li
                b/jboss-aop-jdk50-1.5.6.GA.jar;./lib/jboss-messaging-client.jar;./lib/jboss-remoting.jar;./lib/jbossesb-config-model-1.0
                .1.jar;./lib/jbossesb-rosetta.jar;./lib/jbossts-common.jar;./lib/juddi-client-3.0.0.aop.jar;./lib/juddi-core-3.0.0.aop.j
                ar;./lib/log4j-1.2.15.jar;./lib/scout-1.2.aop.jar;./lib/stax-1.2.0.jar;./lib/stax-api-1.0.1.jar;./lib/trove.jar;./lib/ud
                di-ws-3.0.0.jar;./lib/wstx-asl-3.2.0.jar;./lib/xbean-2.2.0.jar;./lib/xercesImpl-2.8.0.jar;./lib/commons-codec-1.3.jar;./
                lib/jbossall-client.jar;
                
                C:\Temp\sinvoker>java org.jboss.esb.client.EsbClient
                org.jboss.soa.esb.listeners.message.MessageDeliverException: org.apache.ws.scout.transport.TransportException: java.lang
                .reflect.InvocationTargetException
                
                C:\Temp\sinvoker>
                
                

                 

                What is wrong with my libraries and classpath?

                • 5. Re: Get a Response from ESB
                  Is there an other way to get a response from ESB without ServiceInvoker?