Get a Response from ESB
hartmann1980 Feb 17, 2010 5:13 PMHi
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