I am trying to send a message from a Weblogic 10.3.4 domain to a JMS queue hosted in another Weblogic 10.3.4 domain. Both domains run on the same host.
I have been able to write a simple Java program that successfully sends a message to the queue in the other domain; but I am not able to do so by using the <jee:jndi-lookup... or the JndiObjectFactoryBean. The JNDI lookup fails with a name not found exception. It doesn't seem to be able to find it on the other domain's JNDI tree, even though I am using the provider URL of the domain where the queue is residing (The same as used by the programe below that works)...
Is there some secret to getting this to work?
Any assistance would be much appreciated.
Thanks in advance...
Here is the code that successfully sends the message:
I have been able to write a simple Java program that successfully sends a message to the queue in the other domain; but I am not able to do so by using the <jee:jndi-lookup... or the JndiObjectFactoryBean. The JNDI lookup fails with a name not found exception. It doesn't seem to be able to find it on the other domain's JNDI tree, even though I am using the provider URL of the domain where the queue is residing (The same as used by the programe below that works)...
Is there some secret to getting this to work?
Any assistance would be much appreciated.
Thanks in advance...
Here is the code that successfully sends the message:
Code:
public Object invoke(Object object) throws ServiceInvocationException {
try {
Object convertedObject = object;
if (object instanceof Document) {
if (LOG.isInfoEnabled())
{
LOG.info(getClass().getName()+".invoke with Document type argument is called");
}
convertedObject = DOMSerializerHelper
.serializeDocument((Document) object);
}
Hashtable<String,String> props = new Hashtable<String,String>();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://localhost:7003");
props.put(Context.SECURITY_PRINCIPAL, "weblogic");
props.put(Context.SECURITY_CREDENTIALS, "mypassword");
Context ctx = new InitialContext(props);
qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
if (qconFactory == null)
{
if (LOG.isErrorEnabled())
{
LOG.error("Queue connection factory is null.");
return object;
}
}
if (LOG.isInfoEnabled())
{
LOG.info("JMS connection factory "+JMS_FACTORY+" looked up");
}
qcon = qconFactory.createQueueConnection();
qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
if (LOG.isInfoEnabled())
{
LOG.info("Queue connection created.");
}
queue = (Queue) ctx.lookup(QUEUE);
if (queue == null)
{
if (LOG.isErrorEnabled())
{
LOG.error("Queue lookup returns null.");
return object;
}
}
qsender = qsession.createSender(queue);
if (LOG.isInfoEnabled())
{
LOG.info("Create queue sender for "+QUEUE);
}
msg = qsession.createTextMessage();
msg.setText(convertedObject.toString());
if (LOG.isInfoEnabled())
{
LOG.info("Message to send "+msg.getText());
}
qcon.start();
qsender.send(msg);
if (LOG.isInfoEnabled())
{
LOG.info("Message sent");
}
} catch (Exception e) {
if (LOG.isErrorEnabled())
{
LOG.error("Failed to send message: "+e);
LOG.error(StackTraceUtil.getStackTrace(e));
}
} finally {
try {
if (qsender != null)
{
qsender.close();
if (LOG.isInfoEnabled())
{
LOG.info("Closed queue sender");
}
}
if (qsession != null)
{
qsession.close();
if (LOG.isInfoEnabled())
{
LOG.info("Closed queue session");
}
}
if (qcon != null)
{
qcon.close();
if (LOG.isInfoEnabled())
{
LOG.info("Closed queue connection");
}
}
} catch (JMSException ex) {
if (LOG.isErrorEnabled())
{
LOG.error("Failed to close JMS resources: "+ex);
}
}
}
return object;
}